00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024 #ifndef SOCKETS_SOCKET_H
00025 #define SOCKETS_SOCKET_H
00026
00027
00028
00029 #if HAVE_SYS_SOCKET_H
00030 # include <sys/socket.h>
00031 #endif
00032
00033 #if HAVE_NETINET_IN_H
00034 # include <netinet/in.h>
00035 #endif
00036
00037 #if HAVE_SYS_UN_H
00038 # include <sys/un.h>
00039 #endif
00040
00041 #include <string>
00042
00043
00044
00046
00047 namespace sockets
00048 {
00049
00050
00051
00052 class Monitor;
00053
00054
00055
00057
00065 class Socket
00066 {
00067 public:
00068
00069
00071 friend class SSLInfo;
00072
00073
00074
00076 enum
00077 {
00079 ssCreated = 0x00000001,
00081 ssLocalInfo = 0x00000002,
00083 ssRemoteInfo = 0x00000004,
00085 ssBound = 0x00000008,
00087 ssConnecting = 0x00000010,
00089 ssConnected = 0x00000020,
00091 ssListening = 0x00000040,
00093 ssMonitored = 0x00000080,
00095 ssReadable = 0x00000100,
00097 ssWritable = 0x00000200,
00099 ssSSL = 0x00000400,
00101 ssSSLHandshake = 0x00000800,
00102
00104 ssCloseFlags = (ssCreated | ssBound | ssConnecting | ssConnected |
00105 ssListening | ssMonitored | ssReadable | ssWritable |
00106 ssSSLHandshake),
00108 ssCopyFlags = (ssLocalInfo | ssRemoteInfo | ssSSL)
00109 };
00110
00111
00112
00114
00121 static void init(size_t hint);
00122
00124 static char const *hostname();
00125
00126
00127
00129
00141 explicit Socket(int family = PF_UNSPEC, int type = 0,
00142 int protocol = 0);
00144
00148 Socket(Socket const &s) : m_fd(-1), m_family(s.m_family),
00149 m_type(s.m_type), m_protocol(s.m_protocol),
00150 m_status(s.m_status & ssCopyFlags), m_monitor(s.m_monitor) { }
00152
00156 virtual Socket &operator=(Socket const &right);
00158
00159 virtual ~Socket();
00160
00162
00176 virtual bool assign(int fd, uint32_t status);
00177
00179
00184 virtual bool read_event() { return true; }
00185
00187
00192 virtual bool write_event() { return true; }
00193
00195 int family() const { return m_family; }
00197 int type() const { return m_type; }
00199 int protocol() const { return m_protocol; }
00200
00202
00206 uint32_t status() const { return m_status; }
00207
00209 std::string const &monitor() const;
00211
00219 bool monitor(std::string const &name);
00220 protected:
00222
00234 virtual bool create();
00235
00237
00246 virtual bool close();
00247
00249
00258 virtual bool watch();
00259
00261
00265 virtual void unwatch();
00266
00268
00272 int fd() const { return m_fd; }
00273
00275
00280 int family(int family);
00281
00283
00288 int type(int type);
00289
00291
00296 int protocol(int protocol);
00297
00299
00304 uint32_t status_add(uint32_t flags) { return (m_status |= flags); }
00305
00307
00312 uint32_t status_remove(uint32_t flags) { return (m_status &= ~flags); }
00313 private:
00315 int m_fd;
00316
00318 int m_family;
00320 int m_type;
00322 int m_protocol;
00323
00325 uint32_t m_status;
00326
00328 Monitor *m_monitor;
00329 };
00330
00331
00332
00333
00334
00335
00336
00337 }
00338
00339
00340
00341 #endif