bool TransportInfo::initWithSocket()

in wangle/acceptor/TransportInfo.cpp [29:78]


bool TransportInfo::initWithSocket(const folly::AsyncSocket* sock) {
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
  if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) {
    tcpinfoErrno = errno;
    return false;
  }
#ifdef __APPLE__
  rtt = microseconds(tcpinfo.tcpi_srtt * 1000);
  rtt_var = tcpinfo.tcpi_rttvar * 1000;
  rto = tcpinfo.tcpi_rto * 1000;
  rtx_tm = -1;
  mss = tcpinfo.tcpi_maxseg;
  cwndBytes = tcpinfo.tcpi_snd_cwnd;
  if (mss > 0) {
    cwnd = (cwndBytes + mss - 1) / mss;
  }
#else
  rtt = microseconds(tcpinfo.tcpi_rtt);
  rtt_var = tcpinfo.tcpi_rttvar;
  rto = tcpinfo.tcpi_rto;
#ifdef __FreeBSD__
  rtx_tm = tcpinfo.__tcpi_retransmits;
#else
  rtx_tm = tcpinfo.tcpi_retransmits;
#endif
  mss = tcpinfo.tcpi_snd_mss;
  cwnd = tcpinfo.tcpi_snd_cwnd;
  cwndBytes = cwnd * mss;
#endif // __APPLE__
  ssthresh = tcpinfo.tcpi_snd_ssthresh;
#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 17
  rtx = tcpinfo.tcpi_total_retrans;
#else
  rtx = -1;
#endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 17
  validTcpinfo = true;
#else
  (sock); // unused
  tcpinfoErrno = EINVAL;
  rtt = microseconds(-1);
  rtt_var = -1;
  rtx = -1;
  rtx_tm = -1;
  rto = -1;
  cwnd = -1;
  mss = -1;
  ssthresh = -1;
#endif
  return true;
}