2013-01-30 21:33:52 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2013-01-30 21:33:52 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "SocketError.hxx"
|
2015-02-25 16:01:46 +01:00
|
|
|
#include "util/Macros.hxx"
|
2013-01-30 21:33:52 +01:00
|
|
|
|
2013-12-15 18:30:25 +01:00
|
|
|
#include <string.h>
|
2013-09-04 23:36:30 +02:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
2017-05-08 14:44:49 +02:00
|
|
|
SocketErrorMessage::SocketErrorMessage(socket_error_t code) noexcept
|
2013-09-04 23:36:30 +02:00
|
|
|
{
|
2015-02-25 16:01:46 +01:00
|
|
|
#ifdef _UNICODE
|
|
|
|
wchar_t buffer[ARRAY_SIZE(msg)];
|
|
|
|
#else
|
|
|
|
auto *buffer = msg;
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 23:36:30 +02:00
|
|
|
DWORD nbytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS |
|
|
|
|
FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
2015-02-25 16:01:46 +01:00
|
|
|
nullptr, code, 0,
|
|
|
|
buffer, ARRAY_SIZE(msg), nullptr);
|
|
|
|
if (nbytes == 0) {
|
2013-09-04 23:36:30 +02:00
|
|
|
strcpy(msg, "Unknown error");
|
2015-02-25 16:01:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _UNICODE
|
|
|
|
auto length = WideCharToMultiByte(CP_UTF8, 0, buffer, -1,
|
|
|
|
msg, ARRAY_SIZE(msg),
|
|
|
|
nullptr, nullptr);
|
|
|
|
if (length <= 0) {
|
|
|
|
strcpy(msg, "WideCharToMultiByte() error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-04 23:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-05-08 14:44:49 +02:00
|
|
|
SocketErrorMessage::SocketErrorMessage(socket_error_t code) noexcept
|
2013-12-15 18:30:25 +01:00
|
|
|
:msg(strerror(code)) {}
|
2013-09-04 23:36:30 +02:00
|
|
|
|
|
|
|
#endif
|