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.
5 #include "net/base/net_errors.h"
9 #include "base/logging.h"
13 // Map winsock and system errors to Chromium errors.
14 Error
MapSystemError(logging::SystemErrorCode os_error
) {
16 DVLOG(2) << "Error " << os_error
;
18 // There are numerous Winsock error codes, but these are the ones we thus far
23 return ERR_IO_PENDING
;
25 return ERR_ACCESS_DENIED
;
27 return ERR_INTERNET_DISCONNECTED
;
31 case WSAENETRESET
: // Related to keep-alive
32 return ERR_CONNECTION_RESET
;
34 return ERR_CONNECTION_ABORTED
;
36 return ERR_CONNECTION_REFUSED
;
37 case WSA_IO_INCOMPLETE
:
39 return ERR_CONNECTION_CLOSED
;
41 return ERR_SOCKET_IS_CONNECTED
;
44 return ERR_ADDRESS_UNREACHABLE
;
45 case WSAEADDRNOTAVAIL
:
46 return ERR_ADDRESS_INVALID
;
48 return ERR_MSG_TOO_BIG
;
50 return ERR_SOCKET_NOT_CONNECTED
;
52 return ERR_ADDRESS_UNREACHABLE
;
54 return ERR_INVALID_ARGUMENT
;
56 return ERR_ADDRESS_IN_USE
;
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.
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.
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
;
113 case ERROR_BROKEN_PIPE
: // Pipe is not connected.
114 return ERR_CONNECTION_RESET
;
119 LOG(WARNING
) << "Unknown error " << os_error
120 << " mapped to net::ERR_FAILED";