Skip to content
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

Merged
merged 2 commits into from
Feb 11, 2019
Merged

make wait_readable and wait_writable public #7366

merged 2 commits into from
Feb 11, 2019

Conversation

stakach
Copy link
Contributor

@stakach stakach commented Feb 3, 2019

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

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
@asterite
Copy link
Member

asterite commented Feb 3, 2019

Those methods are just an implementation detail, it's not right to expose them.

@stakach
Copy link
Contributor Author

stakach commented Feb 3, 2019

@asterite how should one integrate libssh2 to prevent it blocking the event loop?
Using those methods definitely works to achieve what is required for libssh2 as it's an implementation detail for libssh2 too

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.

@asterite
Copy link
Member

asterite commented Feb 3, 2019

How is it done in Go?

@asterite
Copy link
Member

asterite commented Feb 3, 2019

Actually, nevermind, I have no idea what I am talking about 😊

@stakach
Copy link
Contributor Author

stakach commented Feb 3, 2019

haha yeah, looks like they have a native golang implementation..

Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Since we've already merged #7354 in the same spirit as this PR, I think this is good to merge 👍 Thanks @stakach

@ysbaddaden
Copy link
Contributor

Can we make them :nodoc:? It would allow to use them, but make no guarantee these methods will continue to exist.

@sdogruyol sdogruyol merged commit f7085a8 into crystal-lang:master Feb 11, 2019
@sdogruyol sdogruyol added this to the 0.28.0 milestone Feb 11, 2019
elebow added a commit to elebow/minyaty that referenced this pull request Apr 2, 2022
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
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.

5 participants