Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | Examples

AsyncTcpConnection.h

Go to the documentation of this file.
00001 
00032 #ifndef ASYNC_TCP_CONNECTION_INCLUDED
00033 #define ASYNC_TCP_CONNECTION_INCLUDED
00034 
00035 
00036 /****************************************************************************
00037  *
00038  * System Includes
00039  *
00040  ****************************************************************************/
00041 
00042 #include <sigc++/signal_system.h>
00043 
00044 #include <string>
00045 
00046 
00047 /****************************************************************************
00048  *
00049  * Project Includes
00050  *
00051  ****************************************************************************/
00052 
00053 #include <AsyncIpAddress.h>
00054 
00055 
00056 /****************************************************************************
00057  *
00058  * Local Includes
00059  *
00060  ****************************************************************************/
00061 
00062 
00063 
00064 /****************************************************************************
00065  *
00066  * Forward declarations
00067  *
00068  ****************************************************************************/
00069 
00070 
00071 
00072 /****************************************************************************
00073  *
00074  * Namespace
00075  *
00076  ****************************************************************************/
00077 
00078 namespace Async
00079 {
00080 
00081 /****************************************************************************
00082  *
00083  * Forward declarations of classes inside of the declared namespace
00084  *
00085  ****************************************************************************/
00086 
00087 class FdWatch;
00088 class IpAddress;
00089 
00090 
00091 /****************************************************************************
00092  *
00093  * Defines & typedefs
00094  *
00095  ****************************************************************************/
00096 
00097 
00098 
00099 /****************************************************************************
00100  *
00101  * Exported Global Variables
00102  *
00103  ****************************************************************************/
00104 
00105 
00106 
00107 /****************************************************************************
00108  *
00109  * Class definitions
00110  *
00111  ****************************************************************************/
00112 
00122 class TcpConnection : public SigC::Object
00123 {
00124   public:
00128     typedef enum
00129     { 
00130       DR_HOST_NOT_FOUND,      
00131       DR_REMOTE_DISCONNECTED, 
00132       DR_SYSTEM_ERROR,        
00133       DR_RECV_BUFFER_OVERFLOW 
00134     } DisconnectReason;
00135     
00139     static const int DEFAULT_RECV_BUF_LEN = 1024;
00140     
00145     explicit TcpConnection(size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
00146     
00154     TcpConnection(int sock, const IpAddress& remote_addr,
00155                   unsigned short remote_port,
00156                   size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
00157     
00161     ~TcpConnection(void);
00162     
00170     void disconnect(void);
00171     
00178     int write(const void *buf, int count);
00179     
00186     const IpAddress& remoteHost(void) const { return remote_addr; }
00187     
00192     unsigned short remotePort(void) const { return remote_port; }
00193     
00199     SigC::Signal2<void, TcpConnection *, DisconnectReason> disconnected;
00200     
00215     SigC::Signal3<int, TcpConnection *, void *, int> dataReceived;
00216     
00222     SigC::Signal1<void, bool> sendBufferFull;
00223 
00224         
00225   protected:
00232     void setSocket(int sock);
00233     
00240     void setRemoteAddr(const IpAddress& remote_addr);
00241     
00248     void setRemotePort(unsigned short remote_port);
00249     
00257     int socket(void) const { return sock; }
00258     
00259     
00260   private:
00261     IpAddress       remote_addr;
00262     unsigned short  remote_port;
00263     size_t          recv_buf_len;
00264     int             sock;
00265     FdWatch *       rd_watch;
00266     FdWatch *       wr_watch;
00267     char *          recv_buf;
00268     size_t          recv_buf_cnt;
00269     
00270     void recvHandler(FdWatch *watch);
00271     void writeHandler(FdWatch *watch);
00272 
00273 };  /* class TcpConnection */
00274 
00275 
00276 } /* namespace */
00277 
00278 #endif /* ASYNC_TCP_CONNECTION_INCLUDED */
00279 
00280 
00281 
00282 /*
00283  * This file has not been truncated
00284  */
00285 

Generated on Thu Dec 1 22:30:32 2005 for Async by  doxygen 1.4.4