Commit 622b22b9 authored by Dominik Charousset's avatar Dominik Charousset

improved error messages in fd_util

parent 542ef61a
...@@ -60,9 +60,7 @@ void throw_io_failure(const char* what, bool add_errno_failure) { ...@@ -60,9 +60,7 @@ void throw_io_failure(const char* what, bool add_errno_failure) {
int rd_flags(native_socket_type fd) { int rd_flags(native_socket_type fd) {
auto flags = fcntl(fd, F_GETFL, 0); auto flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) { if (flags == -1) throw_io_failure("unable to read socket flags");
throw_io_failure("unable to read socket flags");
}
return flags; return flags;
} }
...@@ -94,22 +92,21 @@ void tcp_nodelay(native_socket_type fd, bool new_value) { ...@@ -94,22 +92,21 @@ void tcp_nodelay(native_socket_type fd, bool new_value) {
} }
} }
void handle_write_result(ssize_t result, bool is_nonblocking_io) { void handle_io_result(ssize_t res, bool is_nonblock, const char* msg) {
if (result < 0) { if (res < 0) {
if (is_nonblocking_io) { // don't throw for 'failed' non-blocking IO
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (is_nonblock && (errno == EAGAIN || errno == EWOULDBLOCK)) { }
return; // don't throw, just try again else throw_io_failure(msg);
}
}
throw_io_failure("cannot write to file descriptor");
} }
} }
void handle_read_result(ssize_t result, bool is_nonblocking_io) { void handle_write_result(ssize_t res, bool is_nonblock) {
handle_write_result(result, is_nonblocking_io); handle_io_result(res, is_nonblock, "cannot write to file descriptor");
if (result == 0) { }
throw_io_failure("cannot read from closed socket / file handle");
} void handle_read_result(ssize_t res, bool is_nonblock) {
handle_io_result(res, is_nonblock, "cannot read from file descriptor");
if (res == 0) throw_io_failure("cannot read from closed file descriptor");
} }
} } } // namespace cppa::detail::fd_util } } } // namespace cppa::detail::fd_util
......
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