caffe-distri/src/main/cpp/util/socket.cpp
// Connect called by client with inbuilt support for retries
Connect called by client with inbuilt support for retries
Connect called by client with inbuilt support for retries
bool SocketChannel::Connect(string peer) {
  bool retry = true;
  int attempts = 0;
  int client_fd = 0;
  vector<string> name_port;
  boost::split(name_port, peer, boost::is_any_of(":"));
  int backoff = 1;
  while (retry && (attempts < 5)) {
    retry = false;
    if (client_fd == 0) {
      string peername = name_port.at(0).c_str();;
      string portnumber;
      if (name_port.size() > 1) 
        portnumber = name_port.at(1).c_str();
      LOG(INFO) << "Trying to connect with ...["
                << peername <<":"
                << portnumber << "]";
      client_fd = connect_to_peer(peername,
                                  portnumber);
      if (!client_fd) {
        retry = true;
      } else {
        this->client_fd = client_fd;
        this->peer_name = name_port.at(0);
        this->port_no = atoi(name_port.at(1).c_str());
      }
    }
    attempts++;
    usleep(backoff*1000000);
    backoff = backoff * 2;
  }
  if (retry)
    return false;
  return true;
}
bool SocketChannel :: Connect ( string peer ) { bool retry = true ; int attempts = 0 ; int client_fd = 0 ; vector < string > name_port ; boost :: split ( name_port , peer , boost :: is_any_of ( " " ) ) ; int backoff = 1 ; while ( retry && ( attempts < 5 ) ) { retry = false ; if ( client_fd == 0 ) { string peername = name_port . at ( 0 ) . c_str ( ) ; ; string portnumber ; if ( name_port . size ( ) > 1 ) portnumber = name_port . at ( 1 ) . c_str ( ) ; LOG ( INFO ) << " " << peername << " " << portnumber << " " ; client_fd = connect_to_peer ( peername , portnumber ) ; if ( ! client_fd ) { retry = true ; } else { this -> client_fd = client_fd ; this -> peer_name = name_port . at ( 0 ) ; this -> port_no = atoi ( name_port . at ( 1 ) . c_str ( ) ) ; } } attempts ++ ; usleep ( backoff * 1000000 ) ; backoff = backoff * 2 ; } if ( retry ) return false ; return true ; }
Connect called by client with inbuilt support for retries
Connect called by client with inbuilt support for retries
// On success update the local peer's // SocketChannel with the connection details // Retry after 10 secs