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

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

Issue 159904: Add a new net::Error value: ERR_CONNECTION_TIMED_OUT. (Closed)
Patch Set: Use MapConnectError() for asynchronous case too. Created 11 years, 4 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_client_socket_libevent.cc ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory_debug.h" 9 #include "base/memory_debug.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 case WSA_IO_INCOMPLETE: 69 case WSA_IO_INCOMPLETE:
70 return ERR_UNEXPECTED; 70 return ERR_UNEXPECTED;
71 case ERROR_SUCCESS: 71 case ERROR_SUCCESS:
72 return OK; 72 return OK;
73 default: 73 default:
74 LOG(WARNING) << "Unknown error " << err << " mapped to net::ERR_FAILED"; 74 LOG(WARNING) << "Unknown error " << err << " mapped to net::ERR_FAILED";
75 return ERR_FAILED; 75 return ERR_FAILED;
76 } 76 }
77 } 77 }
78 78
79 int MapConnectError(DWORD err) {
80 switch (err) {
81 case WSAETIMEDOUT:
82 return ERR_CONNECTION_TIMED_OUT;
83 default:
84 return MapWinsockError(err);
85 }
86 }
87
79 } // namespace 88 } // namespace
80 89
81 //----------------------------------------------------------------------------- 90 //-----------------------------------------------------------------------------
82 91
83 // This class encapsulates all the state that has to be preserved as long as 92 // This class encapsulates all the state that has to be preserved as long as
84 // there is a network IO operation in progress. If the owner TCPClientSocketWin 93 // there is a network IO operation in progress. If the owner TCPClientSocketWin
85 // is destroyed while an operation is in progress, the Core is detached and it 94 // is destroyed while an operation is in progress, the Core is detached and it
86 // lives until the operation completes and the OS doesn't reference any resource 95 // lives until the operation completes and the OS doesn't reference any resource
87 // declared on this class anymore. 96 // declared on this class anymore.
88 class TCPClientSocketWin::Core : public base::RefCounted<Core> { 97 class TCPClientSocketWin::Core : public base::RefCounted<Core> {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 NOTREACHED(); 272 NOTREACHED();
264 273
265 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) { 274 if (ResetEventIfSignaled(core_->read_overlapped_.hEvent)) {
266 TRACE_EVENT_END("socket.connect", this, ""); 275 TRACE_EVENT_END("socket.connect", this, "");
267 return OK; 276 return OK;
268 } 277 }
269 } else { 278 } else {
270 DWORD err = WSAGetLastError(); 279 DWORD err = WSAGetLastError();
271 if (err != WSAEWOULDBLOCK) { 280 if (err != WSAEWOULDBLOCK) {
272 LOG(ERROR) << "connect failed: " << err; 281 LOG(ERROR) << "connect failed: " << err;
273 return MapWinsockError(err); 282 return MapConnectError(err);
274 } 283 }
275 } 284 }
276 285
277 core_->WatchForRead(); 286 core_->WatchForRead();
278 waiting_connect_ = true; 287 waiting_connect_ = true;
279 read_callback_ = callback; 288 read_callback_ = callback;
280 return ERR_IO_PENDING; 289 return ERR_IO_PENDING;
281 } 290 }
282 291
283 void TCPClientSocketWin::Disconnect() { 292 void TCPClientSocketWin::Disconnect() {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 error_code == WSAECONNREFUSED || 541 error_code == WSAECONNREFUSED ||
533 error_code == WSAENETUNREACH || 542 error_code == WSAENETUNREACH ||
534 error_code == WSAEHOSTUNREACH || 543 error_code == WSAEHOSTUNREACH ||
535 error_code == WSAETIMEDOUT)) { 544 error_code == WSAETIMEDOUT)) {
536 // Try using the next address. 545 // Try using the next address.
537 const struct addrinfo* next = current_ai_->ai_next; 546 const struct addrinfo* next = current_ai_->ai_next;
538 Disconnect(); 547 Disconnect();
539 current_ai_ = next; 548 current_ai_ = next;
540 result = Connect(read_callback_); 549 result = Connect(read_callback_);
541 } else { 550 } else {
542 result = MapWinsockError(error_code); 551 result = MapConnectError(error_code);
543 } 552 }
544 } else { 553 } else {
545 NOTREACHED(); 554 NOTREACHED();
546 result = ERR_UNEXPECTED; 555 result = ERR_UNEXPECTED;
547 } 556 }
548 557
549 if (result != ERR_IO_PENDING) 558 if (result != ERR_IO_PENDING)
550 DoReadCallback(result); 559 DoReadCallback(result);
551 } 560 }
552 561
(...skipping 16 matching lines...) Expand all
569 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, 578 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_,
570 &num_bytes, FALSE, &flags); 579 &num_bytes, FALSE, &flags);
571 WSAResetEvent(core_->write_overlapped_.hEvent); 580 WSAResetEvent(core_->write_overlapped_.hEvent);
572 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", num_bytes)); 581 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", num_bytes));
573 waiting_write_ = false; 582 waiting_write_ = false;
574 core_->write_iobuffer_ = NULL; 583 core_->write_iobuffer_ = NULL;
575 DoWriteCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError())); 584 DoWriteCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError()));
576 } 585 }
577 586
578 } // namespace net 587 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_libevent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698