StormByte C++ Library: Network module 1.1.0
StormByte-Network is the C++26 networking module of the StormByte suite.
Loading...
Searching...
No Matches
status.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Network.
5 *
6 * StormByte-Network is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Network is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Network. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/visibility.h>
23
24#include <string>
25
34 enum class STORMBYTE_NETWORK_PUBLIC Status: unsigned short {
35 Connected,
40 Rejected,
42 Error
43 };
44
50 constexpr STORMBYTE_NETWORK_PUBLIC std::string StatusToString(const Status& status) {
51 switch (status) {
52 case Status::Connected: return "Connected";
53 case Status::Disconnected: return "Disconnected";
54 case Status::Connecting: return "Connecting";
55 case Status::Disconnecting: return "Disconnecting";
56 case Status::Negotiating: return "Negotiating";
57 case Status::Rejected: return "Rejected";
58 case Status::PeerClosed: return "PeerClosed";
59 case Status::Error:
60 default: return "Error";
61 }
62 }
63
69 constexpr STORMBYTE_NETWORK_PUBLIC bool IsConnected(const Status& status) noexcept {
70 return status == Status::Connected || status == Status::Negotiating;
71 }
72}
Connection types of the Network module.
Definition client.hxx:31
constexpr bool IsConnected(const Status &status) noexcept
Whether the connection is usable for I/O (Connected or Negotiating).
Definition status.hxx:69
constexpr std::string StatusToString(const Status &status)
Status as text.
Definition status.hxx:50
Status
Lifecycle of a connection or listener.
Definition status.hxx:34
@ Disconnecting
Shutdown in progress.
@ Connected
Connection established.
@ Rejected
Peer or local rejection.
@ PeerClosed
Peer closed the connection.
@ Connecting
Connect or listen in progress.
@ Negotiating
Application-level handshake.
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:28