From 9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 16 Oct 2010 03:02:11 +0000 Subject: Many, many changes. Documentation changes, renamed the socket class to TcpSocket, fixed many other things, and finally removed ParamProc. Anything that needs it will now have to switch to OptParser. --- src/tcpserversocket.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/tcpserversocket.h (limited to 'src/tcpserversocket.h') diff --git a/src/tcpserversocket.h b/src/tcpserversocket.h new file mode 100644 index 0000000..b1d7e02 --- /dev/null +++ b/src/tcpserversocket.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007-2010 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_TCP_SERVER_SOCKET_H +#define BU_TCP_SERVER_SOCKET_H + +#include +#include "bu/fstring.h" +#include "bu/exceptionbase.h" + +#ifdef WIN32 + #include +#else + #include +#endif + +namespace Bu +{ + subExceptionDecl( TcpServerSocketException ); + + /** + * A single tcp/ip server socket. When created the server socket will bind + * to the specified interface and port, and immediately begin listening for + * connections. When connections come in they are pooled by the networking + * drivers in the kernel until they are accepted, this means that failure + * to keep space in the connection pool will result in connection refusals. + * + * Although the accept function returns an integral file descriptor, it is + * designed to be used with the Socket class. + * + *@ingroup Serving + */ + class TcpServerSocket + { + public: + TcpServerSocket( int nPort, int nPoolSize=40 ); + TcpServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 ); + TcpServerSocket( int nSocket, bool bInit, int nPoolSize=40 ); + TcpServerSocket( const TcpServerSocket &rSrc ); + virtual ~TcpServerSocket(); + + int accept( int nTimeoutSec=0, int nTimeoutUSec=0 ); + int getSocket(); + int getPort(); + + private: + void startServer( struct sockaddr_in &name, int nPoolSize ); + void initServer( struct sockaddr_in &name, int nPoolSize ); + + fd_set fdActive; +#ifdef WIN32 + unsigned int nServer; +#else + int nServer; +#endif + int nPort; + }; +} + +#endif -- cgit v1.2.3