From 65ea2f177bd0810590895d89a490af8cea60253b Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Fri, 27 Jul 2007 17:19:30 +0000 Subject: * Asynchronous network IO subsystem - This is now implemented such that it very nearly only depends on the platform code (Socker & Poller), this is not 100% true at present, but should be simple to finish. - This is still not the default (use "./configure --disable-apr-netio" to get it) - Interrupting the broker gives a known error - Default for number of broker io threads is not correct (needs to be number of CPUs - it will run slower with too many io threads) * EventChannel code - Deleted all EventChannel code as it's entirely superceded by this new shiny code ;-) * Rearranged the platform Socket implementations a bit for better abstraction git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@560323 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/Socket.h | 73 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) (limited to 'cpp/src/qpid/sys/Socket.h') 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 +#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*/ -- cgit v1.2.1