diff options
Diffstat (limited to 'src/serversocket.cpp')
-rw-r--r-- | src/serversocket.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/serversocket.cpp b/src/serversocket.cpp index 89fef7e..b3a8c2d 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp | |||
@@ -65,9 +65,37 @@ Bu::ServerSocket::ServerSocket(const FString &sAddr,int nPort, int nPoolSize) : | |||
65 | startServer( name, nPoolSize ); | 65 | startServer( name, nPoolSize ); |
66 | } | 66 | } |
67 | 67 | ||
68 | Bu::ServerSocket::ServerSocket( int nServer, bool bInit, int nPoolSize ) : | ||
69 | nServer( nServer ), | ||
70 | nPort( 0 ) | ||
71 | { | ||
72 | if( bInit ) | ||
73 | { | ||
74 | struct sockaddr name; | ||
75 | socklen_t namelen = sizeof(name); | ||
76 | getpeername( nServer, &name, &namelen ); | ||
77 | |||
78 | initServer( *((sockaddr_in *)&name), nPoolSize ); | ||
79 | } | ||
80 | else | ||
81 | { | ||
82 | FD_ZERO( &fdActive ); | ||
83 | FD_SET( nServer, &fdActive ); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | Bu::ServerSocket::ServerSocket( const ServerSocket &rSrc ) | ||
88 | { | ||
89 | nServer = dup( rSrc.nServer ); | ||
90 | nPort = rSrc.nPort; | ||
91 | FD_ZERO( &fdActive ); | ||
92 | FD_SET( nServer, &fdActive ); | ||
93 | } | ||
94 | |||
68 | Bu::ServerSocket::~ServerSocket() | 95 | Bu::ServerSocket::~ServerSocket() |
69 | { | 96 | { |
70 | ::close( nServer ); | 97 | if( nServer > -1 ) |
98 | ::close( nServer ); | ||
71 | } | 99 | } |
72 | 100 | ||
73 | void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | 101 | void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) |
@@ -79,7 +107,7 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | |||
79 | { | 107 | { |
80 | throw Bu::ServerSocketException("Couldn't create a listen socket."); | 108 | throw Bu::ServerSocketException("Couldn't create a listen socket."); |
81 | } | 109 | } |
82 | 110 | ||
83 | int opt = 1; | 111 | int opt = 1; |
84 | bu_setsockopt( | 112 | bu_setsockopt( |
85 | nServer, | 113 | nServer, |
@@ -89,6 +117,11 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) | |||
89 | sizeof( opt ) | 117 | sizeof( opt ) |
90 | ); | 118 | ); |
91 | 119 | ||
120 | initServer( name, nPoolSize ); | ||
121 | } | ||
122 | |||
123 | void Bu::ServerSocket::initServer( struct sockaddr_in &name, int nPoolSize ) | ||
124 | { | ||
92 | if( bu_bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) | 125 | if( bu_bind( nServer, (struct sockaddr *) &name, sizeof(name) ) < 0 ) |
93 | { | 126 | { |
94 | throw Bu::ServerSocketException("Couldn't bind to the listen socket."); | 127 | throw Bu::ServerSocketException("Couldn't bind to the listen socket."); |