summaryrefslogtreecommitdiff
path: root/src/connectionmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/connectionmanager.cpp')
-rw-r--r--src/connectionmanager.cpp37
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
60bool 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
74bool 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}