Cx Class Reference
[Network]

Base class for network/file data transfert.

This class contain only methods related to data transfert (send, receive). Use a derived class to be able to open a connection, like FileCx or TcpCx. You can send/receive arbitrary data or file, or you can use the Packet class that already contains useful attributes. More...

#include <Cx.hh>

Inheritance diagram for Cx:

Inheritance graph
[legend]
List of all members.

Public Member Functions

bool poll (int timeout=0)
 Check if there is some data to fetch.
void begin ()
 Begin a send-in-batch-mode packet.
void commit ()
 End a send-in-batch-mode packet. It flush the write buffer.
void send (const Packet &pkt)
 Send a packet, or add it to the write buffer if in batch mode.
Packetreceive ()
 Receive a Packet class.

Protected Member Functions

virtual bool pollInternal (int *timeout)=0
virtual int recvData (bool use_exception)=0
virtual void sendData (unsigned char *data, unsigned size)=0
virtual void print (std::ostream &os) const
 Print some debug info.

Protected Attributes

int fd_
 The file descriptor.
int state_
 CX_WRITE / CX_READ.
char last_error_ [64]
 Last cx error, if not using exception.
unsigned char buff_send_ [BUF_SEND_SIZE]
 Internal buffer for outcoming packets.
bool batch_send_
 True if we must pack messages before sending.
unsigned buff_send_tail_
 Index to the end of used buff_send_.
unsigned char buff_recv_ [BUF_RECV_SIZE]
 Internal buffer for incoming packets.
unsigned buff_recv_head_
unsigned buff_recv_tail_

Friends

class CxPool
std::ostream & operator<< (std::ostream &os, const Cx &cx)
 Print some debug info into the stream.

Detailed Description

Base class for network/file data transfert.

This class contain only methods related to data transfert (send, receive). Use a derived class to be able to open a connection, like FileCx or TcpCx. You can send/receive arbitrary data or file, or you can use the Packet class that already contains useful attributes.

Take care that all read/write functions throw exception on error, instead of using a return value indicator. Be sure to add the necessary try/catch blocks.

See also:
TcpCx

Packet


Member Function Documentation

bool Cx::poll ( int  timeout = 0  ) 

Check if there is some data to fetch.

Note:
Be sure to call this function before trying to retrieve data.
Returns:
true if there is some data to fetch.
Exceptions:
NetError Thrown on network error, such as timeout or broken pipe.

Packet * Cx::receive (  ) 

Receive a Packet class.

Returns:
A Packet.
Note:
packet is allocated, and never deleted.

void Cx::send ( const Packet pkt  ) 

Send a packet, or add it to the write buffer if in batch mode.

Parameters:
pkt Packet to send.
Exceptions:
NetError Thrown on network error, such as timeout or broken pipe.


The documentation for this class was generated from the following files:
Generated on Sat Jun 23 16:10:15 2007 for Stechec/TBT by  doxygen 1.4.7