Files
swift-nio/Sources/CNIOWindows/WSAStartup.c
T
Saleem Abdulrasool c141d91338 CNIOWindows: preprocess away WinSock support code (#1639)
This preprocesses away the WinSock2 support code when on non-Windows
targets.
2020-09-21 17:23:03 +01:00

36 lines
878 B
C

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if defined(_WIN32)
#include <Winsock2.h>
#include <stdlib.h>
#pragma section(".CRT$XCU", read)
static void __cdecl
NIOWSAStartup(void) {
WSADATA wsa;
WORD wVersionRequested = MAKEWORD(2, 2);
if (!WSAStartup(wVersionRequested, &wsa)) {
_exit(EXIT_FAILURE);
}
}
__declspec(allocate(".CRT$XCU"))
static void (*pNIOWSAStartup)(void) = &NIOWSAStartup;
#endif