socket (962B)
1 #ifndef _SOCKET_ 2 #define _SOCKET_ 3 4 #include "sys/sys" 5 #include "error/error" 6 #include "config/config" 7 #include "SocketHandling/basesocket/basesocket" 8 9 // To have the smart-socket approach generate debug info: 10 // #define SOCKET_DEBUG 11 12 class Socket { 13 public: 14 Socket(); 15 Socket(Socket const &other); 16 Socket(int fd); 17 Socket(Basesocket *b); 18 ~Socket(); 19 20 Socket const &operator=(Socket const &other); 21 Socket accept(); 22 23 int fd() { 24 return _basesocket->fd(); 25 } 26 void fd(int f) { 27 _basesocket->fd(f); 28 } 29 void bind(string const &addr, int port) { 30 _basesocket->bind(addr, port); 31 } 32 bool operator==(Socket const &other) const { 33 return *_basesocket == *(other._basesocket); 34 } 35 void close() { 36 _basesocket->close(); 37 *_refcount = 1; 38 } 39 40 struct sockaddr_in clientaddr() { 41 return _basesocket->clientaddr(); 42 } 43 44 string description(); 45 46 private: 47 int *_refcount; 48 Basesocket *_basesocket; 49 }; 50 51 #endif