lmsg/Socket.hh

00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 #ifndef LMSG_SOCKET_HH
00003 #define LMSG_SOCKET_HH
00004 #include "lmsg/MsgTypes.hh"
00005 #include "lmsg/MsgAddr.hh"
00006 
00007 namespace lmsg {
00008   class Buffer;
00009   class BufferPool;
00010   class SocketPool;
00011 
00018   class Socket {
00019   public:
00020 
00023     typedef struct sockaddr_in   ipsock_t;
00024 
00028     Socket(void);
00029 
00033     virtual ~Socket(void);
00034 
00041     MsgAddr getAddr(void) const;
00042 
00047     int getDebug(void) const;
00048 
00059     MsgAddr getPartner(void) const;
00060 
00065     int getRecvBuf(void) const;
00066 
00071     int getSendBuf(void) const;
00072 
00077     bool isConnected(void) const;
00078 
00083     bool isOpen(void) const;
00084 
00095     virtual error_type async(bool enable=true);
00096 
00102     virtual error_type bind(const MsgAddr* addr);
00103 
00110     virtual error_type connect(const MsgAddr& addr);
00111 
00117     virtual error_type disconnect(void);
00118 
00125     virtual error_type read(char* data, size_type len);
00126 
00137     virtual error_type receive(Buffer** Data);
00138 
00148     virtual error_type receive(Buffer* Data);
00149 
00155     virtual error_type send(Buffer* b);
00156 
00163     virtual error_type send(const MsgAddr& to, Buffer* b);
00164 
00173     error_type wait(wtime_type maxtime) const;
00174 
00186     static error_type waitAny(wtime_type maxtime, int N, const Socket* list[]);
00187 
00192     void setDebug(int level);
00193 
00198     void setPool(BufferPool* pool);
00199 
00204     void setPool(SocketPool* pool);
00205 
00210     error_type setRecvBuf(int nBytes);
00211 
00216     error_type setSendBuf(int nBytes);
00217 
00221     void Return(void);
00222 
00223   protected:
00225     MsgAddr     myAddr;
00227     MsgAddr     mPartner;
00229     BufferPool* mBPool;
00231     bool        mConnected;
00233     int         mSocket;
00234 
00235   private:
00236     SocketPool* mSPool;
00237     int         mDebug;
00238   };
00239 } // namespace lmsg
00240 
00241 inline int
00242 lmsg::Socket::getDebug(void) const {
00243     return mDebug;
00244 }
00245 
00246 inline bool
00247 lmsg::Socket::isConnected(void) const {
00248     return mConnected;
00249 }
00250 
00251 inline bool
00252 lmsg::Socket::isOpen(void) const {
00253     return mSocket>=0;
00254 }
00255 
00256 #endif // LMSG_SOCKET_HH

Generated on Sun Mar 8 19:20:50 2009 for dmt by  doxygen 1.5.4