make wait_readable and wait_writable public#7366
make wait_readable and wait_writable public#7366sdogruyol merged 2 commits intocrystal-lang:masterfrom stakach:patch-2
Conversation
These methods are useful for integrating 3rd party libraries that require you to wait for a readable or writable socket. Example [libssh2](https://github.com/libssh2/libssh2/blob/master/example/ssh2_exec.c) How this is implemented in crystal: https://github.com/spider-gazelle/ssh2.cr/blob/a93eb957420b9e9f31bb8cd46e50ff862c5bc54b/src/session.cr#L39-L49
|
Those methods are just an implementation detail, it's not right to expose them. |
|
@asterite how should one integrate libssh2 to prevent it blocking the event loop? When using non-blocking methods, it returns EAGAIN, then you query if it's waiting for the socket to be readable and / or writable. Then you have to wait_readable / wait_writeable before calling the method again. |
|
How is it done in Go? |
|
Actually, nevermind, I have no idea what I am talking about 😊 |
|
haha yeah, looks like they have a native golang implementation.. |
|
Can we make them |
restoring the changes made in #7366 Change was originally made in this release: https://github.com/crystal-lang/crystal/blob/3aa1a04ca666dcf12a625b58deccbf0f209e1e4d/CHANGELOG.md#0280-2019-04-17
We can use IO::FileDescriptor#wait_readable (an undocumented but public method) to yield a fiber until the file descriptor has something to read. On POSIX systems (only), the X11 socket is exposed as a file descriptor. That's an acceptable limitation for now---I don't care to support X11 on Windows. crystal-lang/crystal#7366 crystal-lang/crystal#8651 https://forum.crystal-lang.org/t/fibers-blocking-io-and-c-libraries/3116/13?u=elebow
These methods are useful for integrating 3rd party libraries that require you to wait for a readable or writable socket.
Example libssh2
How this is implemented in crystal: https://github.com/spider-gazelle/ssh2.cr/blob/a93eb957420b9e9f31bb8cd46e50ff862c5bc54b/src/session.cr#L39-L49