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/net_errors.h" 6 7 #include <winsock2.h> 8 9 #include "base/logging.h" 10 11 namespace net { 12 13 // Map winsock error to Chromium error. 14 Error MapSystemError(int os_error) { 15 // There are numerous Winsock error codes, but these are the ones we thus far 16 // find interesting. 17 switch (os_error) { 18 case WSAEWOULDBLOCK: 19 return ERR_IO_PENDING; 20 case WSAEACCES: 21 return ERR_ACCESS_DENIED; 22 case WSAENETDOWN: 23 return ERR_INTERNET_DISCONNECTED; 24 case WSAETIMEDOUT: 25 return ERR_TIMED_OUT; 26 case WSAECONNRESET: 27 case WSAENETRESET: // Related to keep-alive 28 return ERR_CONNECTION_RESET; 29 case WSAECONNABORTED: 30 return ERR_CONNECTION_ABORTED; 31 case WSAECONNREFUSED: 32 return ERR_CONNECTION_REFUSED; 33 case WSA_IO_INCOMPLETE: 34 case WSAEDISCON: 35 return ERR_CONNECTION_CLOSED; 36 case WSAEHOSTUNREACH: 37 case WSAENETUNREACH: 38 return ERR_ADDRESS_UNREACHABLE; 39 case WSAEADDRNOTAVAIL: 40 return ERR_ADDRESS_INVALID; 41 case WSAENOTCONN: 42 return ERR_SOCKET_NOT_CONNECTED; 43 case WSAEAFNOSUPPORT: 44 return ERR_ADDRESS_UNREACHABLE; 45 case ERROR_SUCCESS: 46 return OK; 47 default: 48 LOG(WARNING) << "Unknown error " << os_error 49 << " mapped to net::ERR_FAILED"; 50 return ERR_FAILED; 51 } 52 } 53 54 } // namespace net 55