OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Some socket related helper methods for quic. | 5 // Some socket related helper methods for quic. |
6 | 6 |
7 #ifndef NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ | 7 #ifndef NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ |
8 #define NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ | 8 #define NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ |
9 | 9 |
10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Deprecated; serves only as padding. | 31 // Deprecated; serves only as padding. |
32 struct timespec hwtimetrans; | 32 struct timespec hwtimetrans; |
33 // The raw hardware timestamp. | 33 // The raw hardware timestamp. |
34 struct timespec hwtimeraw; | 34 struct timespec hwtimeraw; |
35 }; | 35 }; |
36 | 36 |
37 class QuicSocketUtils { | 37 class QuicSocketUtils { |
38 public: | 38 public: |
39 // The first integer is for overflow. The in6_pktinfo is the larger of the | 39 // The first integer is for overflow. The in6_pktinfo is the larger of the |
40 // address structures present. LinuxTimestamping is present for socket | 40 // address structures present. LinuxTimestamping is present for socket |
41 // timestamping. | 41 // timestamping. The subsequent int is for ttl. |
42 // The final int is a sentinel so the msg_controllen feedback | 42 // The final int is a sentinel so the msg_controllen feedback |
43 // can be used to detect larger control messages than there is space for. | 43 // can be used to detect larger control messages than there is space for. |
44 static const int kSpaceForCmsg = | 44 static const int kSpaceForCmsg = |
45 CMSG_SPACE(CMSG_LEN(sizeof(int)) + CMSG_LEN(sizeof(in6_pktinfo)) + | 45 CMSG_SPACE(CMSG_LEN(sizeof(int)) + CMSG_LEN(sizeof(in6_pktinfo)) + |
46 CMSG_LEN(sizeof(LinuxTimestamping)) + | 46 CMSG_LEN(sizeof(LinuxTimestamping)) + |
| 47 CMSG_LEN(sizeof(int)) + |
47 CMSG_LEN(sizeof(int))); | 48 CMSG_LEN(sizeof(int))); |
48 | 49 |
49 // Fills in |address| if |hdr| contains IP_PKTINFO or IPV6_PKTINFO. Fills in | 50 // Fills in |address| if |hdr| contains IP_PKTINFO or IPV6_PKTINFO. Fills in |
50 // |timestamp| if |hdr| contains |SO_TIMESTAMPING|. |address| and |timestamp| | 51 // |timestamp| if |hdr| contains |SO_TIMESTAMPING|. |address| and |timestamp| |
51 // must not be null. | 52 // must not be null. |
52 // TODO(rjshade): Delete the |timestamp| argument when removing | |
53 // FLAGS_quic_socket_timestamps_walltime | |
54 static void GetAddressAndTimestampFromMsghdr(struct msghdr* hdr, | 53 static void GetAddressAndTimestampFromMsghdr(struct msghdr* hdr, |
55 IPAddress* address, | 54 IPAddress* address, |
56 QuicTime* timestamp, | 55 QuicWallTime* walltimestamp); |
57 QuicWallTime* walltimestamp, | |
58 bool latched_walltimestamps); | |
59 | 56 |
60 // If the msghdr contains an SO_RXQ_OVFL entry, this will set dropped_packets | 57 // If the msghdr contains an SO_RXQ_OVFL entry, this will set dropped_packets |
61 // to the correct value and return true. Otherwise it will return false. | 58 // to the correct value and return true. Otherwise it will return false. |
62 static bool GetOverflowFromMsghdr(struct msghdr* hdr, | 59 static bool GetOverflowFromMsghdr(struct msghdr* hdr, |
63 QuicPacketCount* dropped_packets); | 60 QuicPacketCount* dropped_packets); |
64 | 61 |
| 62 // If the msghdr contains an IP_TTL entry, this will set ttl to the correct |
| 63 // value and return true. Otherwise it will return false. |
| 64 static bool GetTtlFromMsghdr(struct msghdr* hdr, int* ttl); |
| 65 |
65 // Sets either IP_PKTINFO or IPV6_PKTINFO on the socket, based on | 66 // Sets either IP_PKTINFO or IPV6_PKTINFO on the socket, based on |
66 // address_family. Returns the return code from setsockopt. | 67 // address_family. Returns the return code from setsockopt. |
67 static int SetGetAddressInfo(int fd, int address_family); | 68 static int SetGetAddressInfo(int fd, int address_family); |
68 | 69 |
69 // Sets SO_TIMESTAMPING on the socket for software receive timestamping. | 70 // Sets SO_TIMESTAMPING on the socket for software receive timestamping. |
70 // Returns the return code from setsockopt. | 71 // Returns the return code from setsockopt. |
71 static int SetGetSoftwareReceiveTimestamp(int fd); | 72 static int SetGetSoftwareReceiveTimestamp(int fd); |
72 | 73 |
73 // Sets the send buffer size to |size| and returns false if it fails. | 74 // Sets the send buffer size to |size| and returns false if it fails. |
74 static bool SetSendBufferSize(int fd, size_t size); | 75 static bool SetSendBufferSize(int fd, size_t size); |
75 | 76 |
76 // Sets the receive buffer size to |size| and returns false if it fails. | 77 // Sets the receive buffer size to |size| and returns false if it fails. |
77 static bool SetReceiveBufferSize(int fd, size_t size); | 78 static bool SetReceiveBufferSize(int fd, size_t size); |
78 | 79 |
79 // Reads buf_len from the socket. If reading is successful, returns bytes | 80 // Reads buf_len from the socket. If reading is successful, returns bytes |
80 // read and sets peer_address to the peer address. Otherwise returns -1. | 81 // read and sets peer_address to the peer address. Otherwise returns -1. |
81 // | 82 // |
82 // If dropped_packets is non-null, it will be set to the number of packets | 83 // If dropped_packets is non-null, it will be set to the number of packets |
83 // dropped on the socket since the socket was created, assuming the kernel | 84 // dropped on the socket since the socket was created, assuming the kernel |
84 // supports this feature. | 85 // supports this feature. |
85 // | 86 // |
86 // If self_address is non-null, it will be set to the address the peer sent | 87 // If self_address is non-null, it will be set to the address the peer sent |
87 // packets to, assuming a packet was read. | 88 // packets to, assuming a packet was read. |
88 // | 89 // |
89 // If timestamp is non-null, it will be filled with the timestamp of the | 90 // If timestamp is non-null, it will be filled with the timestamp of the |
90 // received packet, assuming a packet was read and the platform supports | 91 // received packet, assuming a packet was read and the platform supports |
91 // packet receipt timestamping. If the platform does not support packet | 92 // packet receipt timestamping. If the platform does not support packet |
92 // receipt timestamping, timestamp will not be changed. | 93 // receipt timestamping, timestamp will not be changed. |
93 // TODO(rjshade): Delete the |timestamp| argument when removing | |
94 // FLAGS_quic_socket_timestamps_walltime | |
95 static int ReadPacket(int fd, | 94 static int ReadPacket(int fd, |
96 char* buffer, | 95 char* buffer, |
97 size_t buf_len, | 96 size_t buf_len, |
98 QuicPacketCount* dropped_packets, | 97 QuicPacketCount* dropped_packets, |
99 IPAddress* self_address, | 98 IPAddress* self_address, |
100 QuicTime* timestamp, | |
101 QuicWallTime* walltimestamp, | 99 QuicWallTime* walltimestamp, |
102 bool latched_walltimestamps, | |
103 IPEndPoint* peer_address); | 100 IPEndPoint* peer_address); |
104 | 101 |
105 // Writes buf_len to the socket. If writing is successful, sets the result's | 102 // Writes buf_len to the socket. If writing is successful, sets the result's |
106 // status to WRITE_STATUS_OK and sets bytes_written. Otherwise sets the | 103 // status to WRITE_STATUS_OK and sets bytes_written. Otherwise sets the |
107 // result's status to WRITE_STATUS_BLOCKED or WRITE_STATUS_ERROR and sets | 104 // result's status to WRITE_STATUS_BLOCKED or WRITE_STATUS_ERROR and sets |
108 // error_code to errno. | 105 // error_code to errno. |
109 static WriteResult WritePacket(int fd, | 106 static WriteResult WritePacket(int fd, |
110 const char* buffer, | 107 const char* buffer, |
111 size_t buf_len, | 108 size_t buf_len, |
112 const IPAddress& self_address, | 109 const IPAddress& self_address, |
(...skipping 10 matching lines...) Expand all Loading... |
123 static int CreateUDPSocket(const IPEndPoint& address, | 120 static int CreateUDPSocket(const IPEndPoint& address, |
124 bool* overflow_supported); | 121 bool* overflow_supported); |
125 | 122 |
126 private: | 123 private: |
127 DISALLOW_COPY_AND_ASSIGN(QuicSocketUtils); | 124 DISALLOW_COPY_AND_ASSIGN(QuicSocketUtils); |
128 }; | 125 }; |
129 | 126 |
130 } // namespace net | 127 } // namespace net |
131 | 128 |
132 #endif // NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ | 129 #endif // NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ |
OLD | NEW |