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

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

Issue 185553013: Standardize error reporting of IPEndPoint::ToSockAddr and (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 9 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
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_win.h" 5 #include "net/socket/tcp_socket_win.h"
6 6
7 #include <mstcpip.h> 7 #include <mstcpip.h>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 if (net_error != ERR_IO_PENDING) 704 if (net_error != ERR_IO_PENDING)
705 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error); 705 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error);
706 return net_error; 706 return net_error;
707 } 707 }
708 708
709 IPEndPoint ip_end_point; 709 IPEndPoint ip_end_point;
710 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) { 710 if (!ip_end_point.FromSockAddr(storage.addr, storage.addr_len)) {
711 NOTREACHED(); 711 NOTREACHED();
712 if (closesocket(new_socket) < 0) 712 if (closesocket(new_socket) < 0)
713 PLOG(ERROR) << "closesocket"; 713 PLOG(ERROR) << "closesocket";
714 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, ERR_FAILED); 714 int net_error = ERR_ADDRESS_INVALID;
715 return ERR_FAILED; 715 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, net_error);
716 return net_error;
716 } 717 }
717 scoped_ptr<TCPSocketWin> tcp_socket(new TCPSocketWin( 718 scoped_ptr<TCPSocketWin> tcp_socket(new TCPSocketWin(
718 net_log_.net_log(), net_log_.source())); 719 net_log_.net_log(), net_log_.source()));
719 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point); 720 int adopt_result = tcp_socket->AdoptConnectedSocket(new_socket, ip_end_point);
720 if (adopt_result != OK) { 721 if (adopt_result != OK) {
721 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result); 722 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, adopt_result);
722 return adopt_result; 723 return adopt_result;
723 } 724 }
724 *socket = tcp_socket.Pass(); 725 *socket = tcp_socket.Pass();
725 *address = ip_end_point; 726 *address = ip_end_point;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, 761 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT,
761 CreateNetLogIPEndPointCallback(peer_address_.get())); 762 CreateNetLogIPEndPointCallback(peer_address_.get()));
762 763
763 core_ = new Core(this); 764 core_ = new Core(this);
764 // WSAEventSelect sets the socket to non-blocking mode as a side effect. 765 // WSAEventSelect sets the socket to non-blocking mode as a side effect.
765 // Our connect() and recv() calls require that the socket be non-blocking. 766 // Our connect() and recv() calls require that the socket be non-blocking.
766 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT); 767 WSAEventSelect(socket_, core_->read_overlapped_.hEvent, FD_CONNECT);
767 768
768 SockaddrStorage storage; 769 SockaddrStorage storage;
769 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len)) 770 if (!peer_address_->ToSockAddr(storage.addr, &storage.addr_len))
770 return ERR_INVALID_ARGUMENT; 771 return ERR_ADDRESS_INVALID;
771 if (!connect(socket_, storage.addr, storage.addr_len)) { 772 if (!connect(socket_, storage.addr, storage.addr_len)) {
772 // Connected without waiting! 773 // Connected without waiting!
773 // 774 //
774 // The MSDN page for connect says: 775 // The MSDN page for connect says:
775 // With a nonblocking socket, the connection attempt cannot be completed 776 // With a nonblocking socket, the connection attempt cannot be completed
776 // immediately. In this case, connect will return SOCKET_ERROR, and 777 // immediately. In this case, connect will return SOCKET_ERROR, and
777 // WSAGetLastError will return WSAEWOULDBLOCK. 778 // WSAGetLastError will return WSAEWOULDBLOCK.
778 // which implies that for a nonblocking socket, connect never returns 0. 779 // which implies that for a nonblocking socket, connect never returns 0.
779 // It's not documented whether the event object will be signaled or not 780 // It's not documented whether the event object will be signaled or not
780 // if connect does return 0. So the code below is essentially dead code 781 // if connect does return 0. So the code below is essentially dead code
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 waiting_read_ = false; 992 waiting_read_ = false;
992 core_->read_iobuffer_ = NULL; 993 core_->read_iobuffer_ = NULL;
993 core_->read_buffer_length_ = 0; 994 core_->read_buffer_length_ = 0;
994 995
995 DCHECK_NE(rv, ERR_IO_PENDING); 996 DCHECK_NE(rv, ERR_IO_PENDING);
996 base::ResetAndReturn(&read_callback_).Run(rv); 997 base::ResetAndReturn(&read_callback_).Run(rv);
997 } 998 }
998 999
999 } // namespace net 1000 } // namespace net
1000 1001
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698