summaryrefslogtreecommitdiff
path: root/src/tcpserversocket.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-16 03:02:11 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-16 03:02:11 +0000
commit9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5 (patch)
tree17bc9d96b13d16d79385016c087321fc1267743f /src/tcpserversocket.h
parent93c028162318a00b9bd03fc4a48383f830cc529d (diff)
downloadlibbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.gz
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.bz2
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.xz
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.zip
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.
Diffstat (limited to 'src/tcpserversocket.h')
-rw-r--r--src/tcpserversocket.h64
1 files changed, 64 insertions, 0 deletions
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 @@
1/*
2 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_TCP_SERVER_SOCKET_H
9#define BU_TCP_SERVER_SOCKET_H
10
11#include <stdint.h>
12#include "bu/fstring.h"
13#include "bu/exceptionbase.h"
14
15#ifdef WIN32
16 #include <Winsock2.h>
17#else
18 #include <sys/select.h>
19#endif
20
21namespace Bu
22{
23 subExceptionDecl( TcpServerSocketException );
24
25 /**
26 * A single tcp/ip server socket. When created the server socket will bind
27 * to the specified interface and port, and immediately begin listening for
28 * connections. When connections come in they are pooled by the networking
29 * drivers in the kernel until they are accepted, this means that failure
30 * to keep space in the connection pool will result in connection refusals.
31 *
32 * Although the accept function returns an integral file descriptor, it is
33 * designed to be used with the Socket class.
34 *
35 *@ingroup Serving
36 */
37 class TcpServerSocket
38 {
39 public:
40 TcpServerSocket( int nPort, int nPoolSize=40 );
41 TcpServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 );
42 TcpServerSocket( int nSocket, bool bInit, int nPoolSize=40 );
43 TcpServerSocket( const TcpServerSocket &rSrc );
44 virtual ~TcpServerSocket();
45
46 int accept( int nTimeoutSec=0, int nTimeoutUSec=0 );
47 int getSocket();
48 int getPort();
49
50 private:
51 void startServer( struct sockaddr_in &name, int nPoolSize );
52 void initServer( struct sockaddr_in &name, int nPoolSize );
53
54 fd_set fdActive;
55#ifdef WIN32
56 unsigned int nServer;
57#else
58 int nServer;
59#endif
60 int nPort;
61 };
62}
63
64#endif