|
plptools
|
A class for dealing with sockets. More...
#include <tcpsocket.h>

Public Member Functions | |
| TCPSocket () | |
| Constructs a TCPSocket. More... | |
| TCPSocket (const TCPSocket &) | |
| Copy constructor. More... | |
| virtual | ~TCPSocket () |
| Destructor. More... | |
| virtual bool | connect (const char *const Peer, int PeerPort, const char *const Host=NULL, int HostPort=0) |
| Connects to a given host. More... | |
| virtual bool | reconnect () |
| Reopens the connection after closing it. More... | |
| virtual std::string | toString () |
| Retrieve a string representation of the TCPSocket. More... | |
| virtual bool | listen (const char *const Host, int Port) |
| Starts listening. More... | |
| TCPSocket * | accept (std::string *Peer) |
| Accept a connection; blocking, non-cancellable. More... | |
| TCPSocket * | accept (std::string *Peer, int cancellationFd) |
| Accept a connection; blocking, cancellable. More... | |
| bool | dataToGet (int sec, int usec) const |
| Check and optionally wait for incoming data. More... | |
| int | getBufferStore (bufferStore &a, bool wait=true) |
| Receive data into a bufferStore . More... | |
| bool | sendBufferStore (const bufferStore &a) |
| Sends data from a bufferStore . More... | |
| bool | closeSocket (void) |
| Closes the connection. More... | |
| bool | bindSocket (const char *const Host, int Port) |
| Binds to a local address and port. More... | |
| bool | bindInRange (const char *const Host, int Low, int High, int Retries) |
| Tries repeated binds to a local address and port. More... | |
| bool | linger (bool LingerOn, int LingerTime=0) |
| Sets the linger parameter of the socket. More... | |
| bool | getPeer (std::string *Peer, int *Port) |
| Retrieves peer information. More... | |
| bool | getHost (std::string *Host, int *Port) |
| Retrieves local information. More... | |
| void | setWatch (IOWatch *watch) |
| Registers an IOWatch for this socket. More... | |
Private Member Functions | |
| virtual bool | createSocket (void) |
| Creates the socket. More... | |
| int | getLastError (void) |
| bool | setPeer (const char *const Peer, int Port) |
| bool | setHost (const char *const Host, int Port) |
| int | recv (void *buf, int len, int flags) |
| int | send (const void *const buf, int len, int flags) |
Private Attributes | |
| struct sockaddr | m_HostAddr |
| struct sockaddr | m_PeerAddr |
| int | m_Socket |
| int | m_Port |
| bool | m_Bound |
| int | m_LastError |
| IOWatch * | myWatch |
A class for dealing with sockets.
Definition at line 37 of file tcpsocket.h.
| TCPSocket::TCPSocket | ( | ) |
Constructs a TCPSocket.
Definition at line 63 of file tcpsocket.cc.
| TCPSocket::TCPSocket | ( | const TCPSocket & | another | ) |
Copy constructor.
Definition at line 52 of file tcpsocket.cc.
|
virtual |
Destructor.
Definition at line 78 of file tcpsocket.cc.
| TCPSocket * TCPSocket::accept | ( | std::string * | Peer | ) |
Accept a connection; blocking, non-cancellable.
| Peer | If non-Null, the peer's name is returned here. |
Definition at line 207 of file tcpsocket.cc.
| TCPSocket * TCPSocket::accept | ( | std::string * | Peer, |
| int | cancellationFd | ||
| ) |
Accept a connection; blocking, cancellable.
| Peer | If non-Null, the peer's name is returned here. |
| cancellationFd | File descriptor that can be used to signal cancellation. |
Definition at line 251 of file tcpsocket.cc.
| bool TCPSocket::bindInRange | ( | const char *const | Host, |
| int | Low, | ||
| int | High, | ||
| int | Retries | ||
| ) |
Tries repeated binds to a local address and port.
If Retries is <= High - Low, then the port to bind is randomly chosen in the given range. Otherwise, all ports starting from High up to Low are tried in sequence.
| Host | The local address to bind to. |
| Low | The lowest local port to listen on. |
| High | The highest local port to listen on. |
| Retries | The number of retries until giving up. |
Definition at line 424 of file tcpsocket.cc.
| bool TCPSocket::bindSocket | ( | const char *const | Host, |
| int | Port | ||
| ) |
Binds to a local address and port.
| Host | The local address to bind to. |
| Port | The local port to listen on. |
Definition at line 387 of file tcpsocket.cc.
| bool TCPSocket::closeSocket | ( | void | ) |
Closes the connection.
Definition at line 373 of file tcpsocket.cc.
|
virtual |
Connects to a given host.
| Peer | The Host to connect to (name or dotquad-string). |
| PeerPort | The port to connect to. |
| Host | The local address to bind to. |
| HostPort | The local port to bind to. |
Definition at line 152 of file tcpsocket.cc.
|
privatevirtual |
Creates the socket.
Definition at line 501 of file tcpsocket.cc.
| bool TCPSocket::dataToGet | ( | int | sec, |
| int | usec | ||
| ) | const |
Check and optionally wait for incoming data.
| sec | Timeout in seconds |
| usec | Timeout in microseconds |
Definition at line 276 of file tcpsocket.cc.
| int TCPSocket::getBufferStore | ( | bufferStore & | a, |
| bool | wait = true |
||
| ) |
Receive data into a bufferStore .
| a | The bufferStore to fill with received data. |
| wait | If true, wait until something is received, else return if no data is available. |
Definition at line 288 of file tcpsocket.cc.
| bool TCPSocket::getHost | ( | std::string * | Host, |
| int * | Port | ||
| ) |
Retrieves local information.
| Host | The local name is returned here. |
| Port | The local port is returned here. |
Definition at line 608 of file tcpsocket.cc.
|
inlineprivate |
Definition at line 222 of file tcpsocket.h.
| bool TCPSocket::getPeer | ( | std::string * | Peer, |
| int * | Port | ||
| ) |
Retrieves peer information.
| Peer | The peers name is returned here. |
| Port | The peers port is returned here. |
Definition at line 555 of file tcpsocket.cc.
| bool TCPSocket::linger | ( | bool | LingerOn, |
| int | LingerTime = 0 |
||
| ) |
Sets the linger parameter of the socket.
| LingerOn | true, if lingering should be on. |
| LingerTime | If lingering is on, the linger-time. |
Definition at line 472 of file tcpsocket.cc.
|
virtual |
Starts listening.
| Host | The local address to bind to. |
| Port | The local port to listen on. |
Definition at line 182 of file tcpsocket.cc.
|
virtual |
Reopens the connection after closing it.
Definition at line 99 of file tcpsocket.cc.
|
private |
Definition at line 351 of file tcpsocket.cc.
|
private |
Definition at line 362 of file tcpsocket.cc.
| bool TCPSocket::sendBufferStore | ( | const bufferStore & | a | ) |
Sends data from a bufferStore .
| a | The bufferStore to send. |
Definition at line 324 of file tcpsocket.cc.
|
private |
Definition at line 573 of file tcpsocket.cc.
|
private |
Definition at line 522 of file tcpsocket.cc.
| void TCPSocket::setWatch | ( | IOWatch * | watch | ) |
Registers an IOWatch for this socket.
This IOWatch gets the socket added/removed automatically.
| watch | The IOWatch to register. |
Definition at line 88 of file tcpsocket.cc.
|
virtual |
Retrieve a string representation of the TCPSocket.
Definition at line 127 of file tcpsocket.cc.
|
private |
Definition at line 232 of file tcpsocket.h.
|
private |
Definition at line 228 of file tcpsocket.h.
|
private |
Definition at line 233 of file tcpsocket.h.
|
private |
Definition at line 229 of file tcpsocket.h.
|
private |
Definition at line 231 of file tcpsocket.h.
|
private |
Definition at line 230 of file tcpsocket.h.
|
private |
Definition at line 234 of file tcpsocket.h.