#include <BTCPConnection.h>
Inheritance diagram for BTCPConnection:
Public Member Functions | |
BTCPConnection (long addr, short port) | |
TCP client constructor -- connect to addr, port. | |
BTCPConnection (const std::string &host, short port) | |
TCP client constructor -- connect to host, port. | |
BTCPConnection (short port) | |
TCP server constructor -- listen on port. | |
BTCPConnection () | |
TCP server constructor -- don't listen at all (call bind() later). | |
void | bind (short port) |
Bind to the given port (if not already bound). | |
short | portNumber () |
Return the port the connection is bound to. | |
virtual void | handle () |
Handle incoming connections and connection attempts. Call periodically. | |
virtual void | close () |
Close connection. | |
bool | connected () |
Return true if connected. | |
int | writeRaw (const unsigned char *buf, int buflen) |
Send the buffer over the connection. Return the number of bytes sent. | |
bool | write (const unsigned char *buf, int buflen=-1) |
Send the buffer over the connection, making sure everything gets sent. | |
bool | write (const char *buf, int buflen=-1) |
Send the buffer over the connection, making sure everything gets sent. | |
int | read (char *buf, int buflen) |
Read from the connection. | |
bool | makeBlocking () |
Make the connection blocking. Subsequent calls to writeRaw() may block. | |
bool | makeNonblocking () |
Make the connection nonblocking. Calls to writeRaw() may return 0. | |
Protected Member Functions | |
virtual void | handleClose () |
Called if the remote closes the connection. | |
virtual bool | handleConnection () |
Called by handle() if connected. Read and write in here. | |
virtual bool | handleInput (const unsigned char *buf, int bufleno) |
Called by the default handleConnection() if input was received. | |
virtual bool | handleAccept () |
Called by handle() if not connected. Accept in here. | |
unsigned int | readBlockSize () |
Return the size of the read block (buf). | |
void | setReadBlockSize (unsigned int rbs) |
Set the size of the read block. | |
Protected Attributes | |
short | portnum |
The port the connection is listening on, or -1 if it's not. | |
int | sock |
The server socket. | |
int | conn |
The connection socket. | |
bool | doNonblocking |
If this is true, accept()ed connections are nonblocking by default. | |
bool | isServer |
True if this connection is a server. | |
unsigned int | rbs |
Size of the read block (buf). | |
unsigned char * | buf |
The read block. Use this for data transfer. | |
sockaddr_in | lastaddr |
The address of the last connection partner. |