diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-02-27 06:41:03 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-02-27 06:41:03 +0000 |
commit | 8a51dd0db9176a56c482ca5cecb5051d2b6848ba (patch) | |
tree | 523e74a7dc8bc5538953b71dabf3ff9fd8a168b4 /src/connectionmanager.cpp | |
parent | c208b397b798910df4ad129fb13d562b4450034e (diff) | |
download | libbu++-8a51dd0db9176a56c482ca5cecb5051d2b6848ba.tar.gz libbu++-8a51dd0db9176a56c482ca5cecb5051d2b6848ba.tar.bz2 libbu++-8a51dd0db9176a56c482ca5cecb5051d2b6848ba.tar.xz libbu++-8a51dd0db9176a56c482ca5cecb5051d2b6848ba.zip |
This may require slightly more testing, but basically I made ConnectionManager
more general, you can now listen to all local addresses (the old way), or
individual addressses.
Diffstat (limited to 'src/connectionmanager.cpp')
-rw-r--r-- | src/connectionmanager.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index ea794a8..ea60b2b 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp | |||
@@ -46,14 +46,6 @@ bool ConnectionManager::startServer( int nPort ) | |||
46 | /* Create the socket and set it up to accept connections. */ | 46 | /* Create the socket and set it up to accept connections. */ |
47 | struct sockaddr_in name; | 47 | struct sockaddr_in name; |
48 | 48 | ||
49 | /* Create the socket. */ | ||
50 | int nMasterSocket = socket (PF_INET, SOCK_STREAM, 0); | ||
51 | if (nMasterSocket < 0) | ||
52 | { | ||
53 | xLog.LineLog( MultiLog::LError, "Couldn't create a listen socket."); | ||
54 | return false; | ||
55 | } | ||
56 | |||
57 | /* Give the socket a name. */ | 49 | /* Give the socket a name. */ |
58 | name.sin_family = AF_INET; | 50 | name.sin_family = AF_INET; |
59 | name.sin_port = htons( nPort ); | 51 | name.sin_port = htons( nPort ); |
@@ -62,6 +54,33 @@ bool ConnectionManager::startServer( int nPort ) | |||
62 | // a good thing to make configurable later on | 54 | // a good thing to make configurable later on |
63 | name.sin_addr.s_addr = htonl( INADDR_ANY ); | 55 | name.sin_addr.s_addr = htonl( INADDR_ANY ); |
64 | 56 | ||
57 | return startServer( name ); | ||
58 | } | ||
59 | |||
60 | bool ConnectionManager::startServer( const char *sAddr, int nPort ) | ||
61 | { | ||
62 | /* Create the socket and set it up to accept connections. */ | ||
63 | struct sockaddr_in name; | ||
64 | |||
65 | /* Give the socket a name. */ | ||
66 | name.sin_family = AF_INET; | ||
67 | name.sin_port = htons( nPort ); | ||
68 | |||
69 | inet_aton( sAddr, &name.sin_addr ); | ||
70 | |||
71 | return startServer( name ); | ||
72 | } | ||
73 | |||
74 | bool ConnectionManager::startServer( struct sockaddr_in &name ) | ||
75 | { | ||
76 | /* Create the socket. */ | ||
77 | int nMasterSocket = socket (PF_INET, SOCK_STREAM, 0); | ||
78 | if (nMasterSocket < 0) | ||
79 | { | ||
80 | xLog.LineLog( MultiLog::LError, "Couldn't create a listen socket."); | ||
81 | return false; | ||
82 | } | ||
83 | |||
65 | int opt = 1; | 84 | int opt = 1; |
66 | setsockopt( | 85 | setsockopt( |
67 | nMasterSocket, | 86 | nMasterSocket, |
@@ -86,7 +105,7 @@ bool ConnectionManager::startServer( int nPort ) | |||
86 | /* Initialize the set of active sockets. */ | 105 | /* Initialize the set of active sockets. */ |
87 | FD_SET (nMasterSocket, &fdActive); | 106 | FD_SET (nMasterSocket, &fdActive); |
88 | 107 | ||
89 | sMasterSocket[nMasterSocket] = nPort; | 108 | sMasterSocket[nMasterSocket] = name.sin_port; |
90 | 109 | ||
91 | return true; | 110 | return true; |
92 | } | 111 | } |