1 // Copyright (C) 2016 John Biddiscombe 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See 4 // accompanying file LICENSE_1_0.txt or copy at 5 6 #ifndef HPX_PARCELSET_POLICIES_VERBS_RDMA_ERROR_HPP 7 #define HPX_PARCELSET_POLICIES_VERBS_RDMA_ERROR_HPP 8 9 #include <plugins/parcelport/parcelport_logging.hpp> 10 // 11 #include <stdexcept> 12 #include <string> 13 #include <string.h> 14 15 namespace hpx { 16 namespace parcelset { 17 namespace policies { 18 namespace verbs { 19 20 class rdma_error : public std::runtime_error 21 { 22 public: 23 // -------------------------------------------------------------------- rdma_error(int err,const std::string & msg)24 rdma_error(int err, const std::string &msg) 25 : std::runtime_error(msg), 26 error_(err) 27 { 28 LOG_ERROR_MSG(msg << " : " << error_string(err)); 29 } 30 rdma_error(int err)31 rdma_error(int err) 32 : std::runtime_error(error_string(err)), 33 error_(err) 34 { 35 LOG_ERROR_MSG(what()); 36 } 37 38 // -------------------------------------------------------------------- error_code() const39 int error_code() const { return error_; } 40 41 // -------------------------------------------------------------------- error_string(int err)42 static inline char *error_string(int err) 43 { 44 char buffer[256]; 45 #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE 46 return strerror_r(err, buffer, sizeof(buf)) ? nullptr : buffer; 47 #else 48 return strerror_r(err, buffer, 256); 49 #endif 50 } 51 52 int error_; 53 }; 54 55 }}}} 56 57 #endif 58 59