aboutsummaryrefslogtreecommitdiff
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
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?
-rw-r--r--src/formatter.cpp2
-rw-r--r--src/formatter.h2
-rw-r--r--src/serversocket.cpp37
-rw-r--r--src/serversocket.h3
4 files changed, 40 insertions, 4 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp
index 6eb3b86..2fadd96 100644
--- a/src/formatter.cpp
+++ b/src/formatter.cpp
@@ -16,7 +16,7 @@ void Bu::Formatter::write( const Bu::FString &sStr )
16 rOut.write( sStr ); 16 rOut.write( sStr );
17} 17}
18 18
19void Bu::Formatter::write( const char *sStr, int iLen ) 19void Bu::Formatter::write( const void *sStr, int iLen )
20{ 20{
21 rOut.write( sStr, iLen ); 21 rOut.write( sStr, iLen );
22} 22}
diff --git a/src/formatter.h b/src/formatter.h
index 693c3ed..5dd7622 100644
--- a/src/formatter.h
+++ b/src/formatter.h
@@ -83,7 +83,7 @@ namespace Bu
83 } Fmt; 83 } Fmt;
84 84
85 void write( const Bu::FString &sStr ); 85 void write( const Bu::FString &sStr );
86 void write( const char *sStr, int iLen ); 86 void write( const void *sStr, int iLen );
87 void writeAligned( const Bu::FString &sStr ); 87 void writeAligned( const Bu::FString &sStr );
88 void writeAligned( const char *sStr, int iLen ); 88 void writeAligned( const char *sStr, int iLen );
89 89
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.");
diff --git a/src/serversocket.h b/src/serversocket.h
index 0860972..88d09ec 100644
--- a/src/serversocket.h
+++ b/src/serversocket.h
@@ -39,6 +39,8 @@ namespace Bu
39 public: 39 public:
40 ServerSocket( int nPort, int nPoolSize=40 ); 40 ServerSocket( int nPort, int nPoolSize=40 );
41 ServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 ); 41 ServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 );
42 ServerSocket( int nSocket, bool bInit, int nPoolSize=40 );
43 ServerSocket( const ServerSocket &rSrc );
42 virtual ~ServerSocket(); 44 virtual ~ServerSocket();
43 45
44 int accept( int nTimeoutSec=0, int nTimeoutUSec=0 ); 46 int accept( int nTimeoutSec=0, int nTimeoutUSec=0 );
@@ -47,6 +49,7 @@ namespace Bu
47 49
48 private: 50 private:
49 void startServer( struct sockaddr_in &name, int nPoolSize ); 51 void startServer( struct sockaddr_in &name, int nPoolSize );
52 void initServer( struct sockaddr_in &name, int nPoolSize );
50 53
51 fd_set fdActive; 54 fd_set fdActive;
52#ifdef WIN32 55#ifdef WIN32