| 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/socket_node.h" | 5 #include "nacl_io/socket/socket_node.h" |
| 6 | 6 |
| 7 #include "nacl_io/ossocket.h" | 7 #include "nacl_io/ossocket.h" |
| 8 #ifdef PROVIDES_SOCKET_API | 8 #ifdef PROVIDES_SOCKET_API |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 int copy_bytes = std::min(value_len, *len); | 259 int copy_bytes = std::min(value_len, *len); |
| 260 memcpy(optval, value_ptr, copy_bytes); | 260 memcpy(optval, value_ptr, copy_bytes); |
| 261 *len = value_len; | 261 *len = value_len; |
| 262 return 0; | 262 return 0; |
| 263 } | 263 } |
| 264 | 264 |
| 265 Error SocketNode::SetSockOpt(int lvl, | 265 Error SocketNode::SetSockOpt(int lvl, |
| 266 int optname, | 266 int optname, |
| 267 const void* optval, | 267 const void* optval, |
| 268 socklen_t len) { | 268 socklen_t len) { |
| 269 size_t buflen = static_cast<size_t>(len); |
| 270 |
| 269 if (lvl != SOL_SOCKET) | 271 if (lvl != SOL_SOCKET) |
| 270 return ENOPROTOOPT; | 272 return ENOPROTOOPT; |
| 271 | 273 |
| 272 AUTO_LOCK(node_lock_); | 274 AUTO_LOCK(node_lock_); |
| 273 | 275 |
| 274 switch (optname) { | 276 switch (optname) { |
| 275 case SO_REUSEADDR: { | 277 case SO_REUSEADDR: { |
| 276 // SO_REUSEADDR is effectivly always on since we can't | 278 // SO_REUSEADDR is effectivly always on since we can't |
| 277 // disable it with PPAPI sockets. Just return success | 279 // disable it with PPAPI sockets. Just return success |
| 278 // here regardless. | 280 // here regardless. |
| 279 if (len < sizeof(int)) | 281 if (buflen < sizeof(int)) |
| 280 return EINVAL; | 282 return EINVAL; |
| 281 return 0; | 283 return 0; |
| 282 } | 284 } |
| 283 case SO_LINGER: { | 285 case SO_LINGER: { |
| 284 // Not supported by the PPAPI interface but we preserve | 286 // Not supported by the PPAPI interface but we preserve |
| 285 // the settings and pretend to support it. | 287 // the settings and pretend to support it. |
| 286 if (len < sizeof(struct linger)) | 288 if (buflen < sizeof(struct linger)) |
| 287 return EINVAL; | 289 return EINVAL; |
| 288 struct linger new_linger = *static_cast<const linger*>(optval); | 290 struct linger new_linger = *static_cast<const linger*>(optval); |
| 289 // Don't allow setting linger to be enabled until we | 291 // Don't allow setting linger to be enabled until we |
| 290 // implement the required synchronous shutdown()/close(). | 292 // implement the required synchronous shutdown()/close(). |
| 291 // TODO(sbc): remove this after http://crbug.com/312401 | 293 // TODO(sbc): remove this after http://crbug.com/312401 |
| 292 // gets fixed. | 294 // gets fixed. |
| 293 if (new_linger.l_onoff != 0) | 295 if (new_linger.l_onoff != 0) |
| 294 return EINVAL; | 296 return EINVAL; |
| 295 linger_ = new_linger; | 297 linger_ = new_linger; |
| 296 return 0; | 298 return 0; |
| 297 } | 299 } |
| 298 case SO_KEEPALIVE: { | 300 case SO_KEEPALIVE: { |
| 299 // Not supported by the PPAPI interface but we preserve | 301 // Not supported by the PPAPI interface but we preserve |
| 300 // the flag and pretend to support it. | 302 // the flag and pretend to support it. |
| 301 if (len < sizeof(int)) | 303 if (buflen < sizeof(int)) |
| 302 return EINVAL; | 304 return EINVAL; |
| 303 int value = *static_cast<const int*>(optval); | 305 int value = *static_cast<const int*>(optval); |
| 304 keep_alive_ = value != 0; | 306 keep_alive_ = value != 0; |
| 305 return 0; | 307 return 0; |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 | 310 |
| 309 return ENOPROTOOPT; | 311 return ENOPROTOOPT; |
| 310 } | 312 } |
| 311 | 313 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 return 0; | 469 return 0; |
| 468 } | 470 } |
| 469 | 471 |
| 470 *len = ResourceToSockAddr(local_addr_, *len, addr); | 472 *len = ResourceToSockAddr(local_addr_, *len, addr); |
| 471 return 0; | 473 return 0; |
| 472 } | 474 } |
| 473 | 475 |
| 474 } // namespace nacl_io | 476 } // namespace nacl_io |
| 475 | 477 |
| 476 #endif // PROVIDES_SOCKET_API | 478 #endif // PROVIDES_SOCKET_API |
| OLD | NEW |