diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/tcpserversocket.h | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/tcpserversocket.h')
-rw-r--r-- | src/stable/tcpserversocket.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/stable/tcpserversocket.h b/src/stable/tcpserversocket.h new file mode 100644 index 0000000..efb7287 --- /dev/null +++ b/src/stable/tcpserversocket.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 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/string.h" | ||
13 | #include "bu/exceptionbase.h" | ||
14 | |||
15 | #ifdef WIN32 | ||
16 | #include <Winsock2.h> | ||
17 | #else | ||
18 | #include <sys/select.h> | ||
19 | #endif | ||
20 | |||
21 | namespace 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 String &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 | ||