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

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

Issue 8889036: Revert 113699 - base::Bind: Convert Socket::Write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 | « net/socket/tcp_client_socket_win.h ('k') | net/socket/transport_client_socket_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Deleted: svn:mergeinfo
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_client_socket_win.h" 5 #include "net/socket/tcp_client_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/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 TCPClientSocketWin::TCPClientSocketWin(const AddressList& addresses, 311 TCPClientSocketWin::TCPClientSocketWin(const AddressList& addresses,
312 net::NetLog* net_log, 312 net::NetLog* net_log,
313 const net::NetLog::Source& source) 313 const net::NetLog::Source& source)
314 : socket_(INVALID_SOCKET), 314 : socket_(INVALID_SOCKET),
315 bound_socket_(INVALID_SOCKET), 315 bound_socket_(INVALID_SOCKET),
316 addresses_(addresses), 316 addresses_(addresses),
317 current_ai_(NULL), 317 current_ai_(NULL),
318 waiting_read_(false), 318 waiting_read_(false),
319 waiting_write_(false), 319 waiting_write_(false),
320 old_read_callback_(NULL), 320 old_read_callback_(NULL),
321 old_write_callback_(NULL), 321 write_callback_(NULL),
322 next_connect_state_(CONNECT_STATE_NONE), 322 next_connect_state_(CONNECT_STATE_NONE),
323 connect_os_error_(0), 323 connect_os_error_(0),
324 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), 324 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)),
325 previously_disconnected_(false), 325 previously_disconnected_(false),
326 num_bytes_read_(0) { 326 num_bytes_read_(0) {
327 scoped_refptr<NetLog::EventParameters> params; 327 scoped_refptr<NetLog::EventParameters> params;
328 if (source.is_valid()) 328 if (source.is_valid())
329 params = new NetLogSourceParameter("source_dependency", source); 329 params = new NetLogSourceParameter("source_dependency", source);
330 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params); 330 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, params);
331 EnsureWinsockInit(); 331 EnsureWinsockInit();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 core_->read_iobuffer_ = buf; 785 core_->read_iobuffer_ = buf;
786 return ERR_IO_PENDING; 786 return ERR_IO_PENDING;
787 } 787 }
788 788
789 int TCPClientSocketWin::Write(IOBuffer* buf, 789 int TCPClientSocketWin::Write(IOBuffer* buf,
790 int buf_len, 790 int buf_len,
791 OldCompletionCallback* callback) { 791 OldCompletionCallback* callback) {
792 DCHECK(CalledOnValidThread()); 792 DCHECK(CalledOnValidThread());
793 DCHECK_NE(socket_, INVALID_SOCKET); 793 DCHECK_NE(socket_, INVALID_SOCKET);
794 DCHECK(!waiting_write_); 794 DCHECK(!waiting_write_);
795 DCHECK(!old_write_callback_ && write_callback_.is_null()); 795 DCHECK(!write_callback_);
796 DCHECK_GT(buf_len, 0); 796 DCHECK_GT(buf_len, 0);
797 DCHECK(!core_->write_iobuffer_); 797 DCHECK(!core_->write_iobuffer_);
798 798
799 base::StatsCounter writes("tcp.writes"); 799 base::StatsCounter writes("tcp.writes");
800 writes.Increment(); 800 writes.Increment();
801 801
802 core_->write_buffer_.len = buf_len; 802 core_->write_buffer_.len = buf_len;
803 core_->write_buffer_.buf = buf->data(); 803 core_->write_buffer_.buf = buf->data();
804 core_->write_buffer_length_ = buf_len; 804 core_->write_buffer_length_ = buf_len;
805 805
(...skipping 20 matching lines...) Expand all
826 core_->write_buffer_.buf); 826 core_->write_buffer_.buf);
827 return rv; 827 return rv;
828 } 828 }
829 } else { 829 } else {
830 int os_error = WSAGetLastError(); 830 int os_error = WSAGetLastError();
831 if (os_error != WSA_IO_PENDING) 831 if (os_error != WSA_IO_PENDING)
832 return MapSystemError(os_error); 832 return MapSystemError(os_error);
833 } 833 }
834 core_->WatchForWrite(); 834 core_->WatchForWrite();
835 waiting_write_ = true; 835 waiting_write_ = true;
836 old_write_callback_ = callback;
837 core_->write_iobuffer_ = buf;
838 return ERR_IO_PENDING;
839 }
840 int TCPClientSocketWin::Write(IOBuffer* buf,
841 int buf_len,
842 const CompletionCallback& callback) {
843 DCHECK(CalledOnValidThread());
844 DCHECK_NE(socket_, INVALID_SOCKET);
845 DCHECK(!waiting_write_);
846 DCHECK(!old_write_callback_ && write_callback_.is_null());
847 DCHECK_GT(buf_len, 0);
848 DCHECK(!core_->write_iobuffer_);
849
850 base::StatsCounter writes("tcp.writes");
851 writes.Increment();
852
853 core_->write_buffer_.len = buf_len;
854 core_->write_buffer_.buf = buf->data();
855 core_->write_buffer_length_ = buf_len;
856
857 // TODO(wtc): Remove the assertion after enough testing.
858 AssertEventNotSignaled(core_->write_overlapped_.hEvent);
859 DWORD num;
860 int rv = WSASend(socket_, &core_->write_buffer_, 1, &num, 0,
861 &core_->write_overlapped_, NULL);
862 if (rv == 0) {
863 if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) {
864 rv = static_cast<int>(num);
865 if (rv > buf_len || rv < 0) {
866 // It seems that some winsock interceptors report that more was written
867 // than was available. Treat this as an error. http://crbug.com/27870
868 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len
869 << " bytes, but " << rv << " bytes reported.";
870 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES;
871 }
872 base::StatsCounter write_bytes("tcp.write_bytes");
873 write_bytes.Add(rv);
874 if (rv > 0)
875 use_history_.set_was_used_to_convey_data();
876 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv,
877 core_->write_buffer_.buf);
878 return rv;
879 }
880 } else {
881 int os_error = WSAGetLastError();
882 if (os_error != WSA_IO_PENDING)
883 return MapSystemError(os_error);
884 }
885 core_->WatchForWrite();
886 waiting_write_ = true;
887 write_callback_ = callback; 836 write_callback_ = callback;
888 core_->write_iobuffer_ = buf; 837 core_->write_iobuffer_ = buf;
889 return ERR_IO_PENDING; 838 return ERR_IO_PENDING;
890 } 839 }
891 840
892 bool TCPClientSocketWin::SetReceiveBufferSize(int32 size) { 841 bool TCPClientSocketWin::SetReceiveBufferSize(int32 size) {
893 DCHECK(CalledOnValidThread()); 842 DCHECK(CalledOnValidThread());
894 return SetSocketReceiveBufferSize(socket_, size); 843 return SetSocketReceiveBufferSize(socket_, size);
895 } 844 }
896 845
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 c->Run(rv); 890 c->Run(rv);
942 } else { 891 } else {
943 CompletionCallback c = read_callback_; 892 CompletionCallback c = read_callback_;
944 read_callback_.Reset(); 893 read_callback_.Reset();
945 c.Run(rv); 894 c.Run(rv);
946 } 895 }
947 } 896 }
948 897
949 void TCPClientSocketWin::DoWriteCallback(int rv) { 898 void TCPClientSocketWin::DoWriteCallback(int rv) {
950 DCHECK_NE(rv, ERR_IO_PENDING); 899 DCHECK_NE(rv, ERR_IO_PENDING);
951 DCHECK(old_write_callback_ || !write_callback_.is_null()); 900 DCHECK(write_callback_);
952 901
953 // Since Run may result in Write being called, clear old_write_callback_ up 902 // since Run may result in Write being called, clear write_callback_ up front.
954 // front. 903 OldCompletionCallback* c = write_callback_;
955 if (old_write_callback_) { 904 write_callback_ = NULL;
956 OldCompletionCallback* c = old_write_callback_; 905 c->Run(rv);
957 old_write_callback_ = NULL;
958 c->Run(rv);
959 } else {
960 CompletionCallback c = write_callback_;
961 write_callback_.Reset();
962 c.Run(rv);
963 }
964 } 906 }
965 907
966 void TCPClientSocketWin::DidCompleteConnect() { 908 void TCPClientSocketWin::DidCompleteConnect() {
967 DCHECK_EQ(next_connect_state_, CONNECT_STATE_CONNECT_COMPLETE); 909 DCHECK_EQ(next_connect_state_, CONNECT_STATE_CONNECT_COMPLETE);
968 int result; 910 int result;
969 911
970 WSANETWORKEVENTS events; 912 WSANETWORKEVENTS events;
971 int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, 913 int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent,
972 &events); 914 &events);
973 int os_error = 0; 915 int os_error = 0;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 use_history_.set_was_used_to_convey_data(); 980 use_history_.set_was_used_to_convey_data();
1039 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, 981 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes,
1040 core_->write_buffer_.buf); 982 core_->write_buffer_.buf);
1041 } 983 }
1042 } 984 }
1043 core_->write_iobuffer_ = NULL; 985 core_->write_iobuffer_ = NULL;
1044 DoWriteCallback(rv); 986 DoWriteCallback(rv);
1045 } 987 }
1046 988
1047 } // namespace net 989 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_win.h ('k') | net/socket/transport_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698