Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
WinSock.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#if qStroika_Foundation_Common_Platform_Windows
7#include <winsock2.h>
8
9#include <ws2tcpip.h>
10#else
11#error "WINDOWS REQUIRED FOR THIS MODULE"
12#endif
13
14#include "Stroika/Foundation/Execution/Platform/Windows/Exception.h"
15
16#include "WinSock.h"
17
18using namespace Stroika::Foundation;
19using namespace Stroika::Foundation::IO;
21using namespace Stroika::Foundation::IO::Network::Platform;
22using namespace Stroika::Foundation::IO::Network::Platform::Windows;
23
24// Not sure why this is necessary, but we get link errors sometimes without it... Maybe a windows makefile issue on regtest apps?
25// -- LGP 2014-11-06
26#pragma comment(lib, "Ws2_32.lib")
27
28/*
29 ********************************************************************************
30 ******************* Network::Platform::Windows::WinSock ************************
31 ********************************************************************************
32 */
33bool WinSock::sStarted_{false};
34
35void WinSock::ForceStartup ()
36{
37 Require (not sStarted_);
38 WSADATA wsaData; // Initialize Winsock
39 int iResult = ::WSAStartup (MAKEWORD (2, 2), &wsaData);
40 if (iResult != 0) {
41 Execution::ThrowSystemErrNo (::WSAGetLastError ());
42 }
43 sStarted_ = true;
44}