removing non-existing file from the build
[folly.git] / folly / wangle / acceptor / TransportInfo.cpp
1 /*
2  *  Copyright (c) 2015, Facebook, Inc.
3  *  All rights reserved.
4  *
5  *  This source code is licensed under the BSD-style license found in the
6  *  LICENSE file in the root directory of this source tree. An additional grant
7  *  of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #include <folly/wangle/acceptor/TransportInfo.h>
11
12 #include <sys/socket.h>
13 #include <sys/types.h>
14 #include <folly/io/async/AsyncSocket.h>
15
16 using std::chrono::microseconds;
17 using std::map;
18 using std::string;
19
20 namespace folly {
21
22 bool TransportInfo::initWithSocket(const AsyncSocket* sock) {
23 #if defined(__linux__) || defined(__FreeBSD__)
24   if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) {
25     tcpinfoErrno = errno;
26     return false;
27   }
28   rtt = microseconds(tcpinfo.tcpi_rtt);
29   validTcpinfo = true;
30 #else
31   tcpinfoErrno = EINVAL;
32   rtt = microseconds(-1);
33 #endif
34   return true;
35 }
36
37 int64_t TransportInfo::readRTT(const AsyncSocket* sock) {
38 #if defined(__linux__) || defined(__FreeBSD__)
39   struct tcp_info tcpinfo;
40   if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) {
41     return -1;
42   }
43   return tcpinfo.tcpi_rtt;
44 #else
45   return -1;
46 #endif
47 }
48
49 #if defined(__linux__) || defined(__FreeBSD__)
50 bool TransportInfo::readTcpInfo(struct tcp_info* tcpinfo,
51                                 const AsyncSocket* sock) {
52   socklen_t len = sizeof(struct tcp_info);
53   if (!sock) {
54     return false;
55   }
56   if (getsockopt(sock->getFd(), IPPROTO_TCP,
57                  TCP_INFO, (void*) tcpinfo, &len) < 0) {
58     VLOG(4) << "Error calling getsockopt(): " << strerror(errno);
59     return false;
60   }
61   return true;
62 }
63 #endif
64
65 } // folly