summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/Socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys/Socket.h')
-rw-r--r--cpp/src/qpid/sys/Socket.h73
1 files changed, 68 insertions, 5 deletions
diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h
index bb1ef27e65..56b6195b65 100644
--- a/cpp/src/qpid/sys/Socket.h
+++ b/cpp/src/qpid/sys/Socket.h
@@ -21,11 +21,74 @@
* under the License.
*
*/
+#include <string>
+#include "qpid/sys/Time.h"
-#ifdef USE_APR_PLATFORM
-#include "apr/Socket.h"
-#else
-#include "posix/Socket.h"
-#endif
+struct sockaddr;
+namespace qpid {
+namespace sys {
+
+class SocketPrivate;
+class Socket
+{
+ friend class Poller;
+
+ SocketPrivate* const impl;
+
+public:
+ /** Create a socket wrapper for descriptor. */
+ Socket();
+ ~Socket();
+
+ /** Create an initialized TCP socket */
+ void createTcp() const;
+
+ /** Set timeout for read and write */
+ void setTimeout(const Duration& interval) const;
+
+ /** Set socket non blocking */
+ void setNonblocking() const;
+
+ void connect(const std::string& host, int port) const;
+
+ void close() const;
+
+ enum { SOCKET_TIMEOUT=-2, SOCKET_EOF=-3 } ErrorCode;
+
+ /** Returns bytes sent or an ErrorCode value < 0. */
+ ssize_t send(const void* data, size_t size) const;
+
+ /**
+ * Returns bytes received, an ErrorCode value < 0 or 0
+ * if the connection closed in an orderly manner.
+ */
+ ssize_t recv(void* data, size_t size) const;
+
+ /** Bind to a port and start listening.
+ *@param port 0 means choose an available port.
+ *@param backlog maximum number of pending connections.
+ *@return The bound port.
+ */
+ int listen(int port = 0, int backlog = 10) const;
+
+ /** Returns the "socket name" ie the address bound to
+ * the near end of the socket
+ */
+ std::string getSockname() const;
+
+ /** Accept a connection from a socket that is already listening
+ * and has an incoming connection
+ */
+ Socket* accept(struct sockaddr *addr, socklen_t *addrlen) const;
+
+ // TODO The following are raw operations, maybe they need better wrapping?
+ int read(void *buf, size_t count) const;
+ int write(const void *buf, size_t count) const;
+
+private:
+ Socket(SocketPrivate*);
+};
+
+}}
#endif /*!_sys_Socket_h*/