AsyncSocketException.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2017-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <folly/io/async/AsyncSocketException.h>
  17. #include <folly/Format.h>
  18. #include <folly/String.h>
  19. namespace folly {
  20. /* static */ StringPiece AsyncSocketException::getExceptionTypeString(
  21. AsyncSocketExceptionType type) {
  22. switch (type) {
  23. case UNKNOWN:
  24. return "Unknown async socket exception";
  25. case NOT_OPEN:
  26. return "Socket not open";
  27. case ALREADY_OPEN:
  28. return "Socket already open";
  29. case TIMED_OUT:
  30. return "Timed out";
  31. case END_OF_FILE:
  32. return "End of file";
  33. case INTERRUPTED:
  34. return "Interrupted";
  35. case BAD_ARGS:
  36. return "Invalid arguments";
  37. case CORRUPTED_DATA:
  38. return "Corrupted Data";
  39. case INTERNAL_ERROR:
  40. return "Internal error";
  41. case NOT_SUPPORTED:
  42. return "Not supported";
  43. case INVALID_STATE:
  44. return "Invalid state";
  45. case SSL_ERROR:
  46. return "SSL error";
  47. case COULD_NOT_BIND:
  48. return "Could not bind";
  49. case SASL_HANDSHAKE_TIMEOUT:
  50. return "SASL handshake timeout";
  51. case NETWORK_ERROR:
  52. return "Network error";
  53. case EARLY_DATA_REJECTED:
  54. return "Early data rejected";
  55. default:
  56. return "(Invalid exception type)";
  57. }
  58. }
  59. /* static */ std::string AsyncSocketException::getMessage(
  60. AsyncSocketExceptionType type,
  61. const std::string& message,
  62. int errnoCopy) {
  63. if (errnoCopy != 0) {
  64. return sformat(
  65. "AsyncSocketException: {}, type = {}, errno = {} ({})",
  66. message,
  67. getExceptionTypeString(type),
  68. errnoCopy,
  69. errnoStr(errnoCopy));
  70. } else {
  71. return sformat(
  72. "AsyncSocketException: {}, type = {}",
  73. message,
  74. getExceptionTypeString(type));
  75. }
  76. }
  77. } // namespace folly