FACT++  1.0
void ConnectionUSB::CloseImp ( int64_t  delay = 0)
protected

Definition at line 71 of file ConnectionUSB.cc.

References Error(), HandleReconnectTimeout(), and Agilent::State::kDisconnected.

Referenced by Out(), and PostClose().

72 {
73  if (IsConnected())
74  Info("Closing connection to "+URL()+".");
75 
76  // Close possible open connections
77  bs::error_code ec;
78  cancel(ec);
79  if (ec && ec!=ba::error::basic_errors::bad_descriptor)
80  {
81  ostringstream msg;
82  msg << "Cancel async requests on " << URL() << ": " << ec.message() << " (" << ec << ")";
83  Error(msg);
84  }
85 
86  if (IsConnected())
87  {
88  close(ec);
89  if (ec)
90  {
91  ostringstream msg;
92  msg << "Closing " << URL() << ": " << ec.message() << " (" << ec << ")";
93  Error(msg);
94  }
95  else
96  Info("Closed connection to "+URL()+" succesfully.");
97  }
98 
99  // Stop deadline counters
100  fInTimeout.cancel();
101  fOutTimeout.cancel();
102  fConnectTimeout.cancel();
103 
104  // Reset the connection status
105  fQueueSize = 0;
107 
108 #ifdef DEBUG
109  ofstream fout1("transmitted.txt", ios::app);
110  ofstream fout2("received.txt", ios::app);
111  ofstream fout3("send.txt", ios::app);
112  fout1 << Time() << ": ---" << endl;
113  fout2 << Time() << ": ---" << endl;
114  fout3 << Time() << ": ---" << endl;
115 #endif
116 
117  if (delay<0 || IsConnecting())
118  return;
119 
120  // We need some timeout before reconnecting!
121  // And we have to check if we are alreayd trying to connect
122  // We should wait until all operations in progress were canceled
123  fConnectTimeout.expires_from_now(boost::posix_time::seconds(delay));
124  fConnectTimeout.async_wait(boost::bind(&ConnectionUSB::HandleReconnectTimeout, this, dummy::error));
125 }
boost::asio::deadline_timer fOutTimeout
Definition: ConnectionUSB.h:38
std::string URL() const
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
size_t fQueueSize
Definition: ConnectionUSB.h:41
bool IsConnecting() const
int Error(const std::string &str)
Definition: MessageImp.h:49
ConnectionStatus_t fConnectionStatus
Definition: ConnectionUSB.h:43
bool IsConnected() const
void HandleReconnectTimeout(const boost::system::error_code &error)
int Info(const std::string &str)
Definition: MessageImp.h:47
boost::asio::deadline_timer fInTimeout
Definition: ConnectionUSB.h:35
boost::asio::deadline_timer fConnectTimeout
Definition: ConnectionUSB.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function: