Add #wait_readable and #wait_writable to IO::FileDescriptor and Socket#15377
Add #wait_readable and #wait_writable to IO::FileDescriptor and Socket#15377ysbaddaden wants to merge 6 commits intocrystal-lang:masterfrom
#wait_readable and #wait_writable to IO::FileDescriptor and Socket#15377Conversation
de3efdd to
930d521
Compare
|
I don't have an opinion on what the public API should be here, but just wanted to tag @stakach here since I know this is a problem with libssh2 spider-gazelle/ssh2.cr#22 |
|
wait_readable / wait_writable work for me Not that I use libssh2 on windows but it might be useful for someone and implementing the socket checks for windows would make it possible |
|
I fixed a couple details. Still, I'm wondering if exposing these methods is a good idea. I can't shake the feeling that we could have a more interesting take. For example an For now, I keep this PR as a draft. The methods are available on the event loop: evloop = Crystal::EventLoop.current
evloop.wait_readable(socket || file_descriptor)
evloop.wait_writable(socket || file_descriptor) |
|
Being able to wait on IO objects in general (like an array of sockets) would be ideal and integrating that with select even more so Need to be able to handle adding or removing sockets from the array too, possibly a channel could be used in the select to break you out of it, allowing you to re-select, something like @sockets : Array(IPSocket)
update_sockets_notify = Channel(Nil).new
# ...
loop do
select
when socket = IO::Select.wait_readable(@sockets)
process_io(socket)
when update_sockets_notify.receive
# no-op, notifying of a change to the @sockets array
end
end |
Follow up to #15376 that exposes the
#wait_readableand#wait_writablemethods toIO::FileDescriptorandSocketdirectly.I'm not sure this is the actual way to go. This is mostly an example to get started discussing on how to go forward for a more public API for #15374 and the ideas from RFC #0007: