OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "nacl_io/socket/udp_node.h" | 5 #include "nacl_io/socket/udp_node.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 if (!TestStreamFlags(SSF_CAN_SEND)) | 187 if (!TestStreamFlags(SSF_CAN_SEND)) |
188 return; | 188 return; |
189 | 189 |
190 if (TestStreamFlags(SSF_SENDING)) | 190 if (TestStreamFlags(SSF_SENDING)) |
191 return; | 191 return; |
192 | 192 |
193 UdpSendWork* work = new UdpSendWork(emitter_, ScopedSocketNode(this)); | 193 UdpSendWork* work = new UdpSendWork(emitter_, ScopedSocketNode(this)); |
194 stream()->EnqueueWork(work); | 194 stream()->EnqueueWork(work); |
195 } | 195 } |
196 | 196 |
| 197 Error UdpNode::SetSockOpt(int lvl, |
| 198 int optname, |
| 199 const void* optval, |
| 200 socklen_t len) { |
| 201 if (lvl == SOL_SOCKET && optname == SO_RCVBUF) { |
| 202 if (static_cast<size_t>(len) < sizeof(int)) |
| 203 return EINVAL; |
| 204 AUTO_LOCK(node_lock_); |
| 205 int bufsize = *static_cast<const int*>(optval); |
| 206 int32_t error = |
| 207 UDPInterface()->SetOption(socket_resource_, |
| 208 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE, |
| 209 PP_MakeInt32(bufsize), |
| 210 PP_BlockUntilComplete()); |
| 211 return PPErrorToErrno(error); |
| 212 } else if (lvl == SOL_SOCKET && optname == SO_SNDBUF) { |
| 213 if (static_cast<size_t>(len) < sizeof(int)) |
| 214 return EINVAL; |
| 215 AUTO_LOCK(node_lock_); |
| 216 int bufsize = *static_cast<const int*>(optval); |
| 217 int32_t error = |
| 218 UDPInterface()->SetOption(socket_resource_, |
| 219 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE, |
| 220 PP_MakeInt32(bufsize), |
| 221 PP_BlockUntilComplete()); |
| 222 return PPErrorToErrno(error); |
| 223 } |
| 224 |
| 225 return SocketNode::SetSockOpt(lvl, optname, optval, len); |
| 226 } |
| 227 |
197 Error UdpNode::Bind(const struct sockaddr* addr, socklen_t len) { | 228 Error UdpNode::Bind(const struct sockaddr* addr, socklen_t len) { |
198 if (0 == socket_resource_) | 229 if (0 == socket_resource_) |
199 return EBADF; | 230 return EBADF; |
200 | 231 |
201 /* Only bind once. */ | 232 /* Only bind once. */ |
202 if (IsBound()) | 233 if (IsBound()) |
203 return EINVAL; | 234 return EINVAL; |
204 | 235 |
205 PP_Resource out_addr = SockAddrToResource(addr, len); | 236 PP_Resource out_addr = SockAddrToResource(addr, len); |
206 if (0 == out_addr) | 237 if (0 == out_addr) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 int capped_len = static_cast<int32_t>(std::min<int>(len, kMaxPacketSize)); | 322 int capped_len = static_cast<int32_t>(std::min<int>(len, kMaxPacketSize)); |
292 Packet* packet = new Packet(filesystem_->ppapi()); | 323 Packet* packet = new Packet(filesystem_->ppapi()); |
293 packet->Copy(buf, capped_len, addr); | 324 packet->Copy(buf, capped_len, addr); |
294 | 325 |
295 emitter_->WriteTXPacket_Locked(packet); | 326 emitter_->WriteTXPacket_Locked(packet); |
296 *out_len = capped_len; | 327 *out_len = capped_len; |
297 return 0; | 328 return 0; |
298 } | 329 } |
299 | 330 |
300 } // namespace nacl_io | 331 } // namespace nacl_io |
OLD | NEW |