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

Side by Side Diff: net/socket/tcp_socket_win.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Fixed a straggling, old enum and applied static_cast<int> to the new netlog enum types, since this … Created 4 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
« no previous file with comments | « net/socket/tcp_socket_win.h ('k') | net/socket/transport_client_socket_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tcp_socket.h" 5 #include "net/socket/tcp_socket.h"
6 #include "net/socket/tcp_socket_win.h" 6 #include "net/socket/tcp_socket_win.h"
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <mstcpip.h> 9 #include <mstcpip.h>
10 10
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
18 #include "net/base/address_list.h" 18 #include "net/base/address_list.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/ip_endpoint.h" 20 #include "net/base/ip_endpoint.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "net/base/network_activity_monitor.h" 22 #include "net/base/network_activity_monitor.h"
23 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
24 #include "net/base/sockaddr_storage.h" 24 #include "net/base/sockaddr_storage.h"
25 #include "net/base/winsock_init.h" 25 #include "net/base/winsock_init.h"
26 #include "net/base/winsock_util.h" 26 #include "net/base/winsock_util.h"
27 #include "net/log/net_log_event_type.h"
28 #include "net/log/net_log_source_type.h"
27 #include "net/socket/socket_descriptor.h" 29 #include "net/socket/socket_descriptor.h"
28 #include "net/socket/socket_net_log_params.h" 30 #include "net/socket/socket_net_log_params.h"
29 31
30 namespace net { 32 namespace net {
31 33
32 namespace { 34 namespace {
33 35
34 const int kTCPKeepAliveSeconds = 45; 36 const int kTCPKeepAliveSeconds = 45;
35 37
36 int SetSocketReceiveBufferSize(SOCKET socket, int32_t size) { 38 int SetSocketReceiveBufferSize(SOCKET socket, int32_t size) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 : socket_(INVALID_SOCKET), 250 : socket_(INVALID_SOCKET),
249 socket_performance_watcher_(std::move(socket_performance_watcher)), 251 socket_performance_watcher_(std::move(socket_performance_watcher)),
250 accept_event_(WSA_INVALID_EVENT), 252 accept_event_(WSA_INVALID_EVENT),
251 accept_socket_(NULL), 253 accept_socket_(NULL),
252 accept_address_(NULL), 254 accept_address_(NULL),
253 waiting_connect_(false), 255 waiting_connect_(false),
254 waiting_read_(false), 256 waiting_read_(false),
255 waiting_write_(false), 257 waiting_write_(false),
256 connect_os_error_(0), 258 connect_os_error_(0),
257 logging_multiple_connect_attempts_(false), 259 logging_multiple_connect_attempts_(false),
258 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { 260 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)) {
259 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, 261 net_log_.BeginEvent(NetLogEventType::SOCKET_ALIVE,
260 source.ToEventParametersCallback()); 262 source.ToEventParametersCallback());
261 EnsureWinsockInit(); 263 EnsureWinsockInit();
262 } 264 }
263 265
264 TCPSocketWin::~TCPSocketWin() { 266 TCPSocketWin::~TCPSocketWin() {
265 Close(); 267 Close();
266 net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE); 268 net_log_.EndEvent(NetLogEventType::SOCKET_ALIVE);
267 } 269 }
268 270
269 int TCPSocketWin::Open(AddressFamily family) { 271 int TCPSocketWin::Open(AddressFamily family) {
270 DCHECK(CalledOnValidThread()); 272 DCHECK(CalledOnValidThread());
271 DCHECK_EQ(socket_, INVALID_SOCKET); 273 DCHECK_EQ(socket_, INVALID_SOCKET);
272 274
273 socket_ = CreatePlatformSocket(ConvertAddressFamily(family), SOCK_STREAM, 275 socket_ = CreatePlatformSocket(ConvertAddressFamily(family), SOCK_STREAM,
274 IPPROTO_TCP); 276 IPPROTO_TCP);
275 if (socket_ == INVALID_SOCKET) { 277 if (socket_ == INVALID_SOCKET) {
276 PLOG(ERROR) << "CreatePlatformSocket() returned an error"; 278 PLOG(ERROR) << "CreatePlatformSocket() returned an error";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 366
365 int TCPSocketWin::Accept(std::unique_ptr<TCPSocketWin>* socket, 367 int TCPSocketWin::Accept(std::unique_ptr<TCPSocketWin>* socket,
366 IPEndPoint* address, 368 IPEndPoint* address,
367 const CompletionCallback& callback) { 369 const CompletionCallback& callback) {
368 DCHECK(CalledOnValidThread()); 370 DCHECK(CalledOnValidThread());
369 DCHECK(socket); 371 DCHECK(socket);
370 DCHECK(address); 372 DCHECK(address);
371 DCHECK(!callback.is_null()); 373 DCHECK(!callback.is_null());
372 DCHECK(accept_callback_.is_null()); 374 DCHECK(accept_callback_.is_null());
373 375
374 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT); 376 net_log_.BeginEvent(NetLogEventType::TCP_ACCEPT);
375 377
376 int result = AcceptInternal(socket, address); 378 int result = AcceptInternal(socket, address);
377 379
378 if (result == ERR_IO_PENDING) { 380 if (result == ERR_IO_PENDING) {
379 // Start watching. 381 // Start watching.
380 WSAEventSelect(socket_, accept_event_, FD_ACCEPT); 382 WSAEventSelect(socket_, accept_event_, FD_ACCEPT);
381 accept_watcher_.StartWatchingOnce(accept_event_, this); 383 accept_watcher_.StartWatchingOnce(accept_event_, this);
382 384
383 accept_socket_ = socket; 385 accept_socket_ = socket;
384 accept_address_ = address; 386 accept_address_ = address;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (rv == 0) { 499 if (rv == 0) {
498 if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) { 500 if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) {
499 rv = static_cast<int>(num); 501 rv = static_cast<int>(num);
500 if (rv > buf_len || rv < 0) { 502 if (rv > buf_len || rv < 0) {
501 // It seems that some winsock interceptors report that more was written 503 // It seems that some winsock interceptors report that more was written
502 // than was available. Treat this as an error. http://crbug.com/27870 504 // than was available. Treat this as an error. http://crbug.com/27870
503 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len 505 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len
504 << " bytes, but " << rv << " bytes reported."; 506 << " bytes, but " << rv << " bytes reported.";
505 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; 507 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES;
506 } 508 }
507 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, 509 net_log_.AddByteTransferEvent(NetLogEventType::SOCKET_BYTES_SENT, rv,
508 buf->data()); 510 buf->data());
509 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(rv); 511 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(rv);
510 return rv; 512 return rv;
511 } 513 }
512 } else { 514 } else {
513 int os_error = WSAGetLastError(); 515 int os_error = WSAGetLastError();
514 if (os_error != WSA_IO_PENDING) { 516 if (os_error != WSA_IO_PENDING) {
515 int net_error = MapSystemError(os_error); 517 int net_error = MapSystemError(os_error);
516 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, 518 net_log_.AddEvent(NetLogEventType::SOCKET_WRITE_ERROR,
517 CreateNetLogSocketErrorCallback(net_error, os_error)); 519 CreateNetLogSocketErrorCallback(net_error, os_error));
518 return net_error; 520 return net_error;
519 } 521 }
520 } 522 }
521 waiting_write_ = true; 523 waiting_write_ = true;
522 write_callback_ = callback; 524 write_callback_ = callback;
523 core_->write_iobuffer_ = buf; 525 core_->write_iobuffer_ = buf;
524 core_->write_buffer_length_ = buf_len; 526 core_->write_buffer_length_ = buf_len;
525 core_->WatchForWrite(); 527 core_->WatchForWrite();
526 return ERR_IO_PENDING; 528 return ERR_IO_PENDING;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 601
600 bool TCPSocketWin::SetNoDelay(bool no_delay) { 602 bool TCPSocketWin::SetNoDelay(bool no_delay) {
601 return SetTCPNoDelay(socket_, no_delay); 603 return SetTCPNoDelay(socket_, no_delay);
602 } 604 }
603 605
604 void TCPSocketWin::Close() { 606 void TCPSocketWin::Close() {
605 DCHECK(CalledOnValidThread()); 607 DCHECK(CalledOnValidThread());
606 608
607 if (socket_ != INVALID_SOCKET) { 609 if (socket_ != INVALID_SOCKET) {
608 // Only log the close event if there's actually a socket to close. 610 // Only log the close event if there's actually a socket to close.
609 net_log_.AddEvent(NetLog::EventType::TYPE_SOCKET_CLOSED); 611 net_log_.AddEvent(NetLogEventType::SOCKET_CLOSED);
610 612
611 // Note: don't use CancelIo to cancel pending IO because it doesn't work 613 // Note: don't use CancelIo to cancel pending IO because it doesn't work
612 // when there is a Winsock layered service provider. 614 // when there is a Winsock layered service provider.
613 615
614 // In most socket implementations, closing a socket results in a graceful 616 // In most socket implementations, closing a socket results in a graceful
615 // connection shutdown, but in Winsock we have to call shutdown explicitly. 617 // connection shutdown, but in Winsock we have to call shutdown explicitly.
616 // See the MSDN page "Graceful Shutdown, Linger Options, and Socket Closure" 618 // See the MSDN page "Graceful Shutdown, Linger Options, and Socket Closure"
617 // at http://msdn.microsoft.com/en-us/library/ms738547.aspx 619 // at http://msdn.microsoft.com/en-us/library/ms738547.aspx
618 shutdown(socket_, SD_SEND); 620 shutdown(socket_, SD_SEND);
619 621
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } 683 }
682 } 684 }
683 685
684 int TCPSocketWin::AcceptInternal(std::unique_ptr<TCPSocketWin>* socket, 686 int TCPSocketWin::AcceptInternal(std::unique_ptr<TCPSocketWin>* socket,
685 IPEndPoint* address) { 687 IPEndPoint* address) {
686 SockaddrStorage storage; 688 SockaddrStorage storage;
687 int new_socket = accept(socket_, storage.addr, &storage.addr_len); 689 int new_socket = accept(socket_, storage.addr, &storage.addr_len);
688 if (new_socket < 0) { 690 if (new_socket < 0) {
689 int net_error = MapSystemError(WSAGetLastError()); 691 int net_error = MapSystemError(WSAGetLastError());
690 if (net_error != ERR_IO_PENDING) 692 if (net_error != ERR_IO_PENDING)
691 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); 693 net_log_.EndEventWithNetErrorCode(
694 NetLogEventType::TCP_ACCEPT, net_error);
eroman 2016/09/08 05:26:45 This formatting looks strange. Did you run "git cl
mikecirone 2016/09/08 06:39:22 Ok, I just ran "git cl format". Patch set 5 shows
692 return net_error; 695 return net_error;
693 } 696 }
694 697
695 IPEndPoint ip_end_point; 698 IPEndPoint ip_end_point;
696 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) { 699 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) {
697 NOTREACHED(); 700 NOTREACHED();
698 if (closesocket(new_socket) < 0) 701 if (closesocket(new_socket) < 0)
699 PLOG(ERROR) << "closesocket"; 702 PLOG(ERROR) << "closesocket";
700 int net_error = ERR_ADDRESS_INVALID; 703 int net_error = ERR_ADDRESS_INVALID;
701 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); 704 net_log_.EndEventWithNetErrorCode(NetLogEventType::TCP_ACCEPT, net_error);
702 return net_error; 705 return net_error;
703 } 706 }
704 std::unique_ptr<TCPSocketWin> tcp_socket( 707 std::unique_ptr<TCPSocketWin> tcp_socket(
705 new TCPSocketWin(NULL, net_log_.net_log(), net_log_.source())); 708 new TCPSocketWin(NULL, net_log_.net_log(), net_log_.source()));
706 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point); 709 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point);
707 if (adopt_result != OK) { 710 if (adopt_result != OK) {
708 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result); 711 net_log_.EndEventWithNetErrorCode(
712 NetLogEventType::TCP_ACCEPT, adopt_result);
709 return adopt_result; 713 return adopt_result;
710 } 714 }
711 *socket = std::move(tcp_socket); 715 *socket = std::move(tcp_socket);
712 *address = ip_end_point; 716 *address = ip_end_point;
713 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, 717 net_log_.EndEvent(NetLogEventType::TCP_ACCEPT,
714 CreateNetLogIPEndPointCallback(&ip_end_point)); 718 CreateNetLogIPEndPointCallback(&ip_end_point));
715 return OK; 719 return OK;
716 } 720 }
717 721
718 void TCPSocketWin::OnObjectSignaled(HANDLE object) { 722 void TCPSocketWin::OnObjectSignaled(HANDLE object) {
719 WSANETWORKEVENTS ev; 723 WSANETWORKEVENTS ev;
720 if (WSAEnumNetworkEvents(socket_, accept_event_, &ev) == SOCKET_ERROR) { 724 if (WSAEnumNetworkEvents(socket_, accept_event_, &ev) == SOCKET_ERROR) {
721 PLOG(ERROR) << "WSAEnumNetworkEvents()"; 725 PLOG(ERROR) << "WSAEnumNetworkEvents()";
722 return; 726 return;
723 } 727 }
(...skipping 13 matching lines...) Expand all
737 // Start watching the next FD_ACCEPT event. 741 // Start watching the next FD_ACCEPT event.
738 WSAEventSelect(socket_, accept_event_, FD_ACCEPT); 742 WSAEventSelect(socket_, accept_event_, FD_ACCEPT);
739 accept_watcher_.StartWatchingOnce(accept_event_, this); 743 accept_watcher_.StartWatchingOnce(accept_event_, this);
740 } 744 }
741 } 745 }
742 746
743 int TCPSocketWin::DoConnect() { 747 int TCPSocketWin::DoConnect() {
744 DCHECK_EQ(connect_os_error_, 0); 748 DCHECK_EQ(connect_os_error_, 0);
745 DCHECK(!core_.get()); 749 DCHECK(!core_.get());
746 750
747 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, 751 net_log_.BeginEvent(NetLogEventType::TCP_CONNECT_ATTEMPT,
748 CreateNetLogIPEndPointCallback(peer_address_.get())); 752 CreateNetLogIPEndPointCallback(peer_address_.get()));
749 753
750 core_ = new Core(this); 754 core_ = new Core(this);
751 755
752 // WSAEventSelect sets the socket to non-blocking mode as a side effect. 756 // WSAEventSelect sets the socket to non-blocking mode as a side effect.
753 // Our connect() and recv() calls require that the socket be non-blocking. 757 // Our connect() and recv() calls require that the socket be non-blocking.
754 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); 758 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT);
755 759
756 SockaddrStorage storage; 760 SockaddrStorage storage;
757 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) 761 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len))
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 801
798 core_->WatchForRead(); 802 core_->WatchForRead();
799 return ERR_IO_PENDING; 803 return ERR_IO_PENDING;
800 } 804 }
801 805
802 void TCPSocketWin::DoConnectComplete(int result) { 806 void TCPSocketWin::DoConnectComplete(int result) {
803 // Log the end of this attempt (and any OS error it threw). 807 // Log the end of this attempt (and any OS error it threw).
804 int os_error = connect_os_error_; 808 int os_error = connect_os_error_;
805 connect_os_error_ = 0; 809 connect_os_error_ = 0;
806 if (result != OK) { 810 if (result != OK) {
807 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, 811 net_log_.EndEvent(NetLogEventType::TCP_CONNECT_ATTEMPT,
808 NetLog::IntCallback("os_error", os_error)); 812 NetLog::IntCallback("os_error", os_error));
809 } else { 813 } else {
810 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT); 814 net_log_.EndEvent(NetLogEventType::TCP_CONNECT_ATTEMPT);
811 } 815 }
812 816
813 if (!logging_multiple_connect_attempts_) 817 if (!logging_multiple_connect_attempts_)
814 LogConnectEnd(result); 818 LogConnectEnd(result);
815 } 819 }
816 820
817 void TCPSocketWin::LogConnectBegin(const AddressList& addresses) { 821 void TCPSocketWin::LogConnectBegin(const AddressList& addresses) {
818 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT, 822 net_log_.BeginEvent(NetLogEventType::TCP_CONNECT,
819 addresses.CreateNetLogCallback()); 823 addresses.CreateNetLogCallback());
820 } 824 }
821 825
822 void TCPSocketWin::LogConnectEnd(int net_error) { 826 void TCPSocketWin::LogConnectEnd(int net_error) {
823 if (net_error != OK) { 827 if (net_error != OK) {
824 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_CONNECT, net_error); 828 net_log_.EndEventWithNetErrorCode(NetLogEventType::TCP_CONNECT, net_error);
825 return; 829 return;
826 } 830 }
827 831
828 struct sockaddr_storage source_address; 832 struct sockaddr_storage source_address;
829 socklen_t addrlen = sizeof(source_address); 833 socklen_t addrlen = sizeof(source_address);
830 int rv = getsockname( 834 int rv = getsockname(
831 socket_, reinterpret_cast<struct sockaddr*>(&source_address), &addrlen); 835 socket_, reinterpret_cast<struct sockaddr*>(&source_address), &addrlen);
832 if (rv != 0) { 836 if (rv != 0) {
833 LOG(ERROR) << "getsockname() [rv: " << rv 837 LOG(ERROR) << "getsockname() [rv: " << rv
834 << "] error: " << WSAGetLastError(); 838 << "] error: " << WSAGetLastError();
835 NOTREACHED(); 839 NOTREACHED();
836 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_CONNECT, rv); 840 net_log_.EndEventWithNetErrorCode(NetLogEventType::TCP_CONNECT, rv);
837 return; 841 return;
838 } 842 }
839 843
840 net_log_.EndEvent( 844 net_log_.EndEvent(
841 NetLog::TYPE_TCP_CONNECT, 845 NetLogEventType::TCP_CONNECT,
842 CreateNetLogSourceAddressCallback( 846 CreateNetLogSourceAddressCallback(
843 reinterpret_cast<const struct sockaddr*>(&source_address), 847 reinterpret_cast<const struct sockaddr*>(&source_address),
844 sizeof(source_address))); 848 sizeof(source_address)));
845 } 849 }
846 850
847 int TCPSocketWin::DoRead(IOBuffer* buf, int buf_len, 851 int TCPSocketWin::DoRead(IOBuffer* buf, int buf_len,
848 const CompletionCallback& callback) { 852 const CompletionCallback& callback) {
849 if (!core_->non_blocking_reads_initialized_) { 853 if (!core_->non_blocking_reads_initialized_) {
850 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, 854 WSAEventSelect(socket_, core_->read_overlapped_.hEvent,
851 FD_READ | FD_CLOSE); 855 FD_READ | FD_CLOSE);
852 core_->non_blocking_reads_initialized_ = true; 856 core_->non_blocking_reads_initialized_ = true;
853 } 857 }
854 int rv = recv(socket_, buf->data(), buf_len, 0); 858 int rv = recv(socket_, buf->data(), buf_len, 0);
855 if (rv == SOCKET_ERROR) { 859 if (rv == SOCKET_ERROR) {
856 int os_error = WSAGetLastError(); 860 int os_error = WSAGetLastError();
857 if (os_error != WSAEWOULDBLOCK) { 861 if (os_error != WSAEWOULDBLOCK) {
858 int net_error = MapSystemError(os_error); 862 int net_error = MapSystemError(os_error);
859 net_log_.AddEvent( 863 net_log_.AddEvent(
860 NetLog::TYPE_SOCKET_READ_ERROR, 864 NetLogEventType::SOCKET_READ_ERROR,
861 CreateNetLogSocketErrorCallback(net_error, os_error)); 865 CreateNetLogSocketErrorCallback(net_error, os_error));
862 return net_error; 866 return net_error;
863 } 867 }
864 } else { 868 } else {
865 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, 869 net_log_.AddByteTransferEvent(NetLogEventType::SOCKET_BYTES_RECEIVED, rv,
866 buf->data()); 870 buf->data());
867 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(rv); 871 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(rv);
868 return rv; 872 return rv;
869 } 873 }
870 874
871 waiting_read_ = true; 875 waiting_read_ = true;
872 read_callback_ = callback; 876 read_callback_ = callback;
873 core_->read_iobuffer_ = buf; 877 core_->read_iobuffer_ = buf;
874 core_->read_buffer_length_ = buf_len; 878 core_->read_buffer_length_ = buf_len;
875 core_->WatchForRead(); 879 core_->WatchForRead();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 926
923 DWORD num_bytes, flags; 927 DWORD num_bytes, flags;
924 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, 928 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_,
925 &num_bytes, FALSE, &flags); 929 &num_bytes, FALSE, &flags);
926 WSAResetEvent(core_->write_overlapped_.hEvent); 930 WSAResetEvent(core_->write_overlapped_.hEvent);
927 waiting_write_ = false; 931 waiting_write_ = false;
928 int rv; 932 int rv;
929 if (!ok) { 933 if (!ok) {
930 int os_error = WSAGetLastError(); 934 int os_error = WSAGetLastError();
931 rv = MapSystemError(os_error); 935 rv = MapSystemError(os_error);
932 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, 936 net_log_.AddEvent(NetLogEventType::SOCKET_WRITE_ERROR,
933 CreateNetLogSocketErrorCallback(rv, os_error)); 937 CreateNetLogSocketErrorCallback(rv, os_error));
934 } else { 938 } else {
935 rv = static_cast<int>(num_bytes); 939 rv = static_cast<int>(num_bytes);
936 if (rv > core_->write_buffer_length_ || rv < 0) { 940 if (rv > core_->write_buffer_length_ || rv < 0) {
937 // It seems that some winsock interceptors report that more was written 941 // It seems that some winsock interceptors report that more was written
938 // than was available. Treat this as an error. http://crbug.com/27870 942 // than was available. Treat this as an error. http://crbug.com/27870
939 LOG(ERROR) << "Detected broken LSP: Asked to write " 943 LOG(ERROR) << "Detected broken LSP: Asked to write "
940 << core_->write_buffer_length_ << " bytes, but " << rv 944 << core_->write_buffer_length_ << " bytes, but " << rv
941 << " bytes reported."; 945 << " bytes reported.";
942 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; 946 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES;
943 } else { 947 } else {
944 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, 948 net_log_.AddByteTransferEvent(
945 core_->write_iobuffer_->data()); 949 NetLogEventType::SOCKET_BYTES_SENT, num_bytes,
950 core_->write_iobuffer_->data());
946 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(num_bytes); 951 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(num_bytes);
947 } 952 }
948 } 953 }
949 954
950 core_->write_iobuffer_ = NULL; 955 core_->write_iobuffer_ = NULL;
951 956
952 DCHECK_NE(rv, ERR_IO_PENDING); 957 DCHECK_NE(rv, ERR_IO_PENDING);
953 base::ResetAndReturn(&write_callback_).Run(rv); 958 base::ResetAndReturn(&write_callback_).Run(rv);
954 } 959 }
955 960
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 } 1010 }
1006 1011
1007 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { 1012 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const {
1008 DCHECK(out_rtt); 1013 DCHECK(out_rtt);
1009 // TODO(bmcquade): Consider implementing using 1014 // TODO(bmcquade): Consider implementing using
1010 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. 1015 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats.
1011 return false; 1016 return false;
1012 } 1017 }
1013 1018
1014 } // namespace net 1019 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_socket_win.h ('k') | net/socket/transport_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698