A client TCP socket for connecting to remote hosts. More...
#include <Radiant/TCPSocket.hpp>
Public Types | |
| enum | Flags { NONBLOCK, WAIT_SOME, WAIT_ALL } |
| Flags used with read() -function. More... | |
Public Member Functions | |
| virtual bool | close () |
| Closes the socket. More... | |
| const QString & | host () const |
| Returns the hostname. More... | |
| virtual bool | isHungUp () const |
| Returns true if the socket has been closed. More... | |
| virtual bool | isOpen () const |
| Returns true of the socket is open. More... | |
| virtual bool | isPendingInput (unsigned int waitMicroSeconds=0) |
| Return 'true' if readable data is pending. More... | |
| int | open (const char *host, int port) |
| Opens a TCP socket to desired host:port. More... | |
| TCPSocket & | operator= (TCPSocket &&socket) |
| Move the given socket. More... | |
| int | port () const |
| Returns the port number. More... | |
| int | read (void *buffer, int bytes, Flags flags) |
| Read bytes from the socket. More... | |
| virtual int | read (void *buffer, int bytes, bool waitfordata=true) |
| Read bytes from the socket. More... | |
| unsigned long | rxBytes () const |
| Number of bytes received through the socket. More... | |
| bool | setNoDelay (bool noDelay) |
| Turn the Nagle algorithm on or off. More... | |
| TCPSocket () | |
| Constructor. | |
| TCPSocket (int fd) | |
| Construct a socket based on a file descriptor This method is potentially non-portable as not all platforms use file descriptors to handle sockets. More... | |
| TCPSocket (TCPSocket &&socket) | |
| Move the given socket. More... | |
| unsigned long | txBytes () const |
| Number of bytes sent through the socket. More... | |
| virtual int | write (const void *buffer, int bytes) |
| Write bytes to the socket. More... | |
| ~TCPSocket () | |
| Destructor. Closes the socket. | |
Public Member Functions inherited from Radiant::BinaryStream | |
| BinaryStream () | |
| Constructor. | |
| virtual | ~BinaryStream () |
| Destructor. | |
Friends | |
| class | TCPServerSocket |
A client TCP socket for connecting to remote hosts.
Flags used with read() -function.
| Enumerator | |
|---|---|
| NONBLOCK |
Never block. |
| WAIT_SOME |
Block until some data is read or socket has a read error. |
| WAIT_ALL |
Blocks until all requested data is read or socket has a read error. |
| Radiant::TCPSocket::TCPSocket | ( | int | fd | ) |
Construct a socket based on a file descriptor This method is potentially non-portable as not all platforms use file descriptors to handle sockets.
| fd | socket file descriptor |
| Radiant::TCPSocket::TCPSocket | ( | TCPSocket && | socket | ) |
Move the given socket.
| socket | socket to move |
|
virtual |
Closes the socket.
Reimplemented from Radiant::BinaryStream.
| const QString& Radiant::TCPSocket::host | ( | ) | const |
Returns the hostname.
|
virtual |
Returns true if the socket has been closed.
Reimplemented from Radiant::BinaryStream.
|
virtual |
Returns true of the socket is open.
Reimplemented from Radiant::BinaryStream.
|
virtual |
Return 'true' if readable data is pending.
| waitMicroSeconds | How long this call will block at most |
Reimplemented from Radiant::BinaryStream.
| int Radiant::TCPSocket::open | ( | const char * | host, |
| int | port | ||
| ) |
Opens a TCP socket to desired host:port.
| host | hostname |
| port | port |
Move the given socket.
| socket | socket to move |
| int Radiant::TCPSocket::port | ( | ) | const |
Returns the port number.
| int Radiant::TCPSocket::read | ( | void * | buffer, |
| int | bytes, | ||
| Flags | flags | ||
| ) |
Read bytes from the socket.
| [out] | buffer | pointer to a buffer to store the read data to |
| bytes | how many bytes the buffer has room for | |
| flags | Blocking behaviour |
|
inlinevirtual |
Read bytes from the socket.
| [out] | buffer | pointer to a buffer to store the read data to |
| bytes | how many bytes the buffer has room for | |
| waitfordata | wait for all data or do not block at all |
Implements Radiant::BinaryStream.
| unsigned long Radiant::TCPSocket::rxBytes | ( | ) | const |
Number of bytes received through the socket.
This count gets cleared when a socket is opened.
| bool Radiant::TCPSocket::setNoDelay | ( | bool | noDelay | ) |
Turn the Nagle algorithm on or off.
This controls the queuing of messages to fill packets.
| noDelay | if true, the queing is not used and packets are sent immediately |
| unsigned long Radiant::TCPSocket::txBytes | ( | ) | const |
Number of bytes sent through the socket.
This count gets cleared when a socket is opened.
|
virtual |
Write bytes to the socket.
| buffer | Data to write |
| bytes | How many bytes is requested to be written |
Implements Radiant::BinaryStream.