15 throw std::invalid_argument(
"ENetPeer cannot be null");
20 if (!
_peer || !packet) {
27 throw std::invalid_argument(
"Packet must be an ENetPacketWrapper");
30 ENetPacket *nativePacket = enetPacket->getNativePacket();
31 if (enet_peer_send(
_peer, channelID, nativePacket) < 0) {
36 (void)packet.release();
42 enet_peer_disconnect(
_peer, data);
48 enet_peer_disconnect_now(
_peer, data);
53 if (
_peer &&
_peer->state != ENET_PEER_STATE_DISCONNECTED &&
54 _peer->state != ENET_PEER_STATE_DISCONNECTING &&
_peer->state != ENET_PEER_STATE_ZOMBIE) {
55 enet_peer_disconnect_later(
_peer, data);
68 switch (
_peer->state) {
69 case ENET_PEER_STATE_DISCONNECTED:
71 case ENET_PEER_STATE_CONNECTING:
73 case ENET_PEER_STATE_ACKNOWLEDGING_CONNECT:
75 case ENET_PEER_STATE_CONNECTION_PENDING:
77 case ENET_PEER_STATE_CONNECTION_SUCCEEDED:
79 case ENET_PEER_STATE_CONNECTED:
81 case ENET_PEER_STATE_DISCONNECT_LATER:
83 case ENET_PEER_STATE_DISCONNECTING:
85 case ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT:
87 case ENET_PEER_STATE_ZOMBIE:
96 throw std::runtime_error(
"Cannot get address of null peer");
111 return _peer->connectID;
118 return _peer->roundTripTime;
PeerState
Represents the connection state of a peer.
@ CONNECTION_SUCCEEDED
Connection has succeeded.
@ DISCONNECT_LATER
Peer is scheduled to disconnect.
@ ACKNOWLEDGING_CONNECT
Connection acknowledgment is being sent.
@ ACKNOWLEDGING_DISCONNECT
Disconnect acknowledgment is being sent.
@ ZOMBIE
Peer is in a zombie state.
@ CONNECTION_PENDING
Connection is pending.
@ DISCONNECTED
Peer is disconnected.
@ CONNECTING
Connection to peer is being established.
@ CONNECTED
Peer is connected.
@ DISCONNECTING
Disconnection is in progress.
void setData(void *data) override
Set application-specific data associated with this peer.
uint32_t getRoundTripTime() const override
Get the round-trip time (ping) to this peer.
void * getData() const override
Get application-specific data associated with this peer.
ENetPeer * getNativePeer() const
ENetPeerWrapper(ENetPeer *peer)
PeerState getState() const override
Get the current state of this peer.
void disconnectNow(uint32_t data) override
Force an immediate disconnect from this peer.
void disconnectLater(uint32_t data) override
Disconnect from this peer after all queued packets are sent.
void disconnect(uint32_t data) override
Disconnect from this peer.
bool send(std::unique_ptr< IPacket > packet, uint8_t channelID) override
Send a packet to this peer.
std::unique_ptr< ENetAddressWrapper > _cachedAddress
const IAddress & getAddress() const override
Get the address of this peer.
uint32_t getID() const override
Get a unique identifier for this peer.
Interface representing a network address (IP + port).