A client/server to receive/send TCPmessage. More...
#include <Beowulf/TCPcliServ.H>
Public Member Functions | |
TCPcliServ () | |
Base constructor. Must call init() later. | |
void | init (const int connected_fd, const in_addr_t my_ipaddr, const short int my_port, const in_addr_t cli_ipaddr, const short int cli_port, const int inqlen=0, const int outqlen=0, const bool indlast=false, const bool outdlast=false, const bool disableShm=false) |
(re)-initialization from a connected socket | |
TCPcliServ (const int connected_fd, const in_addr_t my_ipaddr, const short int my_port, const in_addr_t cli_ipaddr, const short int cli_port, const int inqlen=0, const int outqlen=0, const bool indlast=false, const bool outdlast=false, const bool disableShm=false) | |
Constructor and initialization from a connected socket. | |
~TCPcliServ () | |
Destructor. | |
void | send (const TCPmessage &msg) |
Send a message. | |
bool | receive (TCPmessage &msg) |
See if we have received a message (returns false if no new message). | |
int | nbReceived () |
Do we have any received messages in our queue. | |
int | check () |
Check for new incoming message and do transfers. | |
int | disconnect () |
Terminate the connection. |
A client/server to receive/send TCPmessage.
This class defines a simple client/server that handles one TCP connection and can send/receive TCPmessages over it. Messages to be sent or being received are queued; the actual transmission happens in check() which should be called often, typically under the control of a TCPcommunicator object that uses a SockServ object to know when our TCPcliServ needs attention.
this class uses a mutex to allow check() to be called from one thread while send() and receive() may simultaneously be called from another thread.
Definition at line 61 of file TCPcliServ.H.
TCPcliServ::TCPcliServ | ( | ) |
Base constructor. Must call init() later.
Definition at line 71 of file TCPcliServ.C.
TCPcliServ::TCPcliServ | ( | const int | connected_fd, | |
const in_addr_t | my_ipaddr, | |||
const short int | my_port, | |||
const in_addr_t | cli_ipaddr, | |||
const short int | cli_port, | |||
const int | inqlen = 0 , |
|||
const int | outqlen = 0 , |
|||
const bool | indlast = false , |
|||
const bool | outdlast = false , |
|||
const bool | disableShm = false | |||
) |
Constructor and initialization from a connected socket.
Definition at line 123 of file TCPcliServ.C.
References init().
TCPcliServ::~TCPcliServ | ( | ) |
int TCPcliServ::check | ( | ) |
Check for new incoming message and do transfers.
Check for new incoming message, continue reading/writing current messages, or start writing out a new message from the write queue (thread-safe). This must be called often for data to flow.
Definition at line 200 of file TCPcliServ.C.
References TCPmessage::getAction(), TCPmessage::getID(), TCPmessage::getSize(), TCPmessage::reset(), and TCPDONE.
int TCPcliServ::disconnect | ( | ) |
void TCPcliServ::init | ( | const int | connected_fd, | |
const in_addr_t | my_ipaddr, | |||
const short int | my_port, | |||
const in_addr_t | cli_ipaddr, | |||
const short int | cli_port, | |||
const int | inqlen = 0 , |
|||
const int | outqlen = 0 , |
|||
const bool | indlast = false , |
|||
const bool | outdlast = false , |
|||
const bool | disableShm = false | |||
) |
(re)-initialization from a connected socket
my_ipaddr and my_port should be my IP address and port. cli_ipaddr and cli_port should be the IP address and port of the client on the other end of connected_fd. For now, they are only used to determine whether we can optimize transfers by using shared memory in case the client's IP address matches ours. inqlen and outqlen are the maximum incoming and outgoing queue length, or zero for unlimited. indlast and outdlast specify the drop policies for ths input and output queues; if true, the last message (most recent) coming into the queue will be dropped if the queue is full, otherwise the oldest message already in the queue will be dropped.
Definition at line 75 of file TCPcliServ.C.
Referenced by TCPcliServ().
int TCPcliServ::nbReceived | ( | ) |
Do we have any received messages in our queue.
Returns the number of messages that have been fully received (not those in progress) and are waiting in the queue. Use receive() to get the messages out of the incoming queue.
Definition at line 190 of file TCPcliServ.C.
Referenced by TCPcommunicator::nbReceived().
bool TCPcliServ::receive | ( | TCPmessage & | msg | ) |
See if we have received a message (returns false if no new message).
Definition at line 179 of file TCPcliServ.C.
Referenced by TCPcommunicator::receiveIt().
void TCPcliServ::send | ( | const TCPmessage & | msg | ) |