00001 #ifndef _sys_Socket_h
00002 #define _sys_Socket_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "IOHandle.h"
00025
00026 #include <string>
00027
00028 struct sockaddr;
00029
00030 namespace qpid {
00031 namespace sys {
00032
00033 class Duration;
00034
00035 class Socket : public IOHandle
00036 {
00037 public:
00039 Socket();
00040
00042 void createTcp() const;
00043
00045 void setTimeout(const Duration& interval) const;
00046
00048 void setNonblocking() const;
00049
00050 void connect(const std::string& host, int port) const;
00051
00052 void close() const;
00053
00054 enum { SOCKET_TIMEOUT=-2, SOCKET_EOF=-3 } ErrorCode;
00055
00057 ssize_t send(const void* data, size_t size) const;
00058
00063 ssize_t recv(void* data, size_t size) const;
00064
00070 int listen(int port = 0, int backlog = 10) const;
00071
00075 std::string getSockname() const;
00076
00080 std::string getPeername() const;
00081
00086 std::string getPeerAddress() const;
00091 std::string getLocalAddress() const;
00092
00093 uint16_t getLocalPort() const;
00094 uint16_t getRemotePort() const;
00095
00100 int getError() const;
00101
00105 Socket* accept(struct sockaddr *addr, socklen_t *addrlen) const;
00106
00107
00108 int read(void *buf, size_t count) const;
00109 int write(const void *buf, size_t count) const;
00110
00111 struct Configuration
00112 {
00113 virtual void configurePosixTcpSocket(int fd) const = 0;
00114 virtual ~Configuration() {}
00115 };
00116
00117 void configure(const Configuration&);
00118
00119 private:
00120 Socket(IOHandlePrivate*);
00121 };
00122
00123 }}
00124 #endif