00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef CXXTOOLS_NET_NET_H
00030 #define CXXTOOLS_NET_NET_H
00031
00032 #include <cxxtools/ioerror.h>
00033 #include <cxxtools/noncopyable.h>
00034
00035 namespace cxxtools
00036 {
00037
00038 namespace net
00039 {
00040 typedef IOTimeout Timeout;
00041
00042 class AddressInUse : public IOError
00043 {
00044 public:
00045 AddressInUse();
00046 };
00047
00049
00052 class Socket : private NonCopyable
00053 {
00054
00055 public:
00057 Socket(int domain, int type, int protocol);
00058
00061 explicit Socket(int fd = -1)
00062 : m_sockFd(fd),
00063 m_timeout(-1)
00064 { }
00065
00068 virtual ~Socket();
00069
00071 bool good() const { return m_sockFd >= 0; }
00073 bool bad() const { return m_sockFd < 0; }
00075 operator bool() const { return m_sockFd >= 0; }
00076
00079 void create(int domain, int type, int protocol);
00081 void close();
00082
00084 int getFd() const { return m_sockFd; }
00085
00087 std::string getSockAddr() const;
00088
00090 void setTimeout(int t);
00092 int getTimeout() const { return m_timeout; }
00093
00096 short poll(short events) const;
00097
00098 protected:
00099 void setFd(int sockFd);
00100
00101 private:
00102 int m_sockFd;
00103 int m_timeout;
00104 };
00105
00106 }
00107
00108 }
00109
00110 #endif // CXXTOOLS_NET_NET_H