net_errors_win.cc 4.9 KB

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