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/udp/udp_socket_libevent.h" | 5 #include "net/udp/udp_socket_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 515 } |
516 if (rv < 0) | 516 if (rv < 0) |
517 return MapSystemError(errno); | 517 return MapSystemError(errno); |
518 } | 518 } |
519 return OK; | 519 return OK; |
520 } | 520 } |
521 | 521 |
522 int UDPSocketLibevent::DoBind(const IPEndPoint& address) { | 522 int UDPSocketLibevent::DoBind(const IPEndPoint& address) { |
523 SockaddrStorage storage; | 523 SockaddrStorage storage; |
524 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 524 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
525 return ERR_UNEXPECTED; | 525 return ERR_ADDRESS_INVALID; |
526 int rv = bind(socket_, storage.addr, storage.addr_len); | 526 int rv = bind(socket_, storage.addr, storage.addr_len); |
527 return rv < 0 ? MapSystemError(errno) : rv; | 527 return rv < 0 ? MapSystemError(errno) : rv; |
528 } | 528 } |
529 | 529 |
530 int UDPSocketLibevent::RandomBind(const IPEndPoint& address) { | 530 int UDPSocketLibevent::RandomBind(const IPEndPoint& address) { |
531 DCHECK(bind_type_ == DatagramSocket::RANDOM_BIND && !rand_int_cb_.is_null()); | 531 DCHECK(bind_type_ == DatagramSocket::RANDOM_BIND && !rand_int_cb_.is_null()); |
532 | 532 |
533 // Construct IPAddressNumber of appropriate size (IPv4 or IPv6) of 0s. | 533 // Construct IPAddressNumber of appropriate size (IPv4 or IPv6) of 0s. |
534 IPAddressNumber ip(address.address().size()); | 534 IPAddressNumber ip(address.address().size()); |
535 | 535 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 610 } |
611 default: | 611 default: |
612 NOTREACHED() << "Invalid address family"; | 612 NOTREACHED() << "Invalid address family"; |
613 return ERR_ADDRESS_INVALID; | 613 return ERR_ADDRESS_INVALID; |
614 } | 614 } |
615 } | 615 } |
616 | 616 |
617 int UDPSocketLibevent::SetMulticastTimeToLive(int time_to_live) { | 617 int UDPSocketLibevent::SetMulticastTimeToLive(int time_to_live) { |
618 DCHECK(CalledOnValidThread()); | 618 DCHECK(CalledOnValidThread()); |
619 if (is_connected()) | 619 if (is_connected()) |
620 return ERR_UNEXPECTED; | 620 return ERR_SOCKET_IS_CONNECTED; |
621 | 621 |
622 if (time_to_live < 0 || time_to_live > 255) | 622 if (time_to_live < 0 || time_to_live > 255) |
623 return ERR_INVALID_ARGUMENT; | 623 return ERR_INVALID_ARGUMENT; |
624 multicast_time_to_live_ = time_to_live; | 624 multicast_time_to_live_ = time_to_live; |
625 return OK; | 625 return OK; |
626 } | 626 } |
627 | 627 |
628 int UDPSocketLibevent::SetMulticastLoopbackMode(bool loopback) { | 628 int UDPSocketLibevent::SetMulticastLoopbackMode(bool loopback) { |
629 DCHECK(CalledOnValidThread()); | 629 DCHECK(CalledOnValidThread()); |
630 if (is_connected()) | 630 if (is_connected()) |
631 return ERR_UNEXPECTED; | 631 return ERR_SOCKET_IS_CONNECTED; |
632 | 632 |
633 if (loopback) | 633 if (loopback) |
634 socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP; | 634 socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP; |
635 else | 635 else |
636 socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP; | 636 socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP; |
637 return OK; | 637 return OK; |
638 } | 638 } |
639 } // namespace net | 639 } // namespace net |
OLD | NEW |