Preserves record boundaries when exchanging messages between connected TCP/IP sockets. More...
Public Member Functions | |
SOCKSIZE | readLine (std::string &message) |
Read a message from a connected socket. More... | |
SOCKSIZE | writeLine (const std::string &message) |
Send a message to a connected socket. More... | |
SOCKSIZE | read (char *buffer, size_t len) |
Reads exactly len bytes from the socket, blocks otherwise. More... | |
SOCKSIZE | write (const char *str, size_t len) |
Writes len bytes to the socket. More... | |
GNatSocket * | socket () |
Returns the associated socket. | |
GNatSocketBuffer (GNatSocket *, size_t inputSize=8192, size_t ouputSize=8192) | |
Constructor. More... | |
void | setReadSeparator (int separ) |
Returns/changes the separator used by readLine(). More... | |
void | setWriteSeparator (int separ) |
Returns/changes the separator used by writeLine(). More... | |
Preserves record boundaries when exchanging messages between connected TCP/IP sockets.
Ensures that one call to readLine() corresponds to one and exactly one call to writeLine() on the other side. By default, writeLine() adds
at the end of each message and readLine() searches for
, or
so that it can retreive the entire record. Beware messages should thus not contain these charecters.
GNatSocketBuffer::GNatSocketBuffer | ( | GNatSocket * | sock, |
size_t | inputSize = 8192 , |
||
size_t | ouputSize = 8192 |
||
) |
Constructor.
socket must be a connected TCP/IP Socket. It should not be deleted as long as the SocketBuffer is used. inputSize and ouputSize are the sizes of the buffers that are used internally for exchanging data.
SOCKSIZE GNatSocketBuffer::readLine | ( | std::string & | message) |
Read a message from a connected socket.
readLine() receives one (and only one) message sent by writeLine() on the other side, ie, a call to writeLine() corresponds to one and exactly one call to readLine() on the other side. The received data is stored in message. This method blocks until the message is fully received.
SOCKSIZE GNatSocketBuffer::writeLine | ( | const std::string & | message) |
Send a message to a connected socket.
writeLine() sends a message that will be received by a single call of readLine() on the other side,
SOCKSIZE GNatSocketBuffer::read | ( | char * | buffer, |
size_t | len | ||
) |
Reads exactly len bytes from the socket, blocks otherwise.
SOCKSIZE GNatSocketBuffer::write | ( | const char * | str, |
size_t | len | ||
) |
Writes len bytes to the socket.
void GNatSocketBuffer::setReadSeparator | ( | int | separ) |
Returns/changes the separator used by readLine().
setReadSeparator() changes the symbol used by readLine() to separate successive messages:
void GNatSocketBuffer::setWriteSeparator | ( | int | separ) |
Returns/changes the separator used by writeLine().
setWriteSeparator() changes the character(s) used by writeLine() to separate successive messages: