| 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> |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 int UDPSocketPosix::GetPeerAddress(IPEndPoint* address) const { | 144 int UDPSocketPosix::GetPeerAddress(IPEndPoint* address) const { |
| 145 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
| 146 DCHECK(address); | 146 DCHECK(address); |
| 147 if (!is_connected()) | 147 if (!is_connected()) |
| 148 return ERR_SOCKET_NOT_CONNECTED; | 148 return ERR_SOCKET_NOT_CONNECTED; |
| 149 | 149 |
| 150 if (!remote_address_.get()) { | 150 if (!remote_address_.get()) { |
| 151 SockaddrStorage storage; | 151 SockaddrStorage storage; |
| 152 if (getpeername(socket_, storage.addr, &storage.addr_len)) | 152 if (getpeername(socket_, storage.addr, &storage.addr_len)) |
| 153 return MapSystemError(errno); | 153 return MapSystemError(errno); |
| 154 scoped_ptr<IPEndPoint> address(new IPEndPoint()); | 154 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); |
| 155 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 155 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
| 156 return ERR_ADDRESS_INVALID; | 156 return ERR_ADDRESS_INVALID; |
| 157 remote_address_.reset(address.release()); | 157 remote_address_.reset(address.release()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 *address = *remote_address_; | 160 *address = *remote_address_; |
| 161 return OK; | 161 return OK; |
| 162 } | 162 } |
| 163 | 163 |
| 164 int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const { | 164 int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const { |
| 165 DCHECK(CalledOnValidThread()); | 165 DCHECK(CalledOnValidThread()); |
| 166 DCHECK(address); | 166 DCHECK(address); |
| 167 if (!is_connected()) | 167 if (!is_connected()) |
| 168 return ERR_SOCKET_NOT_CONNECTED; | 168 return ERR_SOCKET_NOT_CONNECTED; |
| 169 | 169 |
| 170 if (!local_address_.get()) { | 170 if (!local_address_.get()) { |
| 171 SockaddrStorage storage; | 171 SockaddrStorage storage; |
| 172 if (getsockname(socket_, storage.addr, &storage.addr_len)) | 172 if (getsockname(socket_, storage.addr, &storage.addr_len)) |
| 173 return MapSystemError(errno); | 173 return MapSystemError(errno); |
| 174 scoped_ptr<IPEndPoint> address(new IPEndPoint()); | 174 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); |
| 175 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 175 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
| 176 return ERR_ADDRESS_INVALID; | 176 return ERR_ADDRESS_INVALID; |
| 177 local_address_.reset(address.release()); | 177 local_address_.reset(address.release()); |
| 178 net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS, | 178 net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS, |
| 179 CreateNetLogUDPConnectCallback(local_address_.get())); | 179 CreateNetLogUDPConnectCallback(local_address_.get())); |
| 180 } | 180 } |
| 181 | 181 |
| 182 *address = *local_address_; | 182 *address = *local_address_; |
| 183 return OK; | 183 return OK; |
| 184 } | 184 } |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 return MapSystemError(errno); | 803 return MapSystemError(errno); |
| 804 | 804 |
| 805 return OK; | 805 return OK; |
| 806 } | 806 } |
| 807 | 807 |
| 808 void UDPSocketPosix::DetachFromThread() { | 808 void UDPSocketPosix::DetachFromThread() { |
| 809 base::NonThreadSafe::DetachFromThread(); | 809 base::NonThreadSafe::DetachFromThread(); |
| 810 } | 810 } |
| 811 | 811 |
| 812 } // namespace net | 812 } // namespace net |
| OLD | NEW |