| 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/socket/udp_socket_posix.h" | 5 #include "net/socket/udp_socket_posix.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <net/if.h> | 9 #include <net/if.h> |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| 11 #include <netinet/in.h> | 11 #include <netinet/in.h> |
| 12 #include <sys/ioctl.h> | 12 #include <sys/ioctl.h> |
| 13 #include <sys/socket.h> | 13 #include <sys/socket.h> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/posix/eintr_wrapper.h" | 21 #include "base/posix/eintr_wrapper.h" |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 24 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
| 25 #include "net/base/ip_address.h" | 25 #include "net/base/ip_address.h" |
| 26 #include "net/base/ip_endpoint.h" | 26 #include "net/base/ip_endpoint.h" |
| 27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 28 #include "net/base/network_activity_monitor.h" | 28 #include "net/base/network_activity_monitor.h" |
| 29 #include "net/base/sockaddr_storage.h" | 29 #include "net/base/sockaddr_storage.h" |
| 30 #include "net/base/trace_constants.h" |
| 30 #include "net/log/net_log.h" | 31 #include "net/log/net_log.h" |
| 31 #include "net/log/net_log_event_type.h" | 32 #include "net/log/net_log_event_type.h" |
| 32 #include "net/log/net_log_source.h" | 33 #include "net/log/net_log_source.h" |
| 33 #include "net/log/net_log_source_type.h" | 34 #include "net/log/net_log_source_type.h" |
| 34 #include "net/socket/socket_descriptor.h" | 35 #include "net/socket/socket_descriptor.h" |
| 35 #include "net/socket/udp_net_log_parameters.h" | 36 #include "net/socket/udp_net_log_parameters.h" |
| 36 | 37 |
| 37 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
| 38 #include <dlfcn.h> | 39 #include <dlfcn.h> |
| 39 // This was added in Lollipop to dlfcn.h | 40 // This was added in Lollipop to dlfcn.h |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, &value, sizeof(value)); | 568 rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, &value, sizeof(value)); |
| 568 if (rv != 0) | 569 if (rv != 0) |
| 569 return MapSystemError(errno); | 570 return MapSystemError(errno); |
| 570 #endif // defined(OS_MACOSX) | 571 #endif // defined(OS_MACOSX) |
| 571 rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); | 572 rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); |
| 572 | 573 |
| 573 return rv == 0 ? OK : MapSystemError(errno); | 574 return rv == 0 ? OK : MapSystemError(errno); |
| 574 } | 575 } |
| 575 | 576 |
| 576 void UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking(int) { | 577 void UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking(int) { |
| 577 TRACE_EVENT0("net", | 578 TRACE_EVENT0(kNetTracingCategory, |
| 578 "UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking"); | 579 "UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking"); |
| 579 if (!socket_->read_callback_.is_null()) | 580 if (!socket_->read_callback_.is_null()) |
| 580 socket_->DidCompleteRead(); | 581 socket_->DidCompleteRead(); |
| 581 } | 582 } |
| 582 | 583 |
| 583 void UDPSocketPosix::WriteWatcher::OnFileCanWriteWithoutBlocking(int) { | 584 void UDPSocketPosix::WriteWatcher::OnFileCanWriteWithoutBlocking(int) { |
| 584 if (!socket_->write_callback_.is_null()) | 585 if (!socket_->write_callback_.is_null()) |
| 585 socket_->DidCompleteWrite(); | 586 socket_->DidCompleteWrite(); |
| 586 } | 587 } |
| 587 | 588 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 return MapSystemError(errno); | 963 return MapSystemError(errno); |
| 963 | 964 |
| 964 return OK; | 965 return OK; |
| 965 } | 966 } |
| 966 | 967 |
| 967 void UDPSocketPosix::DetachFromThread() { | 968 void UDPSocketPosix::DetachFromThread() { |
| 968 base::NonThreadSafe::DetachFromThread(); | 969 base::NonThreadSafe::DetachFromThread(); |
| 969 } | 970 } |
| 970 | 971 |
| 971 } // namespace net | 972 } // namespace net |
| OLD | NEW |