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 <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/uio.h> | 10 #include <sys/uio.h> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 iovec iov = {buffer, buf_len}; | 109 iovec iov = {buffer, buf_len}; |
110 struct sockaddr_storage raw_address; | 110 struct sockaddr_storage raw_address; |
111 msghdr hdr; | 111 msghdr hdr; |
112 | 112 |
113 hdr.msg_name = &raw_address; | 113 hdr.msg_name = &raw_address; |
114 hdr.msg_namelen = sizeof(sockaddr_storage); | 114 hdr.msg_namelen = sizeof(sockaddr_storage); |
115 hdr.msg_iov = &iov; | 115 hdr.msg_iov = &iov; |
116 hdr.msg_iovlen = 1; | 116 hdr.msg_iovlen = 1; |
117 hdr.msg_flags = 0; | 117 hdr.msg_flags = 0; |
118 | 118 |
119 struct cmsghdr* cmsg = (struct cmsghdr*)cbuf; | 119 struct cmsghdr* cmsg = reinterpret_cast<struct cmsghdr*>(cbuf); |
120 cmsg->cmsg_len = arraysize(cbuf); | 120 cmsg->cmsg_len = arraysize(cbuf); |
121 hdr.msg_control = cmsg; | 121 hdr.msg_control = cmsg; |
122 hdr.msg_controllen = arraysize(cbuf); | 122 hdr.msg_controllen = arraysize(cbuf); |
123 | 123 |
124 int bytes_read = recvmsg(fd, &hdr, 0); | 124 int bytes_read = recvmsg(fd, &hdr, 0); |
125 | 125 |
126 // Return before setting dropped packets: if we get EAGAIN, it will | 126 // Return before setting dropped packets: if we get EAGAIN, it will |
127 // be 0. | 127 // be 0. |
128 if (bytes_read < 0 && errno != 0) { | 128 if (bytes_read < 0 && errno != 0) { |
129 if (errno != EAGAIN) { | 129 if (errno != EAGAIN) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 int rc = sendmsg(fd, &hdr, 0); | 214 int rc = sendmsg(fd, &hdr, 0); |
215 if (rc >= 0) { | 215 if (rc >= 0) { |
216 return WriteResult(WRITE_STATUS_OK, rc); | 216 return WriteResult(WRITE_STATUS_OK, rc); |
217 } | 217 } |
218 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) ? | 218 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) ? |
219 WRITE_STATUS_BLOCKED : WRITE_STATUS_ERROR, errno); | 219 WRITE_STATUS_BLOCKED : WRITE_STATUS_ERROR, errno); |
220 } | 220 } |
221 | 221 |
222 } // namespace tools | 222 } // namespace tools |
223 } // namespace net | 223 } // namespace net |
OLD | NEW |