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_posix.h" | 5 #include "net/udp/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/sparse_histogram.h" | 20 #include "base/metrics/sparse_histogram.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 "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
24 #include "net/base/ip_address.h" | 25 #include "net/base/ip_address.h" |
25 #include "net/base/ip_endpoint.h" | 26 #include "net/base/ip_endpoint.h" |
26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
27 #include "net/base/network_activity_monitor.h" | 28 #include "net/base/network_activity_monitor.h" |
28 #include "net/base/sockaddr_storage.h" | 29 #include "net/base/sockaddr_storage.h" |
29 #include "net/log/net_log.h" | 30 #include "net/log/net_log.h" |
30 #include "net/socket/socket_descriptor.h" | 31 #include "net/socket/socket_descriptor.h" |
31 #include "net/udp/udp_net_log_parameters.h" | 32 #include "net/udp/udp_net_log_parameters.h" |
32 | 33 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // UDP multicast or broadcast datagrams destined for the bound | 407 // UDP multicast or broadcast datagrams destined for the bound |
407 // port. | 408 // port. |
408 rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, &value, sizeof(value)); | 409 rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, &value, sizeof(value)); |
409 #else | 410 #else |
410 rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); | 411 rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); |
411 #endif // defined(OS_MACOSX) | 412 #endif // defined(OS_MACOSX) |
412 return rv == 0 ? OK : MapSystemError(errno); | 413 return rv == 0 ? OK : MapSystemError(errno); |
413 } | 414 } |
414 | 415 |
415 void UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking(int) { | 416 void UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking(int) { |
| 417 TRACE_EVENT0("net", |
| 418 "UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking"); |
416 if (!socket_->read_callback_.is_null()) | 419 if (!socket_->read_callback_.is_null()) |
417 socket_->DidCompleteRead(); | 420 socket_->DidCompleteRead(); |
418 } | 421 } |
419 | 422 |
420 void UDPSocketPosix::WriteWatcher::OnFileCanWriteWithoutBlocking(int) { | 423 void UDPSocketPosix::WriteWatcher::OnFileCanWriteWithoutBlocking(int) { |
421 if (!socket_->write_callback_.is_null()) | 424 if (!socket_->write_callback_.is_null()) |
422 socket_->DidCompleteWrite(); | 425 socket_->DidCompleteWrite(); |
423 } | 426 } |
424 | 427 |
425 void UDPSocketPosix::DoReadCallback(int rv) { | 428 void UDPSocketPosix::DoReadCallback(int rv) { |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 return MapSystemError(errno); | 803 return MapSystemError(errno); |
801 | 804 |
802 return OK; | 805 return OK; |
803 } | 806 } |
804 | 807 |
805 void UDPSocketPosix::DetachFromThread() { | 808 void UDPSocketPosix::DetachFromThread() { |
806 base::NonThreadSafe::DetachFromThread(); | 809 base::NonThreadSafe::DetachFromThread(); |
807 } | 810 } |
808 | 811 |
809 } // namespace net | 812 } // namespace net |
OLD | NEW |