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> |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 if (!is_connected()) | 238 if (!is_connected()) |
239 return ERR_SOCKET_NOT_CONNECTED; | 239 return ERR_SOCKET_NOT_CONNECTED; |
240 | 240 |
241 if (!remote_address_.get()) { | 241 if (!remote_address_.get()) { |
242 SockaddrStorage storage; | 242 SockaddrStorage storage; |
243 if (getpeername(socket_, storage.addr, &storage.addr_len)) | 243 if (getpeername(socket_, storage.addr, &storage.addr_len)) |
244 return MapSystemError(errno); | 244 return MapSystemError(errno); |
245 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); | 245 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); |
246 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 246 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
247 return ERR_ADDRESS_INVALID; | 247 return ERR_ADDRESS_INVALID; |
248 remote_address_.reset(address.release()); | 248 remote_address_ = std::move(address); |
249 } | 249 } |
250 | 250 |
251 *address = *remote_address_; | 251 *address = *remote_address_; |
252 return OK; | 252 return OK; |
253 } | 253 } |
254 | 254 |
255 int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const { | 255 int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const { |
256 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
257 DCHECK(address); | 257 DCHECK(address); |
258 if (!is_connected()) | 258 if (!is_connected()) |
259 return ERR_SOCKET_NOT_CONNECTED; | 259 return ERR_SOCKET_NOT_CONNECTED; |
260 | 260 |
261 if (!local_address_.get()) { | 261 if (!local_address_.get()) { |
262 SockaddrStorage storage; | 262 SockaddrStorage storage; |
263 if (getsockname(socket_, storage.addr, &storage.addr_len)) | 263 if (getsockname(socket_, storage.addr, &storage.addr_len)) |
264 return MapSystemError(errno); | 264 return MapSystemError(errno); |
265 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); | 265 std::unique_ptr<IPEndPoint> address(new IPEndPoint()); |
266 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 266 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
267 return ERR_ADDRESS_INVALID; | 267 return ERR_ADDRESS_INVALID; |
268 local_address_.reset(address.release()); | 268 local_address_ = std::move(address); |
269 net_log_.AddEvent( | 269 net_log_.AddEvent( |
270 NetLogEventType::UDP_LOCAL_ADDRESS, | 270 NetLogEventType::UDP_LOCAL_ADDRESS, |
271 CreateNetLogUDPConnectCallback(local_address_.get(), bound_network_)); | 271 CreateNetLogUDPConnectCallback(local_address_.get(), bound_network_)); |
272 } | 272 } |
273 | 273 |
274 *address = *local_address_; | 274 *address = *local_address_; |
275 return OK; | 275 return OK; |
276 } | 276 } |
277 | 277 |
278 int UDPSocketPosix::Read(IOBuffer* buf, | 278 int UDPSocketPosix::Read(IOBuffer* buf, |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 return MapSystemError(errno); | 963 return MapSystemError(errno); |
964 | 964 |
965 return OK; | 965 return OK; |
966 } | 966 } |
967 | 967 |
968 void UDPSocketPosix::DetachFromThread() { | 968 void UDPSocketPosix::DetachFromThread() { |
969 base::NonThreadSafe::DetachFromThread(); | 969 base::NonThreadSafe::DetachFromThread(); |
970 } | 970 } |
971 | 971 |
972 } // namespace net | 972 } // namespace net |
OLD | NEW |