You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
485 B
C++
29 lines
485 B
C++
// SPDX-License-Identifier: BSD-2-Clause
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
|
|
|
#pragma once
|
|
|
|
#ifdef _WIN32
|
|
#include "SocketError.hxx"
|
|
#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();
|
|
}
|
|
#else
|
|
public:
|
|
ScopeNetInit() {}
|
|
#endif
|
|
};
|