| 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 <net/if.h> | 10 #include <net/if.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/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/metrics/sparse_histogram.h" | 19 #include "base/metrics/sparse_histogram.h" |
| 19 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
| 20 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_log.h" | 25 #include "net/base/net_log.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 write_buf_ = NULL; | 120 write_buf_ = NULL; |
| 120 write_buf_len_ = 0; | 121 write_buf_len_ = 0; |
| 121 write_callback_.Reset(); | 122 write_callback_.Reset(); |
| 122 send_to_address_.reset(); | 123 send_to_address_.reset(); |
| 123 | 124 |
| 124 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); | 125 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); |
| 125 DCHECK(ok); | 126 DCHECK(ok); |
| 126 ok = write_socket_watcher_.StopWatchingFileDescriptor(); | 127 ok = write_socket_watcher_.StopWatchingFileDescriptor(); |
| 127 DCHECK(ok); | 128 DCHECK(ok); |
| 128 | 129 |
| 129 PCHECK(0 == IGNORE_EINTR(close(socket_))); | 130 if (IGNORE_EINTR(close(socket_)) == -1) { |
| 131 int last_error = errno; |
| 132 base::debug::Alias(&last_error); |
| 133 // Crash on any error other than EIO. |
| 134 PCHECK(last_error == EIO); |
| 135 } |
| 130 | 136 |
| 131 socket_ = kInvalidSocket; | 137 socket_ = kInvalidSocket; |
| 132 addr_family_ = 0; | 138 addr_family_ = 0; |
| 133 is_connected_ = false; | 139 is_connected_ = false; |
| 134 } | 140 } |
| 135 | 141 |
| 136 int UDPSocketLibevent::GetPeerAddress(IPEndPoint* address) const { | 142 int UDPSocketLibevent::GetPeerAddress(IPEndPoint* address) const { |
| 137 DCHECK(CalledOnValidThread()); | 143 DCHECK(CalledOnValidThread()); |
| 138 DCHECK(address); | 144 DCHECK(address); |
| 139 if (!is_connected()) | 145 if (!is_connected()) |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 return MapSystemError(errno); | 749 return MapSystemError(errno); |
| 744 | 750 |
| 745 return OK; | 751 return OK; |
| 746 } | 752 } |
| 747 | 753 |
| 748 void UDPSocketLibevent::DetachFromThread() { | 754 void UDPSocketLibevent::DetachFromThread() { |
| 749 base::NonThreadSafe::DetachFromThread(); | 755 base::NonThreadSafe::DetachFromThread(); |
| 750 } | 756 } |
| 751 | 757 |
| 752 } // namespace net | 758 } // namespace net |
| OLD | NEW |