diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-01-10 21:04:17 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-10 21:04:17 +0000 |
commit | 2ba3f84ab559da02a11aa000b3cecb3b3668af61 (patch) | |
tree | 266f450b512f607ec54d54af4fa8c13fdbe7ef91 /src/tcpserversocket.h | |
parent | ea18007633b31901f2ae275cc0576c3f7ce99fc9 (diff) | |
parent | 3611f253f6fdfa4954d374ab85ddaa7f799c130c (diff) | |
download | libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.gz libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.bz2 libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.xz libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.zip |
Merged in the core branch. This is a major update that fixes many things, and
changes many others, including source files that were deleted and renamed.
Before doing this update, I reccomend a full clean, or even a fresh checkout.
Things to note, most outstanding about this update:
- Bu::Socket was changed to Bu::TcpSocket and the default mode is blocking.
- All templatized container classes are SharedCore now, which is good, but
SharedCore is inherently non-reentrant safe. However, all SharedCore classes
have a "clone" function that return a non-shared copy of the object, safe for
passing into a reentrant safe function accessing shared memory.
Diffstat (limited to 'src/tcpserversocket.h')
-rw-r--r-- | src/tcpserversocket.h | 64 |
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 | |||
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 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 | ||