Changeset 11260 for trunk


Ignore:
Timestamp:
07/06/11 13:33:55 (13 years ago)
Author:
tbretz
Message:
Fixed a problem introduced with the splitting of Connect which caused the connection to e.g. the FTM getting established twice.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Connection.cc

    r11198 r11260  
    7171    // AsyncConnect + Deadline
    7272     async_connect(endpoint,
    73                   boost::bind(&Connection::ConnectIterImp,
     73                  boost::bind(&Connection::ConnectIter,
    7474                              this, iterator, ba::placeholders::error));
    7575
     
    8282    // AsyncConnect + Deadline
    8383     async_connect(fEndpoint,
    84                   boost::bind(&Connection::ConnectAddrImp,
     84                  boost::bind(&Connection::ConnectAddr,
    8585                              this, fEndpoint, ba::placeholders::error));
    8686
     
    290290}
    291291
    292 void Connection::ConnectAddrImp(const tcp::endpoint &endpoint, const bs::error_code& error)
     292bool Connection::ConnectImp(const tcp::endpoint &endpoint, const bs::error_code& error)
    293293{
    294294    const string host = endpoint.port()==0 ? "" :
     
    311311
    312312        ConnectionEstablished();
    313         return;
     313        return true;
    314314    }
    315315
     
    334334
    335335    if (error==ba::error::basic_errors::operation_aborted)
    336         return;
     336        return true;
    337337
    338338    fConnectionStatus = kConnecting;
     339
     340    return false;
    339341/*
    340342    // Go on with the next
     
    352354
    353355    // 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
     359void Connection::ConnectIter(tcp::resolver::iterator iterator, const bs::error_code& error)
     360{
     361    if (ConnectImp(*iterator, error))
     362        return;
     363
    409364    // Go on with the next
    410365    if (++iterator != tcp::resolver::iterator())
     
    413368        return;
    414369    }
    415 /*
     370
    416371    // No more entries to try, if we would not put anything else
    417372    // 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 an
    420     // asnychronous timer
    421 
    422     // FIXME: Should we move this before AsyncConnect() ?
    423373    AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer);
    424 */
     374}
     375
     376void 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);
    425382}
    426383
  • trunk/FACT++/src/Connection.h

    r11190 r11260  
    8282    void CloseImp(bool restart=true);
    8383
    84     void ConnectAddrImp(const boost::asio::ip::tcp::endpoint &endpoint,
    85                         const boost::system::error_code& error);
    86     void ConnectIterImp(boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
    87                         const boost::system::error_code& error);
     84    bool ConnectImp(const boost::asio::ip::tcp::endpoint &endpoint,
     85                    const boost::system::error_code& error);
     86    void ConnectIter(boost::asio::ip::tcp::resolver::iterator endpoint_iterator,
     87                     const boost::system::error_code& error);
     88    void ConnectAddr(const boost::asio::ip::tcp::endpoint &endpoint,
     89                     const boost::system::error_code& error);
    8890
    8991    void HandleConnectionTimer(const boost::system::error_code &error);
Note: See TracChangeset for help on using the changeset viewer.