-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make wait_readable and wait_writable public #7366
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.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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