Skip to content

Ask system to decide non-blocking IO::FileDescriptor (win32)#15753

Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/win32-file-descriptor-open-check-for-overlapped-flag
May 9, 2025
Merged

Ask system to decide non-blocking IO::FileDescriptor (win32)#15753
straight-shoota merged 4 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/win32-file-descriptor-open-check-for-overlapped-flag

Conversation

@ysbaddaden
Copy link
Collaborator

The current implementation inherited the file type check for UNIX to detect special file types (sockets, pipes/fifos, or character devices) for which we must set O_NONBLOCK vs regular disk files (not needed).

From what I understand, Windows is more interested about whether the file handle has been opened with OVERLAPPED support for asynchronous IO (non-blocking) or not (blocking).

There isn't an official API that reports if the FILE_FLAG_OVERLAPPED attribute has been set for a HANDLE. We can, however, use an obscure NT library (dates from Windows 2000) that somehow leaks the information.

The current implementation inherits the file type check for UNIX to
detect special file types (sockets, pipes/fifos, or character devices)
for which we must set O_NONBLOCK vs regular disk files (pointless).

From what I understand, Windows is more interested to know if the file
handle has been opened with OVERLAPPED support for asynchronous IO
(non-blocking) or not (blocking).
@ysbaddaden ysbaddaden requested a review from HertzDevil May 6, 2025 16:07
@ysbaddaden ysbaddaden self-assigned this May 6, 2025
@ysbaddaden ysbaddaden added kind:refactor platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files labels May 6, 2025
@straight-shoota straight-shoota added this to the 1.17.0 milestone May 6, 2025
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request May 6, 2025
@straight-shoota straight-shoota changed the title Ask system to decide non-blocking IO::FileDescriptor (win32) Ask system to decide non-blocking IO::FileDescriptor (win32) May 9, 2025
@straight-shoota straight-shoota merged commit cb04e18 into crystal-lang:master May 9, 2025
34 checks passed
@ysbaddaden ysbaddaden deleted the refactor/win32-file-descriptor-open-check-for-overlapped-flag branch May 12, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:refactor platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants