Skip to content

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Sep 5, 2025

Extracts the refactors out of #16128.

The main point is to not pass fd explicitly as an argument and to instead let System::FileDescriptor and System::Socket use the fd property. This allows #16128 to wrap calls affecting the fd to wrap them in a reference counter.

See each individual commit for details on each change.

On UNIX also delegates the implementation from `System::Socket` to
`System::FileDescriptor` since it's identical.
Instead use class methods on System::Socket on Win32 for the one case
where we need to configure the socket handle after accept.
Crystal::System::Socket.fcntl(fd, cmd, arg)
end

def fcntl(cmd, arg = 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Socket#fcntl and Socket.fcntl methods aren't portable, rely on LibC constants to call. We might want to consider deprecating 'em?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's consider that in a follow up PR then.

@straight-shoota straight-shoota added this to the 1.18.0 milestone Sep 5, 2025
@ysbaddaden
Copy link
Contributor Author

I'm missing a change to IO::FileDescriptor#fcntl to now call #system_fcntl.

@straight-shoota straight-shoota merged commit 3ec8169 into crystal-lang:master Sep 9, 2025
39 checks passed
@ysbaddaden ysbaddaden deleted the fix/filedescriptor-and-socket-system-integration branch September 9, 2025 08:31
straight-shoota pushed a commit that referenced this pull request Oct 8, 2025
…6137] (#16183)

I missed a couple cases in #16137 in preparation of #16127 where we need a system indirection around the `fd`, so #16128 will be able to count a reference:

- `Crystal::System::File#system_chown`
- `Crystal::System::Socket#system_accept`

Note that by itself the change has no impact or interest.
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.

4 participants