summaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 9d8b02c..efef144 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -165,7 +165,7 @@ bool Connection::open( int nNewSocket )
165 return true; 165 return true;
166} 166}
167 167
168bool Connection::open( const char *sAddr, int nPort ) 168bool Connection::open( const char *sAddr, int nPort, int nSec )
169{ 169{
170 struct sockaddr_in xServerName; 170 struct sockaddr_in xServerName;
171 bActive = false; 171 bActive = false;
@@ -204,13 +204,42 @@ bool Connection::open( const char *sAddr, int nPort )
204 } 204 }
205 205
206 //printf("Making actual connection..."); 206 //printf("Making actual connection...");
207 fflush( stdout ); 207 //fflush( stdout );
208 int ret = connect( 208 connect(
209 nSocket, 209 nSocket,
210 (struct sockaddr *)&xServerName, 210 (struct sockaddr *)&xServerName,
211 sizeof(xServerName) 211 sizeof(xServerName)
212 ); 212 );
213 //printf("Connected.\n"); 213 //printf("Connected.\n");
214
215 bActive = true;
216 bDisconnectMe = false;
217
218 if( nSec > 0 )
219 {
220 fd_set rfds, wfds, efds;
221 int retval;
222
223 FD_ZERO(&rfds);
224 FD_SET(nSocket, &rfds);
225 FD_ZERO(&wfds);
226 FD_SET(nSocket, &wfds);
227 FD_ZERO(&efds);
228 FD_SET(nSocket, &efds);
229
230 struct timeval tv;
231 tv.tv_sec = nSec;
232 tv.tv_usec = 0;
233
234 retval = select( nSocket+1, &rfds, &wfds, &efds, &tv );
235
236 if( retval == 0 )
237 {
238 close();
239 throw ExceptionBase("Connection timeout.\n");
240 }
241
242 }
214 243
215 /* 244 /*
216 if( ret < 0 ) 245 if( ret < 0 )
@@ -218,9 +247,6 @@ bool Connection::open( const char *sAddr, int nPort )
218 return false; 247 return false;
219 }*/ 248 }*/
220 249
221 bActive = true;
222 bDisconnectMe = false;
223
224 return true; 250 return true;
225} 251}
226 252