File indexing completed on 2024-06-23 05:14:19

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     utils/wsastarter.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include <config-kleopatra.h>
0011 
0012 #include "wsastarter.h"
0013 
0014 using namespace Kleo;
0015 
0016 #ifdef _WIN32
0017 #include <winsock2.h>
0018 #else
0019 using WSADATA = int;
0020 static inline int WSAStartup(int, int *)
0021 {
0022     return 0;
0023 }
0024 static inline void WSACleanup()
0025 {
0026 }
0027 #endif
0028 
0029 static int startWSA()
0030 {
0031     WSADATA dummy;
0032     return WSAStartup(0x202, &dummy);
0033 }
0034 
0035 WSAStarter::WSAStarter()
0036     : startupError(startWSA())
0037 {
0038 }
0039 
0040 WSAStarter::~WSAStarter()
0041 {
0042     if (!startupError) {
0043         WSACleanup();
0044     }
0045 }