Skip to content

Add .set_blocking to Socket and IO::FileDescriptor and deprecate #blocking property#16033

Merged
straight-shoota merged 6 commits intocrystal-lang:masterfrom
ysbaddaden:feature/deprecate-io-blocking-property-and-add-set_blocking
Aug 2, 2025
Merged

Add .set_blocking to Socket and IO::FileDescriptor and deprecate #blocking property#16033
straight-shoota merged 6 commits intocrystal-lang:masterfrom
ysbaddaden:feature/deprecate-io-blocking-property-and-add-set_blocking

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Jul 29, 2025

The #blocking properties on Socket and IO::FileDescriptor changes the underlying configuration of the system file descriptor or handle, and can conflict with the IO runtime (i.e. the event loop requirements) and lead to runtime issues.

This PR deprecates the #blocking property and instead introduces a couple class methods to change the blocking configuration of a raw file descriptor or handle outside of the IO objects when you really need to change it:

  • IO::FileDescriptor.set_blocking(fd, value) that's only available on UNIX targets (raises on Windows);
  • Socket.set_blocking(fd, value) that's available on all targets (though it's legacy on Windows).

Extracted from #15924.

ysbaddaden and others added 2 commits July 31, 2025 11:38
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
@ysbaddaden
Copy link
Collaborator Author

I added the .get_blocking counterpart.

@straight-shoota straight-shoota added this to the 1.18.0 milestone Jul 31, 2025
@straight-shoota straight-shoota merged commit ba29871 into crystal-lang:master Aug 2, 2025
39 checks passed
@ysbaddaden ysbaddaden deleted the feature/deprecate-io-blocking-property-and-add-set_blocking branch August 4, 2025 16:13
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Sep 2, 2025
Fijxu added a commit to Fijxu/invidious that referenced this pull request Nov 18, 2025
This replaces the deprecated argument `blocking` and uses
`Socket.set_blocking(fd, value)` instead.

Fixes a warning in the compiler

crystal-lang/crystal#16033
unixfox pushed a commit to Fijxu/invidious that referenced this pull request Dec 19, 2025
This replaces the deprecated argument `blocking` and uses
`Socket.set_blocking(fd, value)` instead.

Fixes a warning in the compiler

crystal-lang/crystal#16033
unixfox added a commit to iv-org/invidious that referenced this pull request Dec 19, 2025
* Replace deprecated `blocking` property of `Socket`

This replaces the deprecated argument `blocking` and uses
`Socket.set_blocking(fd, value)` instead.

Fixes a warning in the compiler

crystal-lang/crystal#16033

* Upgrade to upstream

* chore: only Socket.set_blocking for > 1.18

---------

Co-authored-by: Emilien <4016501+unixfox@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants