aboutsummaryrefslogtreecommitdiff
path: root/src/serversocket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-03-26 17:00:35 +0000
committerMike Buland <eichlan@xagasoft.com>2009-03-26 17:00:35 +0000
commitb4ab27db8a97f0a56a61bd56480cfbe08a1f3399 (patch)
tree83c984b68f10099deac2e9536227a96cc416e39b /src/serversocket.cpp
parent94fff060ee9ec6c2a8da75568702d8e944963d46 (diff)
downloadlibbu++-b4ab27db8a97f0a56a61bd56480cfbe08a1f3399.tar.gz
libbu++-b4ab27db8a97f0a56a61bd56480cfbe08a1f3399.tar.bz2
libbu++-b4ab27db8a97f0a56a61bd56480cfbe08a1f3399.tar.xz
libbu++-b4ab27db8a97f0a56a61bd56480cfbe08a1f3399.zip
Added some more constructors to the ServerSocket, and also switched the write
function in Bu::Formatter to take a void *, what was I thinking?
Diffstat (limited to '')
-rw-r--r--src/serversocket.cpp37
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
68Bu::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
87Bu::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
68Bu::ServerSocket::~ServerSocket() 95Bu::ServerSocket::~ServerSocket()
69{ 96{
70 ::close( nServer ); 97 if( nServer > -1 )
98 ::close( nServer );
71} 99}
72 100
73void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) 101void 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
123void 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.");