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_win.h" | 5 #include "net/udp/udp_socket_win.h" |
6 | 6 |
7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 DCHECK(CalledOnValidThread()); | 320 DCHECK(CalledOnValidThread()); |
321 DCHECK(address); | 321 DCHECK(address); |
322 if (!is_connected()) | 322 if (!is_connected()) |
323 return ERR_SOCKET_NOT_CONNECTED; | 323 return ERR_SOCKET_NOT_CONNECTED; |
324 | 324 |
325 // TODO(szym): Simplify. http://crbug.com/126152 | 325 // TODO(szym): Simplify. http://crbug.com/126152 |
326 if (!remote_address_.get()) { | 326 if (!remote_address_.get()) { |
327 SockaddrStorage storage; | 327 SockaddrStorage storage; |
328 if (getpeername(socket_, storage.addr, &storage.addr_len)) | 328 if (getpeername(socket_, storage.addr, &storage.addr_len)) |
329 return MapSystemError(WSAGetLastError()); | 329 return MapSystemError(WSAGetLastError()); |
330 scoped_ptr<IPEndPoint> address(new IPEndPoint()); | 330 scoped_ptr<IPEndPoint> remote_address(new IPEndPoint()); |
331 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 331 if (!remote_address->FromSockAddr(storage.addr, storage.addr_len)) |
332 return ERR_ADDRESS_INVALID; | 332 return ERR_ADDRESS_INVALID; |
333 remote_address_.reset(address.release()); | 333 remote_address_.reset(remote_address.release()); |
334 } | 334 } |
335 | 335 |
336 *address = *remote_address_; | 336 *address = *remote_address_; |
337 return OK; | 337 return OK; |
338 } | 338 } |
339 | 339 |
340 int UDPSocketWin::GetLocalAddress(IPEndPoint* address) const { | 340 int UDPSocketWin::GetLocalAddress(IPEndPoint* address) const { |
341 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
342 DCHECK(address); | 342 DCHECK(address); |
343 if (!is_connected()) | 343 if (!is_connected()) |
344 return ERR_SOCKET_NOT_CONNECTED; | 344 return ERR_SOCKET_NOT_CONNECTED; |
345 | 345 |
346 // TODO(szym): Simplify. http://crbug.com/126152 | 346 // TODO(szym): Simplify. http://crbug.com/126152 |
347 if (!local_address_.get()) { | 347 if (!local_address_.get()) { |
348 SockaddrStorage storage; | 348 SockaddrStorage storage; |
349 if (getsockname(socket_, storage.addr, &storage.addr_len)) | 349 if (getsockname(socket_, storage.addr, &storage.addr_len)) |
350 return MapSystemError(WSAGetLastError()); | 350 return MapSystemError(WSAGetLastError()); |
351 scoped_ptr<IPEndPoint> address(new IPEndPoint()); | 351 scoped_ptr<IPEndPoint> local_address(new IPEndPoint()); |
352 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 352 if (!local_address->FromSockAddr(storage.addr, storage.addr_len)) |
353 return ERR_ADDRESS_INVALID; | 353 return ERR_ADDRESS_INVALID; |
354 local_address_.reset(address.release()); | 354 local_address_.reset(local_address.release()); |
355 net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS, | 355 net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS, |
356 CreateNetLogUDPConnectCallback(local_address_.get())); | 356 CreateNetLogUDPConnectCallback(local_address_.get())); |
357 } | 357 } |
358 | 358 |
359 *address = *local_address_; | 359 *address = *local_address_; |
360 return OK; | 360 return OK; |
361 } | 361 } |
362 | 362 |
363 int UDPSocketWin::Read(IOBuffer* buf, | 363 int UDPSocketWin::Read(IOBuffer* buf, |
364 int buf_len, | 364 int buf_len, |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 NULL); | 1010 NULL); |
1011 | 1011 |
1012 return OK; | 1012 return OK; |
1013 } | 1013 } |
1014 | 1014 |
1015 void UDPSocketWin::DetachFromThread() { | 1015 void UDPSocketWin::DetachFromThread() { |
1016 base::NonThreadSafe::DetachFromThread(); | 1016 base::NonThreadSafe::DetachFromThread(); |
1017 } | 1017 } |
1018 | 1018 |
1019 } // namespace net | 1019 } // namespace net |
OLD | NEW |