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 #include "net/tools/quic/quic_socket_utils.h" | 5 #include "net/tools/quic/quic_socket_utils.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 continue; | 44 continue; |
45 } | 45 } |
46 return IPAddressNumber(addr_data, addr_data + len); | 46 return IPAddressNumber(addr_data, addr_data + len); |
47 } | 47 } |
48 } | 48 } |
49 DCHECK(false) << "Unable to get address from msghdr"; | 49 DCHECK(false) << "Unable to get address from msghdr"; |
50 return IPAddressNumber(); | 50 return IPAddressNumber(); |
51 } | 51 } |
52 | 52 |
53 // static | 53 // static |
54 bool QuicSocketUtils::GetOverflowFromMsghdr(struct msghdr *hdr, | 54 bool QuicSocketUtils::GetOverflowFromMsghdr( |
55 uint32 *dropped_packets) { | 55 struct msghdr *hdr, |
| 56 QuicPacketCount *dropped_packets) { |
56 if (hdr->msg_controllen > 0) { | 57 if (hdr->msg_controllen > 0) { |
57 struct cmsghdr *cmsg; | 58 struct cmsghdr *cmsg; |
58 for (cmsg = CMSG_FIRSTHDR(hdr); | 59 for (cmsg = CMSG_FIRSTHDR(hdr); |
59 cmsg != nullptr; | 60 cmsg != nullptr; |
60 cmsg = CMSG_NXTHDR(hdr, cmsg)) { | 61 cmsg = CMSG_NXTHDR(hdr, cmsg)) { |
61 if (cmsg->cmsg_type == SO_RXQ_OVFL) { | 62 if (cmsg->cmsg_type == SO_RXQ_OVFL) { |
62 *dropped_packets = *(reinterpret_cast<int*>CMSG_DATA(cmsg)); | 63 *dropped_packets = *(reinterpret_cast<int*>CMSG_DATA(cmsg)); |
63 return true; | 64 return true; |
64 } | 65 } |
65 } | 66 } |
(...skipping 26 matching lines...) Expand all Loading... |
92 bool QuicSocketUtils::SetReceiveBufferSize(int fd, size_t size) { | 93 bool QuicSocketUtils::SetReceiveBufferSize(int fd, size_t size) { |
93 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) != 0) { | 94 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) != 0) { |
94 LOG(ERROR) << "Failed to set socket recv size"; | 95 LOG(ERROR) << "Failed to set socket recv size"; |
95 return false; | 96 return false; |
96 } | 97 } |
97 return true; | 98 return true; |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 int QuicSocketUtils::ReadPacket(int fd, char* buffer, size_t buf_len, | 102 int QuicSocketUtils::ReadPacket(int fd, char* buffer, size_t buf_len, |
102 uint32* dropped_packets, | 103 QuicPacketCount* dropped_packets, |
103 IPAddressNumber* self_address, | 104 IPAddressNumber* self_address, |
104 IPEndPoint* peer_address) { | 105 IPEndPoint* peer_address) { |
105 CHECK(peer_address != nullptr); | 106 CHECK(peer_address != nullptr); |
106 const int kSpaceForOverflowAndIp = | 107 const int kSpaceForOverflowAndIp = |
107 CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(in6_pktinfo)); | 108 CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(in6_pktinfo)); |
108 char cbuf[kSpaceForOverflowAndIp]; | 109 char cbuf[kSpaceForOverflowAndIp]; |
109 memset(cbuf, 0, arraysize(cbuf)); | 110 memset(cbuf, 0, arraysize(cbuf)); |
110 | 111 |
111 iovec iov = {buffer, buf_len}; | 112 iovec iov = {buffer, buf_len}; |
112 struct sockaddr_storage raw_address; | 113 struct sockaddr_storage raw_address; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 int rc = sendmsg(fd, &hdr, 0); | 217 int rc = sendmsg(fd, &hdr, 0); |
217 if (rc >= 0) { | 218 if (rc >= 0) { |
218 return WriteResult(WRITE_STATUS_OK, rc); | 219 return WriteResult(WRITE_STATUS_OK, rc); |
219 } | 220 } |
220 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) ? | 221 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) ? |
221 WRITE_STATUS_BLOCKED : WRITE_STATUS_ERROR, errno); | 222 WRITE_STATUS_BLOCKED : WRITE_STATUS_ERROR, errno); |
222 } | 223 } |
223 | 224 |
224 } // namespace tools | 225 } // namespace tools |
225 } // namespace net | 226 } // namespace net |
OLD | NEW |