FACT++  1.0
void Connection::StartConnect ( )
virtual

Definition at line 352 of file Connection.cc.

References Error(), HandleConnectionTimer(), BIAS::State::kConnecting, SetEndpoint(), and valid().

Referenced by ConnectionFailed(), StateMachineFAD< T >::EnableConnection(), ConnectionGCN::StartConnect(), and StateMachineFAD< T >::StateMachineFAD().

353 {
355 
356  if (fEndpoint!=tcp::endpoint())
357  {
358  ostringstream msg;
359  msg << "Trying to connect to " << fEndpoint << "...";
360  if (fMsgConnect!=msg.str())
361  {
362  fMsgConnect = msg.str();
363  Info(msg);
364  }
365 
366  AsyncConnect();
367  return;
368  }
369 
370  const bool valid = !fAddress.empty() || !fPort.empty();
371 
372  boost::system::error_code ec;
373 
374  ostringstream msg;
375  if (!valid)
376  msg << "No target address... connection attempt postponed.";
377  else
378  {
379  tcp::resolver resolver(get_io_service());
380 
381  tcp::resolver::query query(fAddress, fPort);
382  tcp::resolver::iterator iterator = resolver.resolve(query, ec);
383 
384  msg << "Trying to connect to " << URL() << "...";
385 
386  // Start connection attempts (will also reset deadline counter)
387  if (!ec)
388  AsyncConnect(iterator);
389  else
390  msg << " " << ec.message() << " (" << ec << ")";
391  }
392 
393  // Only output message if it has changed
394  if (fMsgConnect!=msg.str())
395  {
396  fMsgConnect = msg.str();
397  if (ec)
398  Error(msg);
399  if (!ec && fVerbose)
400  Info(msg);
401  }
402 
403  if (!valid || ec)
405 }
boost::asio::deadline_timer fConnectionTimer
Definition: Connection.h:40
void AsyncWait(boost::asio::deadline_timer &timer, int millisec, void(Connection::*handler)(const boost::system::error_code &))
Definition: Connection.h:75
void HandleConnectionTimer(const boost::system::error_code &error)
Definition: Connection.cc:230
void AsyncConnect()
Definition: Connection.cc:76
ConnectionStatus_t fConnectionStatus
Definition: Connection.h:44
boost::asio::ip::tcp::endpoint fEndpoint
Definition: Connection.h:23
std::string URL() const
Definition: Connection.h:151
std::string fPort
Definition: Connection.h:21
int Error(const std::string &str)
Definition: MessageImp.h:49
bool valid() const
Definition: HeadersFTM.h:271
std::string fAddress
Definition: Connection.h:20
std::string fMsgConnect
Definition: Connection.h:47
int Info(const std::string &str)
Definition: MessageImp.h:47
bool fVerbose
Definition: Connection.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function: