コード例 #1
0
ファイル: remotehost.cpp プロジェクト: hellok/PetaBricks
void petabricks::RemoteHost::accept(jalib::JServerSocket& s) {
  _control.close();
  _control = s.accept();
  JASSERT(_control.isValid());
  for(int i=0; i<REMOTEHOST_DATACHANS; ++i) {
    _data[i].close();
    _data[i] = s.accept();
    JASSERT(_data[i].isValid());
  }
  _lastchan = 1;
  handshake();
}
コード例 #2
0
ファイル: ib2tcp.cpp プロジェクト: FrancoisAi/dmtcp
void IB2TCP::createTCPConnections()
{
  if (!isVirtIB) {
    return;
  }

  size_t numRemaining = 0;
  map<uint32_t, IB_QP*>::iterator it;
  //First do a connect
  for (it = queuePairs.begin(); it != queuePairs.end(); it++) {
    IB_QP *ibqp = it->second;
    IB_QId remoteId = ibqp->getRemoteId();
    if (ibqp->localId > ibqp->remoteId) {
      struct sockaddr_in *addr_in = (struct sockaddr_in*) &ibqp->remoteAddr;
      JNOTE("connecting to remote node")
        (inet_ntoa(addr_in->sin_addr)) (ntohs(addr_in->sin_port));
      jalib::JSocket sock = jalib::JClientSocket((sockaddr*) &ibqp->remoteAddr,
                                                 ibqp->remoteAddrLen);
      sock.changeFd(fdCounter++);
      int fd = sock.sockfd();
      JASSERT(fd != -1);
      JASSERT(Util::writeAll(fd, &remoteId, sizeof(remoteId)) == sizeof(remoteId))
        (JASSERT_ERRNO);
      fdToQP[fd] = ibqp;
      qpToFd[ibqp] = fd;
      socks.push_back(fd);
    } else {
      numRemaining++;
    }
  }

  // Now accept all connections.
  for (size_t i = 0; i < numRemaining; i++) {
    IB_QId localId;
    jalib::JSocket sock = listenSock.accept();
    JASSERT(sock.isValid());
    sock.changeFd(fdCounter++);
    JASSERT(Util::readAll(sock.sockfd(), &localId, sizeof(localId)) == sizeof(localId))
      (JASSERT_ERRNO);

    JASSERT(queuePairs.find(localId.qp_num) != queuePairs.end())
      (localId.qp_num) (localId.lid);

    IB_QP *ibqp = queuePairs[localId.qp_num];
    JASSERT(ibqp->localId < ibqp->remoteId)
      (ibqp->localId.qp_num) (ibqp->remoteId.qp_num);

    fdToQP[sock.sockfd()] = ibqp;
    qpToFd[ibqp] = sock.sockfd();
    socks.push_back(sock.sockfd());
  }
}