Skip to content

Add support for Windows#869

Open
Joannis wants to merge 3 commits into
mainfrom
jo/windows-support
Open

Add support for Windows#869
Joannis wants to merge 3 commits into
mainfrom
jo/windows-support

Conversation

@Joannis

@Joannis Joannis commented Nov 5, 2025

Copy link
Copy Markdown
Member
  • Lacks CI
  • Has an ugly shim + workaround for cookie timestamps (WIP, AI generated temporary placeholder right now)
  • Tests on Windows exit positively, but I don't think all the tests are running (toolchain bug?)

TODOs

I'm thinking of replacing timestamp parsing with Foundation for now, or at least writing an implementation in Swift. I wanted to check what folks prefer for now.

@brian-contio-ai

Copy link
Copy Markdown
  • 1 - would be nice to have support for Windows.

@Joannis
Joannis marked this pull request as ready for review July 20, 2026 11:17
Comment on lines +76 to +78
return (a=='M'&&b=='o'&&c=='n')||(a=='T'&&b=='u'&&c=='e')||(a=='W'&&b=='e'&&c=='d')||
(a=='T'&&b=='h'&&c=='u')||(a=='F'&&b=='r'&&c=='i')||(a=='S'&&b=='a'&&c=='t')||
(a=='S'&&b=='u'&&c=='n');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a little hard to parse without any whitespace. It'd probably benefit from having one day one per line.

.serverChannelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: 1)
#if !os(Windows)
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

formatting looks off here

// Check for valid weekday abbreviation (Mon..Sun)
// Expect exactly 3 ASCII letters.
if (!p) return 0;
char a = p[0], b = p[1], c = p[2];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We're potentially reading out of bounds here.

Comment on lines +127 to +133
int hh = parse_fixed2(pp); if (hh < 0) return 0;
if (!expect_char(pp, ':')) return 0;
int mm = parse_fixed2(pp); if (mm < 0) return 0;
if (!expect_char(pp, ':')) return 0;
int ss = parse_fixed2(pp); if (ss < 0) return 0;
if (hh > 23 || mm > 59 || ss > 60) return 0; // allow leap second 60
*h = hh; *m = mm; *s = ss;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you avoid multiple statements per line? It generally just makes readability worse.

server = try ServerBootstrap(group: group)
.serverChannelOption(ChannelOptions.socket(.init(SOL_SOCKET), .init(SO_REUSEADDR)), value: 1)
#if !os(Windows)
.serverChannelOption(ChannelOptions.socket(.init(SOL_SOCKET), .init(SO_REUSEADDR)), value: 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Formatting looks off here (and below)

#else
nonisolated(unsafe) private let posixLocale: UnsafeMutableRawPointer = {
// FIXME: This can be cleaner. But the Windows shim doesn't need a locale pointer
UnsafeMutableRawPointer(bitPattern: 0)!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This init is documented to return nil for a bitPattern of 0 so this is a crash in disguise. If the Windows shim doesn't need a locale pointer, can we just remove this branch entirely and update the caller?

return timestamp == -1 && errno == EOVERFLOW ? nil : timestamp

#if os(Windows)
let err = GetLastError()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

_mkgmtime is a CRT function, doesn't that mean you should be checking errno? (Apologies if that's a naive Windows question...)

XCTAssertEqual("abc\"", c?.value)
}

#if !os(Windows)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you move this inside the text and do an XCTSkip for Windows? That way we can document why the test is skipped.

Comment on lines +273 to +274
// _mktemp_s is not great, as it's rumored to have limited randomness, but Windows doesn't have mkstemp
// And this is a test utility only.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's no rumor about this:

_mktemp_s can create a maximum of 26 unique file names for any given combination of base and nameTemplate values.

From the docs: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mktemp-s-wmktemp-s?view=msvc-170

This is such a limitation that I wonder if tests might legitimately hit this.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants