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 <stddef.h> | 10 #include <stddef.h> |
11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
15 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 namespace tools { | 18 namespace tools { |
19 | 19 |
20 class QuicSocketUtils { | 20 class QuicSocketUtils { |
21 public: | 21 public: |
22 // If the msghdr contains IP_PKTINFO or IPV6_PKTINFO, this will return the | 22 // If the msghdr contains IP_PKTINFO or IPV6_PKTINFO, this will return the |
23 // IPAddressNumber in that header. Returns an uninitialized IPAddress on | 23 // IPAddressNumber in that header. Returns an uninitialized IPAddress on |
24 // failure. | 24 // failure. |
25 static IPAddressNumber GetAddressFromMsghdr(struct msghdr *hdr); | 25 static IPAddressNumber GetAddressFromMsghdr(struct msghdr* hdr); |
26 | 26 |
27 // If the msghdr contains an SO_RXQ_OVFL entry, this will set dropped_packets | 27 // If the msghdr contains an SO_RXQ_OVFL entry, this will set dropped_packets |
28 // to the correct value and return true. Otherwise it will return false. | 28 // to the correct value and return true. Otherwise it will return false. |
29 static bool GetOverflowFromMsghdr(struct msghdr *hdr, | 29 static bool GetOverflowFromMsghdr(struct msghdr* hdr, |
30 uint32 *dropped_packets); | 30 uint32* dropped_packets); |
31 | 31 |
32 // Sets either IP_PKTINFO or IPV6_PKTINFO on the socket, based on | 32 // Sets either IP_PKTINFO or IPV6_PKTINFO on the socket, based on |
33 // address_family. Returns the return code from setsockopt. | 33 // address_family. Returns the return code from setsockopt. |
34 static int SetGetAddressInfo(int fd, int address_family); | 34 static int SetGetAddressInfo(int fd, int address_family); |
35 | 35 |
36 // Sets the send buffer size to |size| and returns false if it fails. | 36 // Sets the send buffer size to |size| and returns false if it fails. |
37 static bool SetSendBufferSize(int fd, size_t size); | 37 static bool SetSendBufferSize(int fd, size_t size); |
38 | 38 |
39 // Sets the receive buffer size to |size| and returns false if it fails. | 39 // Sets the receive buffer size to |size| and returns false if it fails. |
40 static bool SetReceiveBufferSize(int fd, size_t size); | 40 static bool SetReceiveBufferSize(int fd, size_t size); |
(...skipping 11 matching lines...) Expand all Loading... |
52 char* buffer, | 52 char* buffer, |
53 size_t buf_len, | 53 size_t buf_len, |
54 uint32* dropped_packets, | 54 uint32* dropped_packets, |
55 IPAddressNumber* self_address, | 55 IPAddressNumber* self_address, |
56 IPEndPoint* peer_address); | 56 IPEndPoint* peer_address); |
57 | 57 |
58 // Writes buf_len to the socket. If writing is successful, sets the result's | 58 // Writes buf_len to the socket. If writing is successful, sets the result's |
59 // status to WRITE_STATUS_OK and sets bytes_written. Otherwise sets the | 59 // status to WRITE_STATUS_OK and sets bytes_written. Otherwise sets the |
60 // result's status to WRITE_STATUS_BLOCKED or WRITE_STATUS_ERROR and sets | 60 // result's status to WRITE_STATUS_BLOCKED or WRITE_STATUS_ERROR and sets |
61 // error_code to errno. | 61 // error_code to errno. |
62 static WriteResult WritePacket(int fd, const char* buffer, size_t buf_len, | 62 static WriteResult WritePacket(int fd, |
| 63 const char* buffer, |
| 64 size_t buf_len, |
63 const IPAddressNumber& self_address, | 65 const IPAddressNumber& self_address, |
64 const IPEndPoint& peer_address); | 66 const IPEndPoint& peer_address); |
65 | 67 |
66 private: | 68 private: |
67 DISALLOW_COPY_AND_ASSIGN(QuicSocketUtils); | 69 DISALLOW_COPY_AND_ASSIGN(QuicSocketUtils); |
68 }; | 70 }; |
69 | 71 |
70 } // namespace tools | 72 } // namespace tools |
71 } // namespace net | 73 } // namespace net |
72 | 74 |
73 #endif // NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ | 75 #endif // NET_TOOLS_QUIC_QUIC_SOCKET_UTILS_H_ |
OLD | NEW |