Beispiel #1
0
Variant sockopen_impl(const HostURL &hosturl, VRefParam errnum,
                      VRefParam errstr, double timeout, bool persistent) {
  errnum = 0;
  errstr = empty_string();
  std::string key;
  if (persistent) {
    key = hosturl.getHostURL() + ":" +
          folly::to<std::string>(hosturl.getPort());
    auto sockItr = s_sockets.find(key);
    if (sockItr != s_sockets.end()) {
      auto sock = makeSmartPtr<Socket>(sockItr->second);

      if (sock->getError() == 0 && sock->checkLiveness()) {
        return Variant(sock);
      }

      // socket had an error earlier, we need to close it, remove it from
      // persistent storage, and create a new one (in that order)
      sock->close();
      s_sockets.erase(sockItr);
    }
  }

  if (timeout < 0) {
    timeout = ThreadInfo::s_threadInfo.getNoCheck()->
      m_reqInjectionData.getSocketDefaultTimeout();
  }

  auto socket = new_socket_connect(hosturl, timeout, errnum, errstr);
  if (!socket.isResource()) {
    return false;
  }

  if (persistent) {
    assert(!key.empty());
    s_sockets[key] = cast<Socket>(socket)->getData();
    assert(s_sockets[key]);
  }

  return socket;
}
bool rice::pastry::transport::NodeHandleAdapter::checkLiveness(::java::lang::Object* i, ::java::util::Map* options)
{ 
    return checkLiveness(dynamic_cast< ::rice::pastry::NodeHandle* >(i), options);
}