FACT++  1.0
bool Connection::ConnectImp ( const boost::asio::ip::tcp::endpoint &  endpoint,
const boost::system::error_code &  error 
)
private

Definition at line 257 of file Connection.cc.

References Agilent::State::kConnected, and BIAS::State::kConnecting.

Referenced by AsyncWait().

258 {
259  const string host = endpoint.port()==0 ? "" :
260  endpoint.address().to_string()+':'+to_string((long long unsigned int)endpoint.port());
261 
262  // Connection established
263  if (!error)
264  {
265  set_option(socket_base::keep_alive(true));
266 
267  const int optval = 30;
268  // First keep alive after 30s
269  setsockopt(native(), SOL_TCP, TCP_KEEPIDLE, &optval, sizeof(optval));
270  // New keep alive after 30s
271  setsockopt(native(), SOL_TCP, TCP_KEEPINTVL, &optval, sizeof(optval));
272 
273  if (fVerbose)
274  Info("Connection established to "+host+"...");
275 
276  fQueueSize = 0;
278 
280  return true;
281  }
282 
283  // If returning from run will lead to deletion of this
284  // instance, close() is not needed (maybe implicitly called).
285  // If run is called again, close() is needed here. Otherwise:
286  // Software caused connection abort when we try to resolve
287  // the endpoint again.
288  CloseImp(false);
289 
290  ostringstream msg;
291  if (!host.empty())
292  msg << "Connecting to " << host << ": " << error.message() << " (" << error << ")";
293 
294  if (fErrConnect!=msg.str())
295  {
296  if (error!=ba::error::basic_errors::connection_refused)
297  fMsgConnect = "";
298  fErrConnect = msg.str();
299  Warn(fErrConnect);
300  }
301 
302  if (error==ba::error::basic_errors::operation_aborted)
303  return true;
304 
306 
307  return false;
308 /*
309  // Go on with the next
310  if (++iterator != tcp::resolver::iterator())
311  {
312  AsyncConnect(iterator);
313  return;
314  }
315 */
316  // No more entries to try, if we would not put anything else
317  // into the queue anymore it would now return (run() would return)
318 
319  // Since we don't want to block the main loop, we wait using an
320  // asnychronous timer
321 
322  // FIXME: Should we move this before AsyncConnect() ?
323 // AsyncWait(fConnectionTimer, 250, &Connection::HandleConnectionTimer);
324 }
void CloseImp(bool restart=true)
Definition: Connection.cc:89
ConnectionStatus_t fConnectionStatus
Definition: Connection.h:44
std::string fErrConnect
Definition: Connection.h:46
int Warn(const std::string &str)
Definition: MessageImp.h:48
std::string fMsgConnect
Definition: Connection.h:47
int Info(const std::string &str)
Definition: MessageImp.h:47
bool fVerbose
Definition: Connection.h:25
virtual void ConnectionEstablished()
Definition: Connection.h:101
size_t fQueueSize
Definition: Connection.h:42

+ Here is the caller graph for this function: