Main: move WinSock initialization to class ScopeNetInit
This commit is contained in:
parent
666e456551
commit
5b80711d75
@ -497,6 +497,7 @@ libthread_a_SOURCES = \
|
|||||||
|
|
||||||
libnet_a_SOURCES = \
|
libnet_a_SOURCES = \
|
||||||
src/net/Features.hxx \
|
src/net/Features.hxx \
|
||||||
|
src/net/Init.hxx \
|
||||||
src/net/ToString.cxx src/net/ToString.hxx \
|
src/net/ToString.cxx src/net/ToString.hxx \
|
||||||
src/net/Resolver.cxx src/net/Resolver.hxx \
|
src/net/Resolver.cxx src/net/Resolver.hxx \
|
||||||
src/net/StaticSocketAddress.cxx src/net/StaticSocketAddress.hxx \
|
src/net/StaticSocketAddress.cxx src/net/StaticSocketAddress.hxx \
|
||||||
|
32
src/Main.cxx
32
src/Main.cxx
@ -50,6 +50,7 @@
|
|||||||
#include "unix/SignalHandlers.hxx"
|
#include "unix/SignalHandlers.hxx"
|
||||||
#include "system/FatalError.hxx"
|
#include "system/FatalError.hxx"
|
||||||
#include "thread/Slack.hxx"
|
#include "thread/Slack.hxx"
|
||||||
|
#include "net/Init.hxx"
|
||||||
#include "lib/icu/Init.hxx"
|
#include "lib/icu/Init.hxx"
|
||||||
#include "config/ConfigGlobal.hxx"
|
#include "config/ConfigGlobal.hxx"
|
||||||
#include "config/Param.hxx"
|
#include "config/Param.hxx"
|
||||||
@ -106,11 +107,6 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __BLOCKS__
|
#ifdef __BLOCKS__
|
||||||
#include <dispatch/dispatch.h>
|
#include <dispatch/dispatch.h>
|
||||||
#endif
|
#endif
|
||||||
@ -284,25 +280,6 @@ glue_state_file_init()
|
|||||||
instance->state_file->Read();
|
instance->state_file->Read();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Windows-only initialization of the Winsock2 library.
|
|
||||||
*/
|
|
||||||
static void winsock_init(void)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSADATA sockinfo;
|
|
||||||
|
|
||||||
int retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
|
|
||||||
if(retval != 0)
|
|
||||||
FormatFatalError("Attempt to open Winsock2 failed; error code %d",
|
|
||||||
retval);
|
|
||||||
|
|
||||||
if (LOBYTE(sockinfo.wVersion) != 2)
|
|
||||||
FatalError("We use Winsock2 but your version is either too new "
|
|
||||||
"or old; please install Winsock 2.x");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the decoder and player core, including the music pipe.
|
* Initialize the decoder and player core, including the music pipe.
|
||||||
*/
|
*/
|
||||||
@ -451,7 +428,8 @@ try {
|
|||||||
|
|
||||||
IcuInit();
|
IcuInit();
|
||||||
|
|
||||||
winsock_init();
|
const ScopeNetInit net_init;
|
||||||
|
|
||||||
io_thread_init();
|
io_thread_init();
|
||||||
config_global_init();
|
config_global_init();
|
||||||
|
|
||||||
@ -702,10 +680,6 @@ try {
|
|||||||
daemonize_finish();
|
daemonize_finish();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
WSACleanup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IcuFinish();
|
IcuFinish();
|
||||||
|
|
||||||
log_deinit();
|
log_deinit();
|
||||||
|
46
src/net/Init.hxx
Normal file
46
src/net/Init.hxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2017 The Music Player Daemon Project
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NET_INIT_HXX
|
||||||
|
#define NET_INIT_HXX
|
||||||
|
|
||||||
|
#include "check.h"
|
||||||
|
#include "SocketError.hxx"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class ScopeNetInit {
|
||||||
|
#ifdef _WIN32
|
||||||
|
public:
|
||||||
|
ScopeNetInit() {
|
||||||
|
WSADATA sockinfo;
|
||||||
|
int retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
|
||||||
|
if (retval != 0)
|
||||||
|
throw MakeSocketError(retval, "WSAStartup() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
~ScopeNetInit() noexcept {
|
||||||
|
WSACleanup();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user