Skip to content

Commit 17218cd

Browse files
committed
Foundation: initialize CFSocket on startup
Windows requires the networking subsystem (WinSock) to be initialized. However, the user expects to be able to use the networking APIs in Foundation without performing any one-time initialization. Furthermore, due to the macro usage in the initialization path, it is easier to perform the initialization in C than in Swift. CoreFoundation has a SPI for this (`__CFSocketInitializeWinSock`).
1 parent 8e587b8 commit 17218cd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Foundation/NSSwiftRuntime.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,18 @@ internal func __CFSwiftGetBaseClass() -> UnsafeRawPointer {
147147
return unsafeBitCast(__NSCFType.self, to:UnsafeRawPointer.self)
148148
}
149149

150+
#if os(Windows)
151+
@_silgen_name("__CFSocketInitializeWinSock")
152+
func __CFSocketInitializeWinSock() -> ()
153+
#endif
154+
150155
@usableFromInline
151156
@_cdecl("__CFInitializeSwift")
152157
internal func __CFInitializeSwift() {
153-
158+
#if os(Windows)
159+
__CFSocketInitializeWinSock()
160+
#endif
161+
154162
_CFRuntimeBridgeTypeToClass(CFStringGetTypeID(), unsafeBitCast(_NSCFString.self, to: UnsafeRawPointer.self))
155163
_CFRuntimeBridgeTypeToClass(CFArrayGetTypeID(), unsafeBitCast(_NSCFArray.self, to: UnsafeRawPointer.self))
156164
_CFRuntimeBridgeTypeToClass(CFDictionaryGetTypeID(), unsafeBitCast(_NSCFDictionary.self, to: UnsafeRawPointer.self))

0 commit comments

Comments
 (0)