Commit c39c2eae authored by Joseph Noir's avatar Joseph Noir

Add function to generate string from socket err

parent 41547a86
......@@ -79,6 +79,9 @@ bool would_block_or_temporarily_unavailable(int errcode);
/// Returns the last socket error as human-readable string.
std::string last_socket_error_as_string();
/// Returns a human-readable string for a given socket error.
std::string socket_error_as_string(int errcode);
/// Creates two connected sockets. The former is the read handle
/// and the latter is the write handle.
std::pair<native_socket, native_socket> create_pipe();
......
......@@ -125,6 +125,11 @@ namespace network {
return strerror(errno);
}
string socket_error_as_string(int errcode) {
return strerror(errcode);
}
expected<void> child_process_inherit(native_socket fd, bool new_value) {
CAF_LOG_TRACE(CAF_ARG(fd) << CAF_ARG(new_value));
// read flags for fd
......@@ -187,9 +192,12 @@ namespace network {
}
string last_socket_error_as_string() {
return socket_error_as_string(last_socket_error());
}
string socket_error_as_string(int errcode) {
LPTSTR errorText = NULL;
auto hresult = last_socket_error();
FormatMessage( // use system message tables to retrieve error text
FormatMessage(// use system message tables to retrieve error text
FORMAT_MESSAGE_FROM_SYSTEM
// allocate buffer on local heap for error text
| FORMAT_MESSAGE_ALLOCATE_BUFFER
......@@ -197,7 +205,7 @@ namespace network {
// (and CANNOT) pass insertion parameters
| FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, // unused with FORMAT_MESSAGE_FROM_SYSTEM
hresult, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) & errorText, // output
0, // minimum size for output buffer
nullptr); // arguments - see note
......
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