Skip to content

Conversation

@Joannis
Copy link
Contributor

@Joannis Joannis commented Nov 3, 2025

This should enable NIOExtras to work on Windows, except for modules that depend on NIOSSL.

@Joannis Joannis marked this pull request as draft November 3, 2025 16:04
@Joannis Joannis marked this pull request as ready for review November 4, 2025 15:28
@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Nov 4, 2025
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks @Joannis.

@Lukasa Lukasa enabled auto-merge (squash) November 5, 2025 22:38
@Lukasa
Copy link
Contributor

Lukasa commented Nov 5, 2025

Looks like there are format tweaks that need to happen.

@Joannis
Copy link
Contributor Author

Joannis commented Nov 6, 2025

@Lukasa I tried swift format -r -i ., but the invocation results in many more changes than my PR touches.

@Lukasa
Copy link
Contributor

Lukasa commented Nov 7, 2025

It would probably be enough to apply this diff:

diff --git a/Package.swift b/Package.swift
index 0707fe6..7d6d0dd 100644
--- a/Package.swift
+++ b/Package.swift
@@ -111,7 +111,7 @@ var targets: [PackageDescription.Target] = [
         name: "CNIOExtrasZlib",
         dependencies: [],
         cSettings: [
-            .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
+            .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
         ],
         linkerSettings: [
             .linkedLibrary("z", .when(platforms: [.linux, .macOS, .iOS, .tvOS, .watchOS, .visionOS])),
diff --git a/Sources/HTTPServerWithQuiescingDemo/main.swift b/Sources/HTTPServerWithQuiescingDemo/main.swift
index 41c1458..a84ba37 100644
--- a/Sources/HTTPServerWithQuiescingDemo/main.swift
+++ b/Sources/HTTPServerWithQuiescingDemo/main.swift
@@ -136,4 +136,4 @@ private func runServer() throws {
 try runServer()
 #else
 print("This demo is not supported on Windows.")
-#endif
\ No newline at end of file
+#endif
diff --git a/Sources/NIOExtras/WritePCAPHandler.swift b/Sources/NIOExtras/WritePCAPHandler.swift
index 2e02cac..23c9978 100644
--- a/Sources/NIOExtras/WritePCAPHandler.swift
+++ b/Sources/NIOExtras/WritePCAPHandler.swift
@@ -26,21 +26,21 @@ import Android
 import ucrt
 import WinSDK
 
-fileprivate func gettimeofday(_ tp: inout timeval, _ tzp: Never?) {
+private func gettimeofday(_ tp: inout timeval, _ tzp: Never?) {
     var file_time = FILETIME()
     var system_time = SYSTEMTIME()
     var time: UInt64 = 0
 
     // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
-    // until 00:00:00 January 1, 1970 
-    let epoch: UInt64 = 116444736000000000
+    // until 00:00:00 January 1, 1970
+    let epoch: UInt64 = 116_444_736_000_000_000
 
-    GetSystemTime(&system_time);
-    SystemTimeToFileTime(&system_time, &file_time);
-    time =  UInt64(file_time.dwLowDateTime)
+    GetSystemTime(&system_time)
+    SystemTimeToFileTime(&system_time, &file_time)
+    time = UInt64(file_time.dwLowDateTime)
     time += UInt64(file_time.dwHighDateTime) << 32
 
-    tp.tv_sec = Int32((time - epoch) / 10000000)
+    tp.tv_sec = Int32((time - epoch) / 10_000_000)
     tp.tv_usec = Int32(system_time.wMilliseconds * 1000)
 }
 #else
@@ -752,7 +752,14 @@ extension NIOWritePCAPHandler {
         ) throws -> SynchronizedFileSink {
             #if os(Windows)
             let fd = try path.withCString(encodedAs: UTF16.self) { pathPtr -> CInt in
-                let fd = _wsopen_s(nil, pathPtr, _O_WRONLY | (fileWritingMode == FileWritingMode.createNewPCAPFile ? (_O_TRUNC | _O_CREAT) : _O_APPEND), _SH_DENYNO, _S_IREAD | _S_IWRITE)
+                let fd = _wsopen_s(
+                    nil,
+                    pathPtr,
+                    _O_WRONLY
+                        | (fileWritingMode == FileWritingMode.createNewPCAPFile ? (_O_TRUNC | _O_CREAT) : _O_APPEND),
+                    _SH_DENYNO,
+                    _S_IREAD | _S_IWRITE
+                )
                 guard fd >= 0 else {
                     throw SynchronizedFileSink.Error(errorCode: Error.ErrorCode.cannotOpenFileError.rawValue)
                 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants