Commit ae663f84 authored by Dominik Charousset's avatar Dominik Charousset

changed throw_io_failure to use ostringstream

this patch re-implements throw_io_failure to take a const char* and
use a string stream to build error message, fixes #73
parent 9b8ed31d
...@@ -39,7 +39,7 @@ namespace cppa { namespace detail { namespace fd_util { ...@@ -39,7 +39,7 @@ namespace cppa { namespace detail { namespace fd_util {
#if defined(CPPA_MACOS) || defined(CPPA_LINUX) #if defined(CPPA_MACOS) || defined(CPPA_LINUX)
// throws ios_base::failure and adds errno failure if @p add_errno_failure // throws ios_base::failure and adds errno failure if @p add_errno_failure
void throw_io_failure(std::string&& what, bool add_errno_failure = true); void throw_io_failure(const char* what, bool add_errno_failure = true);
// returns true if fd is nonblocking // returns true if fd is nonblocking
// throws @p ios_base::failure on error // throws @p ios_base::failure on error
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <ios> #include <ios>
#include <sstream>
#include "cppa/exception.hpp" #include "cppa/exception.hpp"
#include "cppa/detail/fd_util.hpp" #include "cppa/detail/fd_util.hpp"
...@@ -36,27 +38,24 @@ ...@@ -36,27 +38,24 @@
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
#include <fcntl.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <fcntl.h>
namespace cppa { namespace detail { namespace fd_util { namespace cppa { namespace detail { namespace fd_util {
void throw_io_failure(std::string&& what, bool add_errno_failure) { void throw_io_failure(const char* what, bool add_errno_failure) {
if (add_errno_failure) { if (add_errno_failure) {
std::string tmp(std::move(what)); std::ostringstream oss;
tmp += ": "; oss << what << ": " << strerror(errno)
tmp += strerror(errno); << " [errno: " << std::to_string(errno) << "]";
tmp += " [errno: "; throw std::ios_base::failure(oss.str());
tmp += std::to_string(errno);
tmp += "]";
throw std::ios_base::failure(std::move(tmp));
} }
throw std::ios_base::failure(std::move(what)); throw std::ios_base::failure(what);
} }
int rd_flags(native_socket_type fd) { int rd_flags(native_socket_type fd) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment