aboutsummaryrefslogtreecommitdiff
path: root/src/stable/serversockettcp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/serversockettcp.h')
-rw-r--r--src/stable/serversockettcp.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/stable/serversockettcp.h b/src/stable/serversockettcp.h
new file mode 100644
index 0000000..8e43c76
--- /dev/null
+++ b/src/stable/serversockettcp.h
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2007-2019 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_SERVER_SOCKET_TCP_H
9#define BU_SERVER_SOCKET_TCP_H
10
11#include <stdint.h>
12#include "bu/string.h"
13#include "bu/exceptionbase.h"
14#include "bu/serversocket.h"
15
16#ifdef WIN32
17 #include <Winsock2.h>
18#else
19 #include <sys/select.h>
20#endif
21
22namespace Bu
23{
24 subExceptionDecl( ServerSocketTcpException );
25
26 /**
27 * A single tcp/ip server socket. When created the server socket will bind
28 * to the specified interface and port, and immediately begin listening for
29 * connections. When connections come in they are pooled by the networking
30 * drivers in the kernel until they are accepted, this means that failure
31 * to keep space in the connection pool will result in connection refusals.
32 *
33 * Although the accept function returns an integral file descriptor, it is
34 * designed to be used with the Socket class.
35 *
36 *@ingroup Serving
37 */
38 class ServerSocketTcp : public ServerSocket
39 {
40 public:
41#ifdef WIN32
42 typedef unsigned int socket_t;
43#else
44 typedef int socket_t;
45#endif
46 ServerSocketTcp( int iPort, int nPoolSize=40 );
47 ServerSocketTcp( const String &sAddr, int iPort, int nPoolSize=40 );
48 ServerSocketTcp( socket_t nSocket, bool bInit, int nPoolSize=40 );
49 ServerSocketTcp( const ServerSocketTcp &rSrc );
50 virtual ~ServerSocketTcp();
51
52 virtual Bu::Socket *accept( int nTimeoutSec=0, int nTimeoutUSec=0 );
53 virtual bool getFd( int &rFdOut ) const;
54
55 private:
56 void startServer( struct sockaddr_in &name, int nPoolSize );
57 void initServer( struct sockaddr_in &name, int nPoolSize );
58
59 fd_set fdActive;
60 socket_t iSocket;
61 int iPort;
62 };
63}
64
65#endif