-
Notifications
You must be signed in to change notification settings - Fork 232
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
Add ev/to-file
for synchronous resource operations
#1533
Conversation
I think |
I got a tip that may be
Does that seem right? |
I don't think |
That is strange to me, since the windows path should be used on windows and mingw |
I don't have a MinGW environment that I can test to explore further. You can see the errors that were occurring for various approaches in my Actions history. A sample error:
and if I disable buffering:
I've removed the special casing in e94e8dc and, while the test suite includes a check to avoid testing in MinGW, the current commit can be experimented with in MinGW. |
Thanks for the work here, @pyrmont! Looks pretty solid to me, and we can investigate the mingw issue later, as I also don't have a mingw setup handy for testing right now. |
Great! Thanks for merging it in! I’m looking forward to using it in my project with the next Janet release :D |
This PR adds
ev/to-file
as a way to allow synchronous operations with stream-based resources (e.g. sockets).Background
Janet supports non-blocking IO operations via the
ev
module. While this is desirable in many cases, there are situations where a user wants to ensure that an operation is synchronous. Janet does not currently offer a mechanism to do this with stream-based resources (e.g. sockets).As discussed in #1531, one way to address this is is to offer a function that would create a
core/file
object based on thecore/stream
object. Thecore/file
object could then be used with the synchronous operations in thefile
module.Implementation
The
src/core/ev.c
file is modified to add anev/to-file
function. The function takes a stream object and attempts to return a file object. This can then be used in the same way as other file objects:Limitations
I wasn’t able to get this working on MinGW. Based on some cursory reading, I think this might be a limitation in how MinGW handles the use of Windows sockets via file descriptors. As a result, calling this function in a MinGW environment will raise an error.