2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "folly/io/async/AsyncSocketException.h"
19 #include <folly/Format.h>
20 #include <folly/String.h>
24 /* static */ StringPiece AsyncSocketException::getExceptionTypeString(
25 AsyncSocketExceptionType type) {
28 return "Unknown async socket exception";
30 return "Socket not open";
32 return "Socket already open";
40 return "Invalid arguments";
42 return "Corrupted Data";
44 return "Internal error";
46 return "Not supported";
48 return "Invalid state";
52 return "Could not bind";
53 case SASL_HANDSHAKE_TIMEOUT:
54 return "SASL handshake timeout";
56 return "Network error";
57 case EARLY_DATA_REJECTED:
58 return "Early data rejected";
60 return "(Invalid exception type)";
64 /* static */ std::string AsyncSocketException::getMessage(
65 AsyncSocketExceptionType type,
66 const std::string& message,
70 "AsyncSocketException: {}, type = {}, errno = {} ({})",
72 getExceptionTypeString(type),
77 "AsyncSocketException: {}, type = {}",
79 getExceptionTypeString(type));