Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame^] | 1 | // Copyright 2011 The Chromium Authors |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 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 | |
[email protected] | 33c6d3f1 | 2011-09-04 00:00:54 | [diff] [blame] | 13 | // Map winsock and system errors to Chromium errors. |
pkasting | 32c74152 | 2014-11-26 01:03:56 | [diff] [blame] | 14 | Error MapSystemError(logging::SystemErrorCode os_error) { |
[email protected] | 210564f | 2011-09-23 20:38:20 | [diff] [blame] | 15 | if (os_error != 0) |
| 16 | DVLOG(2) << "Error " << os_error; |
| 17 | |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 18 | // There are numerous Winsock error codes, but these are the ones we thus far |
| 19 | // find interesting. |
| 20 | switch (os_error) { |
[email protected] | 60b707e2 | 2011-04-04 22:21:22 | [diff] [blame] | 21 | case WSAEWOULDBLOCK: |
[email protected] | bfb88ec | 2013-02-27 20:21:35 | [diff] [blame] | 22 | case WSA_IO_PENDING: |
[email protected] | 60b707e2 | 2011-04-04 22:21:22 | [diff] [blame] | 23 | return ERR_IO_PENDING; |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 24 | case WSAEACCES: |
| 25 | return ERR_ACCESS_DENIED; |
| 26 | case WSAENETDOWN: |
| 27 | return ERR_INTERNET_DISCONNECTED; |
| 28 | case WSAETIMEDOUT: |
| 29 | return ERR_TIMED_OUT; |
| 30 | case WSAECONNRESET: |
| 31 | case WSAENETRESET: // Related to keep-alive |
| 32 | return ERR_CONNECTION_RESET; |
| 33 | case WSAECONNABORTED: |
| 34 | return ERR_CONNECTION_ABORTED; |
| 35 | case WSAECONNREFUSED: |
| 36 | return ERR_CONNECTION_REFUSED; |
| 37 | case WSA_IO_INCOMPLETE: |
| 38 | case WSAEDISCON: |
| 39 | return ERR_CONNECTION_CLOSED; |
[email protected] | bd2e375 | 2013-05-01 21:18:07 | [diff] [blame] | 40 | case WSAEISCONN: |
| 41 | return ERR_SOCKET_IS_CONNECTED; |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 42 | case WSAEHOSTUNREACH: |
| 43 | case WSAENETUNREACH: |
| 44 | return ERR_ADDRESS_UNREACHABLE; |
| 45 | case WSAEADDRNOTAVAIL: |
| 46 | return ERR_ADDRESS_INVALID; |
[email protected] | d539beae | 2011-06-20 17:29:56 | [diff] [blame] | 47 | case WSAEMSGSIZE: |
| 48 | return ERR_MSG_TOO_BIG; |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 49 | case WSAENOTCONN: |
| 50 | return ERR_SOCKET_NOT_CONNECTED; |
| 51 | case WSAEAFNOSUPPORT: |
| 52 | return ERR_ADDRESS_UNREACHABLE; |
[email protected] | 03ec2538 | 2011-05-27 21:50:28 | [diff] [blame] | 53 | case WSAEINVAL: |
| 54 | return ERR_INVALID_ARGUMENT; |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 55 | case WSAEADDRINUSE: |
| 56 | return ERR_ADDRESS_IN_USE; |
[email protected] | 33c6d3f1 | 2011-09-04 00:00:54 | [diff] [blame] | 57 | |
| 58 | // System errors. |
| 59 | case ERROR_FILE_NOT_FOUND: // The system cannot find the file specified. |
| 60 | return ERR_FILE_NOT_FOUND; |
| 61 | case ERROR_PATH_NOT_FOUND: // The system cannot find the path specified. |
| 62 | return ERR_FILE_NOT_FOUND; |
| 63 | case ERROR_TOO_MANY_OPEN_FILES: // The system cannot open the file. |
| 64 | return ERR_INSUFFICIENT_RESOURCES; |
| 65 | case ERROR_ACCESS_DENIED: // Access is denied. |
| 66 | return ERR_ACCESS_DENIED; |
| 67 | case ERROR_INVALID_HANDLE: // The handle is invalid. |
| 68 | return ERR_INVALID_HANDLE; |
| 69 | case ERROR_NOT_ENOUGH_MEMORY: // Not enough storage is available to |
| 70 | return ERR_OUT_OF_MEMORY; // process this command. |
| 71 | case ERROR_OUTOFMEMORY: // Not enough storage is available to complete |
| 72 | return ERR_OUT_OF_MEMORY; // this operation. |
| 73 | case ERROR_WRITE_PROTECT: // The media is write protected. |
| 74 | return ERR_ACCESS_DENIED; |
| 75 | case ERROR_SHARING_VIOLATION: // Cannot access the file because it is |
| 76 | return ERR_ACCESS_DENIED; // being used by another process. |
| 77 | case ERROR_LOCK_VIOLATION: // The process cannot access the file because |
| 78 | return ERR_ACCESS_DENIED; // another process has locked the file. |
| 79 | case ERROR_HANDLE_EOF: // Reached the end of the file. |
| 80 | return ERR_FAILED; |
| 81 | case ERROR_HANDLE_DISK_FULL: // The disk is full. |
| 82 | return ERR_FILE_NO_SPACE; |
| 83 | case ERROR_FILE_EXISTS: // The file exists. |
| 84 | return ERR_FILE_EXISTS; |
| 85 | case ERROR_INVALID_PARAMETER: // The parameter is incorrect. |
| 86 | return ERR_INVALID_ARGUMENT; |
| 87 | case ERROR_BUFFER_OVERFLOW: // The file name is too long. |
| 88 | return ERR_FILE_PATH_TOO_LONG; |
| 89 | case ERROR_DISK_FULL: // There is not enough space on the disk. |
| 90 | return ERR_FILE_NO_SPACE; |
| 91 | case ERROR_CALL_NOT_IMPLEMENTED: // This function is not supported on |
| 92 | return ERR_NOT_IMPLEMENTED; // this system. |
| 93 | case ERROR_INVALID_NAME: // The filename, directory name, or volume |
| 94 | return ERR_INVALID_ARGUMENT; // label syntax is incorrect. |
| 95 | case ERROR_DIR_NOT_EMPTY: // The directory is not empty. |
| 96 | return ERR_FAILED; |
| 97 | case ERROR_BUSY: // The requested resource is in use. |
| 98 | return ERR_ACCESS_DENIED; |
| 99 | case ERROR_ALREADY_EXISTS: // Cannot create a file when that file |
| 100 | return ERR_FILE_EXISTS; // already exists. |
| 101 | case ERROR_FILENAME_EXCED_RANGE: // The filename or extension is too long. |
| 102 | return ERR_FILE_PATH_TOO_LONG; |
| 103 | case ERROR_FILE_TOO_LARGE: // The file size exceeds the limit allowed |
| 104 | return ERR_FILE_NO_SPACE; // and cannot be saved. |
| 105 | case ERROR_VIRUS_INFECTED: // Operation failed because the file |
| 106 | return ERR_FILE_VIRUS_INFECTED; // contains a virus. |
| 107 | case ERROR_IO_DEVICE: // The request could not be performed |
| 108 | return ERR_ACCESS_DENIED; // because of an I/O device error. |
| 109 | case ERROR_POSSIBLE_DEADLOCK: // A potential deadlock condition has |
| 110 | return ERR_ACCESS_DENIED; // been detected. |
| 111 | case ERROR_BAD_DEVICE: // The specified device name is invalid. |
| 112 | return ERR_INVALID_ARGUMENT; |
[email protected] | 573902f | 2013-09-26 09:31:24 | [diff] [blame] | 113 | case ERROR_BROKEN_PIPE: // Pipe is not connected. |
| 114 | return ERR_CONNECTION_RESET; |
[email protected] | 33c6d3f1 | 2011-09-04 00:00:54 | [diff] [blame] | 115 | |
[email protected] | 051e4ec | 2011-03-15 20:46:32 | [diff] [blame] | 116 | case ERROR_SUCCESS: |
| 117 | return OK; |
| 118 | default: |
| 119 | LOG(WARNING) << "Unknown error " << os_error |
| 120 | << " mapped to net::ERR_FAILED"; |
| 121 | return ERR_FAILED; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | } // namespace net |