Commit ee9e2381 authored by Max Kellermann's avatar Max Kellermann

system/SocketError: un-inline constructor

Reduces header dependencies.
parent 29030b54
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include <glib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
......
...@@ -21,4 +21,26 @@ ...@@ -21,4 +21,26 @@
#include "SocketError.hxx" #include "SocketError.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include <glib.h>
const Domain socket_domain("socket"); const Domain socket_domain("socket");
#ifdef WIN32
SocketErrorMessage::SocketErrorMessage(socket_error_t code)
{
DWORD nbytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, code, 0,
(LPSTR)msg, sizeof(msg), NULL);
if (nbytes == 0)
strcpy(msg, "Unknown error");
}
#else
SocketErrorMessage::SocketErrorMessage(socket_error_t code)
:msg(g_strerror(code)) {}
#endif
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#include "gcc.h" #include "gcc.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include <glib.h>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
typedef DWORD socket_error_t; typedef DWORD socket_error_t;
...@@ -97,18 +95,9 @@ class SocketErrorMessage { ...@@ -97,18 +95,9 @@ class SocketErrorMessage {
public: public:
#ifdef WIN32 #ifdef WIN32
explicit SocketErrorMessage(socket_error_t code=GetSocketError()) { explicit SocketErrorMessage(socket_error_t code=GetSocketError());
DWORD nbytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, code, 0,
(LPSTR)msg, sizeof(msg), NULL);
if (nbytes == 0)
strcpy(msg, "Unknown error");
}
#else #else
explicit SocketErrorMessage(socket_error_t code=GetSocketError()) explicit SocketErrorMessage(socket_error_t code=GetSocketError());
:msg(g_strerror(code)) {}
#endif #endif
operator const char *() const { operator const char *() const {
......
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