|
Zappy Server
C++ game server: world, rules, scheduler, network
|
One client socket plus its read/write buffers. More...
#include <Connection.hpp>
Collaboration diagram for Connection:Public Member Functions | |
| Connection (int fd) | |
| ~Connection () | |
| void | appendRead (std::string_view data) |
| Append freshly-read bytes to the read buffer. | |
| std::optional< std::string > | nextLine () |
| Pop one complete ' '-terminated line, or nullopt if none buffered yet. | |
| void | queueWrite (const std::string &msg) |
Append msg to the write buffer (not sent until flushWrite()). | |
| void | flushWrite () |
| Try to send the buffered write data over the socket. | |
| int | fd () const |
| ClientType | type () const |
| Client kind: PENDING until the handshake promotes it to AI or GUI. | |
| void | setType (ClientType type) |
| int | playerId () const |
| Player this connection drives (-1 for GUI / not yet assigned). | |
| void | setPlayerId (int id) |
| bool | hasPendingWrite () const |
| True if there is still unsent data in the write buffer. | |
| Connection (const Connection &)=delete | |
| Connection & | operator= (const Connection &)=delete |
Private Attributes | |
| int | _fd |
| std::string | _readBuf |
| std::string | _writeBuf |
| ClientType | _type = ClientType::PENDING |
| int | _playerId = -1 |
One client socket plus its read/write buffers.
Owns the fd (closed on destruction). Incoming bytes go into the read buffer, then come out one '
' line at a time; outgoing data is queued and flushed when the socket is writable. Also tracks the client kind (PENDING/AI/GUI) and, for an AI, which player it controls. Non-copyable.
Definition at line 17 of file Connection.hpp.
|
explicit |
Definition at line 6 of file Connection.cpp.
| Connection::~Connection | ( | ) |
Definition at line 8 of file Connection.cpp.
References _fd.
|
delete |
| void Connection::appendRead | ( | std::string_view | data | ) |
Append freshly-read bytes to the read buffer.
Definition at line 13 of file Connection.cpp.
References _readBuf.
| int Connection::fd | ( | ) | const |
Definition at line 34 of file Connection.cpp.
References _fd.
| void Connection::flushWrite | ( | ) |
Try to send the buffered write data over the socket.
Definition at line 27 of file Connection.cpp.
| bool Connection::hasPendingWrite | ( | ) | const |
True if there is still unsent data in the write buffer.
Definition at line 39 of file Connection.cpp.
References _writeBuf.
| std::optional< std::string > Connection::nextLine | ( | ) |
Pop one complete '
'-terminated line, or nullopt if none buffered yet.
Definition at line 15 of file Connection.cpp.
References _readBuf.
|
delete |
| int Connection::playerId | ( | ) | const |
Player this connection drives (-1 for GUI / not yet assigned).
Definition at line 37 of file Connection.cpp.
References _playerId.
Referenced by CommandDispatcher::_handleBroadcast(), CommandDispatcher::_handleConnectNbr(), CommandDispatcher::_handleEject(), CommandDispatcher::_handleFork(), CommandDispatcher::_handleForward(), CommandDispatcher::_handleIncantation(), CommandDispatcher::_handleInventory(), CommandDispatcher::_handleLeft(), CommandDispatcher::_handleLook(), CommandDispatcher::_handleRight(), CommandDispatcher::_handleSet(), and CommandDispatcher::_handleTake().
Here is the caller graph for this function:| void Connection::queueWrite | ( | const std::string & | msg | ) |
Append msg to the write buffer (not sent until flushWrite()).
Definition at line 25 of file Connection.cpp.
References _writeBuf.
| void Connection::setPlayerId | ( | int | id | ) |
Definition at line 38 of file Connection.cpp.
References _playerId, and id().
Referenced by HandshakeHandler::_promoteToAi().
Here is the call graph for this function:
Here is the caller graph for this function:| void Connection::setType | ( | ClientType | type | ) |
Definition at line 36 of file Connection.cpp.
Referenced by HandshakeHandler::_promoteToAi(), and HandshakeHandler::_promoteToGui().
Here is the call graph for this function:
Here is the caller graph for this function:| ClientType Connection::type | ( | ) | const |
Client kind: PENDING until the handshake promotes it to AI or GUI.
Definition at line 35 of file Connection.cpp.
References _type.
Referenced by setType().
Here is the caller graph for this function:
|
private |
Definition at line 46 of file Connection.hpp.
Referenced by fd(), flushWrite(), and ~Connection().
|
private |
Definition at line 50 of file Connection.hpp.
Referenced by playerId(), and setPlayerId().
|
private |
Definition at line 47 of file Connection.hpp.
Referenced by appendRead(), and nextLine().
|
private |
Definition at line 49 of file Connection.hpp.
|
private |
Definition at line 48 of file Connection.hpp.
Referenced by flushWrite(), hasPendingWrite(), and queueWrite().