3es
0.7
|
A TCP/IP communication socket implementation. More...
#include <3estcpsocket.h>
Public Member Functions | |
TcpSocket () | |
Constructor. | |
TcpSocket (TcpSocketDetail *detail) | |
Constructor. | |
~TcpSocket () | |
Destructor. | |
bool | open (const char *host, unsigned short port) |
Open a connection to the target host and port (blocking). More... | |
void | close () |
Close the socket connection (no custom messages sent). Safe to call when not open. | |
bool | isConnected () const |
Checks the connected state. More... | |
void | setNoDelay (bool noDelay) |
Disable Nagle's algorithm, effectively disabling send delays? More... | |
bool | noDelay () const |
Check if Nagle's algorithm is disable. More... | |
void | setReadTimeout (unsigned timeoutMs) |
Sets the blocking timeout on calls to read() . More... | |
unsigned | readTimeout () const |
Returns the read timeout. More... | |
void | setIndefiniteReadTimeout () |
Clears the timeout for read() calls, blocking indefinitely until data are available. More... | |
void | setWriteTimeout (unsigned timeoutMs) |
Sets the blocking timeout on calls to write() . More... | |
unsigned | writeTimeout () const |
Returns the write timeout. More... | |
void | setIndefiniteWriteTimeout () |
Clears the timeout for read() calls, blocking indefinitely until data have been sent. More... | |
void | setReadBufferSize (int bufferSize) |
Sets the read buffer size (bytes). More... | |
int | readBufferSize () const |
Gets the current read buffer size (bytes). | |
void | setSendBufferSize (int bufferSize) |
Sets the send buffer size (bytes). More... | |
int | sendBufferSize () const |
Gets the current send buffer size (bytes). | |
int | read (char *buffer, int bufferLength) const |
Attempts to read data from the socket until the buffer is full. More... | |
int | read (unsigned char *buffer, int bufferLength) const |
int | readAvailable (char *buffer, int bufferLength) const |
Reads available data from the socket, returning immediately if there are no data available. More... | |
int | readAvailable (unsigned char *buffer, int bufferLength) const |
int | write (const char *buffer, int bufferLength) const |
Attempts to write data from the socket. More... | |
int | write (const unsigned char *buffer, int bufferLength) const |
unsigned short | port () const |
Static Public Attributes | |
static const unsigned | IndefiniteTimeout |
Value used to signify an indefinite timeout. | |
A TCP/IP communication socket implementation.
bool tes::TcpSocket::isConnected | ( | ) | const |
Checks the connected state.
TcpSocket
was created from a TcpListenSocket
. true
if the socket is currently connected. bool tes::TcpSocket::noDelay | ( | ) | const |
Check if Nagle's algorithm is disable.
bool tes::TcpSocket::open | ( | const char * | host, |
unsigned short | port | ||
) |
Open a connection to the target host
and port
(blocking).
host | The host IP address or host name. |
port | The target port. |
int tes::TcpSocket::read | ( | char * | buffer, |
int | bufferLength | ||
) | const |
Attempts to read data from the socket until the buffer is full.
This may block. The blocking time may vary, but it will only block for at least the read timeout value so long as there is no activity.
buffer | The data buffer to read into. |
bufferLength | The maximum number of types to read into buffer . |
bufferLength
, or -1 on error.
|
inline |
int tes::TcpSocket::readAvailable | ( | char * | buffer, |
int | bufferLength | ||
) | const |
Reads available data from the socket, returning immediately if there are no data available.
buffer | The data buffer to read into. |
bufferLength | The maximum number of types to read into buffer . |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
References readAvailable().
Referenced by readAvailable().
unsigned tes::TcpSocket::readTimeout | ( | ) | const |
Returns the read timeout.
IndefiniteTimeout
indicates indefinite blocking. void tes::TcpSocket::setIndefiniteReadTimeout | ( | ) |
Clears the timeout for read()
calls, blocking indefinitely until data are available.
void tes::TcpSocket::setIndefiniteWriteTimeout | ( | ) |
Clears the timeout for read()
calls, blocking indefinitely until data have been sent.
void tes::TcpSocket::setNoDelay | ( | bool | noDelay | ) |
Disable Nagle's algorithm, effectively disabling send delays?
noDelay | Disable the delay? |
void tes::TcpSocket::setReadBufferSize | ( | int | bufferSize | ) |
Sets the read buffer size (bytes).
bufferSize | The new buffer size. Max is 2^16 - 1. |
void tes::TcpSocket::setReadTimeout | ( | unsigned | timeoutMs | ) |
Sets the blocking timeout on calls to read()
.
All calls to read()
either until there are data available or this time elapses. Set to zero for non-blocking Use setIndefiniteReadTimeout()
to block undefinately. read()
calls.
timeoutMs | Read timeout in milliseconds. |
void tes::TcpSocket::setSendBufferSize | ( | int | bufferSize | ) |
Sets the send buffer size (bytes).
bufferSize | The new buffer size. Max is 2^16 - 1. |
void tes::TcpSocket::setWriteTimeout | ( | unsigned | timeoutMs | ) |
Sets the blocking timeout on calls to write()
.
This behaves in the same way as setReadTimeout()
, except that it relates to write()
calls.
timeoutMs | Read timeout in milliseconds. |
int tes::TcpSocket::write | ( | const char * | buffer, |
int | bufferLength | ||
) | const |
Attempts to write data from the socket.
This may block for the set write timeout.
buffer | The data buffer to send. |
bufferLength | The number of bytes to send. |
|
inline |
unsigned tes::TcpSocket::writeTimeout | ( | ) | const |
Returns the write timeout.
IndefiniteTimeout
indicates indefinite blocking.