Changeset 11260 for trunk/FACT++/src/Connection.cc
- Timestamp:
- 07/06/11 13:33:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Connection.cc
r11198 r11260 71 71 // AsyncConnect + Deadline 72 72 async_connect(endpoint, 73 boost::bind(&Connection::ConnectIter Imp,73 boost::bind(&Connection::ConnectIter, 74 74 this, iterator, ba::placeholders::error)); 75 75 … … 82 82 // AsyncConnect + Deadline 83 83 async_connect(fEndpoint, 84 boost::bind(&Connection::ConnectAddr Imp,84 boost::bind(&Connection::ConnectAddr, 85 85 this, fEndpoint, ba::placeholders::error)); 86 86 … … 290 290 } 291 291 292 void Connection::ConnectAddrImp(const tcp::endpoint &endpoint, const bs::error_code& error)292 bool Connection::ConnectImp(const tcp::endpoint &endpoint, const bs::error_code& error) 293 293 { 294 294 const string host = endpoint.port()==0 ? "" : … … 311 311 312 312 ConnectionEstablished(); 313 return ;313 return true; 314 314 } 315 315 … … 334 334 335 335 if (error==ba::error::basic_errors::operation_aborted) 336 return ;336 return true; 337 337 338 338 fConnectionStatus = kConnecting; 339 340 return false; 339 341 /* 340 342 // Go on with the next … … 352 354 353 355 // FIXME: Should we move this before AsyncConnect() ? 354 AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer); 355 } 356 357 void Connection::ConnectIterImp(tcp::resolver::iterator iterator, const bs::error_code& error) 358 { 359 ConnectAddrImp(*iterator, error); 360 /* 361 tcp::endpoint endpoint = *iterator; 362 363 const string host = endpoint.port()==0 ? "" : 364 endpoint.address().to_string()+":"+lexical_cast<string>(endpoint.port()); 365 366 // Connection established 367 if (!error) 368 { 369 set_option(socket_base::keep_alive(true)); 370 371 const int optval = 10; 372 // First keep alive after 10s 373 setsockopt(native(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval)); 374 // New keep alive after 10s 375 setsockopt(native(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval)); 376 377 Info("Connection established to "+host+"..."); 378 379 fConnectionStatus = kConnected; 380 381 ConnectionEstablished(); 382 return; 383 } 384 385 // If returning from run will lead to deletion of this 386 // instance, close() is not needed (maybe implicitly called). 387 // If run is called again, close() is needed here. Otherwise: 388 // Software caused connection abort when we try to resolve 389 // the endpoint again. 390 CloseImp(false); 391 392 ostringstream msg; 393 if (!host.empty()) 394 msg << "Connecting to " << host << ": " << error.message() << " (" << error << ")"; 395 396 if (fErrConnect!=msg.str()) 397 { 398 if (error!=ba::error::basic_errors::connection_refused) 399 fMsgConnect = ""; 400 fErrConnect = msg.str(); 401 Warn(fErrConnect); 402 } 403 404 if (error==ba::error::basic_errors::operation_aborted) 405 return; 406 407 fConnectionStatus = kConnecting; 408 */ 356 // AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer); 357 } 358 359 void Connection::ConnectIter(tcp::resolver::iterator iterator, const bs::error_code& error) 360 { 361 if (ConnectImp(*iterator, error)) 362 return; 363 409 364 // Go on with the next 410 365 if (++iterator != tcp::resolver::iterator()) … … 413 368 return; 414 369 } 415 /* 370 416 371 // No more entries to try, if we would not put anything else 417 372 // into the queue anymore it would now return (run() would return) 418 419 // Since we don't want to block the main loop, we wait using an420 // asnychronous timer421 422 // FIXME: Should we move this before AsyncConnect() ?423 373 AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer); 424 */ 374 } 375 376 void Connection::ConnectAddr(const tcp::endpoint &endpoint, const bs::error_code& error) 377 { 378 if (ConnectImp(endpoint, error)) 379 return; 380 381 AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer); 425 382 } 426 383
Note:
See TracChangeset
for help on using the changeset viewer.