Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: net/udp/udp_socket_win.cc

Issue 10882020: [net/udp] Close events and invalidate handles when UDPSocketWin is closed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add check that the socket is still open Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/callback.h" 9 #include "base/callback.h"
10 #include "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return; 76 return;
77 77
78 // Zero out any pending read/write callback state. 78 // Zero out any pending read/write callback state.
79 read_callback_.Reset(); 79 read_callback_.Reset();
80 recv_from_address_ = NULL; 80 recv_from_address_ = NULL;
81 write_callback_.Reset(); 81 write_callback_.Reset();
82 82
83 read_watcher_.StopWatching(); 83 read_watcher_.StopWatching();
84 write_watcher_.StopWatching(); 84 write_watcher_.StopWatching();
85 85
86 WSACloseEvent(read_overlapped_.hEvent);
87 memset(&read_overlapped_, 0xaf, sizeof(read_overlapped_));
88 WSACloseEvent(write_overlapped_.hEvent);
89 memset(&write_overlapped_, 0xaf, sizeof(write_overlapped_));
90
86 closesocket(socket_); 91 closesocket(socket_);
87 socket_ = INVALID_SOCKET; 92 socket_ = INVALID_SOCKET;
88 } 93 }
89 94
90 int UDPSocketWin::GetPeerAddress(IPEndPoint* address) const { 95 int UDPSocketWin::GetPeerAddress(IPEndPoint* address) const {
91 DCHECK(CalledOnValidThread()); 96 DCHECK(CalledOnValidThread());
92 DCHECK(address); 97 DCHECK(address);
93 if (!is_connected()) 98 if (!is_connected())
94 return ERR_SOCKET_NOT_CONNECTED; 99 return ERR_SOCKET_NOT_CONNECTED;
95 100
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 recv_addr_len_ = sizeof(recv_addr_storage_); 377 recv_addr_len_ = sizeof(recv_addr_storage_);
373 struct sockaddr* addr = 378 struct sockaddr* addr =
374 reinterpret_cast<struct sockaddr*>(&recv_addr_storage_); 379 reinterpret_cast<struct sockaddr*>(&recv_addr_storage_);
375 380
376 WSABUF read_buffer; 381 WSABUF read_buffer;
377 read_buffer.buf = buf->data(); 382 read_buffer.buf = buf->data();
378 read_buffer.len = buf_len; 383 read_buffer.len = buf_len;
379 384
380 DWORD flags = 0; 385 DWORD flags = 0;
381 DWORD num; 386 DWORD num;
387 CHECK_NE(INVALID_SOCKET, socket_);
382 AssertEventNotSignaled(read_overlapped_.hEvent); 388 AssertEventNotSignaled(read_overlapped_.hEvent);
383 int rv = WSARecvFrom(socket_, &read_buffer, 1, &num, &flags, addr, 389 int rv = WSARecvFrom(socket_, &read_buffer, 1, &num, &flags, addr,
384 &recv_addr_len_, &read_overlapped_, NULL); 390 &recv_addr_len_, &read_overlapped_, NULL);
385 if (rv == 0) { 391 if (rv == 0) {
386 if (ResetEventIfSignaled(read_overlapped_.hEvent)) { 392 if (ResetEventIfSignaled(read_overlapped_.hEvent)) {
387 int result = num; 393 int result = num;
388 // Convert address. 394 // Convert address.
389 if (address && result >= 0) { 395 if (address && result >= 0) {
390 if (!ReceiveAddressToIPEndpoint(address)) 396 if (!ReceiveAddressToIPEndpoint(address))
391 result = ERR_FAILED; 397 result = ERR_FAILED;
(...skipping 28 matching lines...) Expand all
420 return result; 426 return result;
421 } 427 }
422 } 428 }
423 429
424 WSABUF write_buffer; 430 WSABUF write_buffer;
425 write_buffer.buf = buf->data(); 431 write_buffer.buf = buf->data();
426 write_buffer.len = buf_len; 432 write_buffer.len = buf_len;
427 433
428 DWORD flags = 0; 434 DWORD flags = 0;
429 DWORD num; 435 DWORD num;
430 AssertEventNotSignaled(write_overlapped_.hEvent); 436 AssertEventNotSignaled(write_overlapped_.hEvent);
wtc 2012/08/28 00:19:42 Should we also add a CHECK_NE(INVALID_SOCKET,
431 int rv = WSASendTo(socket_, &write_buffer, 1, &num, flags, 437 int rv = WSASendTo(socket_, &write_buffer, 1, &num, flags,
432 addr, storage.addr_len, &write_overlapped_, NULL); 438 addr, storage.addr_len, &write_overlapped_, NULL);
433 if (rv == 0) { 439 if (rv == 0) {
434 if (ResetEventIfSignaled(write_overlapped_.hEvent)) { 440 if (ResetEventIfSignaled(write_overlapped_.hEvent)) {
435 int result = num; 441 int result = num;
436 LogWrite(result, buf->data(), address); 442 LogWrite(result, buf->data(), address);
437 return result; 443 return result;
438 } 444 }
439 } else { 445 } else {
440 int os_error = WSAGetLastError(); 446 int os_error = WSAGetLastError();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return DoBind(IPEndPoint(ip, 0)); 496 return DoBind(IPEndPoint(ip, 0));
491 } 497 }
492 498
493 bool UDPSocketWin::ReceiveAddressToIPEndpoint(IPEndPoint* address) const { 499 bool UDPSocketWin::ReceiveAddressToIPEndpoint(IPEndPoint* address) const {
494 const struct sockaddr* addr = 500 const struct sockaddr* addr =
495 reinterpret_cast<const struct sockaddr*>(&recv_addr_storage_); 501 reinterpret_cast<const struct sockaddr*>(&recv_addr_storage_);
496 return address->FromSockAddr(addr, recv_addr_len_); 502 return address->FromSockAddr(addr, recv_addr_len_);
497 } 503 }
498 504
499 } // namespace net 505 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698