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

Side by Side Diff: net/base/winsock_util.cc

Issue 6658027: UDP sockets implementation for windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 9 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
« no previous file with comments | « net/base/winsock_util.h ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/base/winsock_util.h"
6
7 #include "base/logging.h"
8 #include "net/base/net_errors.h"
9
10 namespace net {
11
12 namespace {
13
14 // Prevent the compiler from optimizing away the arguments so they appear
15 // nicely on the stack in crash dumps.
16 #pragma warning (disable: 4748)
17 #pragma optimize( "", off )
18
19 // Pass the important values as function arguments so that they are available
20 // in crash dumps.
21 void CheckEventWait(WSAEVENT hEvent, DWORD wait_rv, DWORD expected) {
22 if (wait_rv != expected) {
23 DWORD err = ERROR_SUCCESS;
24 if (wait_rv == WAIT_FAILED)
25 err = GetLastError();
26 CHECK(false); // Crash.
27 }
28 }
29
30 #pragma optimize( "", on )
31 #pragma warning (default: 4748)
32
33 } // namespace
34
35 void AssertEventNotSignaled(WSAEVENT hEvent) {
36 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
37 CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT);
38 }
39
40 bool ResetEventIfSignaled(WSAEVENT hEvent) {
41 // TODO(wtc): Remove the CHECKs after enough testing.
42 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
43 if (wait_rv == WAIT_TIMEOUT)
44 return false; // The event object is not signaled.
45 CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0);
46 BOOL ok = WSAResetEvent(hEvent);
47 CHECK(ok);
48 return true;
49 }
50
51 // Map winsock error to Chromium error.
52 int MapWinsockError(int os_error) {
53 // There are numerous Winsock error codes, but these are the ones we thus far
54 // find interesting.
55 switch (os_error) {
56 case WSAEACCES:
57 return ERR_ACCESS_DENIED;
58 case WSAENETDOWN:
59 return ERR_INTERNET_DISCONNECTED;
60 case WSAETIMEDOUT:
61 return ERR_TIMED_OUT;
62 case WSAECONNRESET:
63 case WSAENETRESET: // Related to keep-alive
64 return ERR_CONNECTION_RESET;
65 case WSAECONNABORTED:
66 return ERR_CONNECTION_ABORTED;
67 case WSAECONNREFUSED:
68 return ERR_CONNECTION_REFUSED;
69 case WSA_IO_INCOMPLETE:
70 case WSAEDISCON:
71 // WSAEDISCON is returned by WSARecv or WSARecvFrom for message-oriented
72 // sockets (where a return value of zero means a zero-byte message) to
73 // indicate graceful connection shutdown. We should not ever see this
74 // error code for TCP sockets, which are byte stream oriented.
75 LOG(DFATAL) << "Unexpected error " << os_error
76 << " mapped to net::ERR_UNEXPECTED";
77 return ERR_UNEXPECTED;
78 case WSAEHOSTUNREACH:
79 case WSAENETUNREACH:
80 return ERR_ADDRESS_UNREACHABLE;
81 case WSAEADDRNOTAVAIL:
82 return ERR_ADDRESS_INVALID;
83 case WSAENOTCONN:
84 return ERR_SOCKET_NOT_CONNECTED;
85 case WSAEAFNOSUPPORT:
86 return ERR_ADDRESS_UNREACHABLE;
87 case ERROR_SUCCESS:
88 return OK;
89 default:
90 LOG(WARNING) << "Unknown error " << os_error
91 << " mapped to net::ERR_FAILED";
92 return ERR_FAILED;
93 }
94 }
95
96 } // namespace net
OLDNEW
« no previous file with comments | « net/base/winsock_util.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698