2 * Copyright 2014 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.
19 #include <folly/io/async/DelayedDestruction.h>
23 class AsyncSocketException : public std::runtime_error {
25 enum AsyncSocketExceptionType
39 , SASL_HANDSHAKE_TIMEOUT = 14
43 AsyncSocketExceptionType type, const std::string& message) :
44 std::runtime_error(message),
45 type_(type), errno_(0) {}
48 AsyncSocketExceptionType type_;
50 /** A copy of the errno. */
53 AsyncSocketException(AsyncSocketExceptionType type,
54 const std::string& message,
56 std::runtime_error(getMessage(message, errno_copy)),
57 type_(type), errno_(errno_copy) {}
59 AsyncSocketExceptionType getType() const noexcept { return type_; }
60 int getErrno() const noexcept { return errno_; }
63 /** Just like strerror_r but returns a C++ string object. */
64 std::string strerror_s(int errno_copy) {
65 return "errno = " + folly::to<std::string>(errno_copy);
68 /** Return a message based on the input. */
69 std::string getMessage(const std::string &message,
71 if (errno_copy != 0) {
72 return message + ": " + strerror_s(errno_copy);