Skip to content

Add Eio_unix.File module - #937

Merged
talex5 merged 1 commit into
ocaml-multicore:mainfrom
talex5:unix-file
Sep 11, 2026
Merged

Add Eio_unix.File module#937
talex5 merged 1 commit into
ocaml-multicore:mainfrom
talex5:unix-file

Conversation

@talex5

@talex5 talex5 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Allows creating Eio files and flows from FDs.

In many cases it was possible to do this before using Eio_unix.Net.import_socket_stream, but that wasn't obvious and doesn't provide support for e.g. pread (see e.g. #899 (comment)).

@talex5 talex5 added the api API design decision label Sep 9, 2026
Comment thread lib_eio/unix/file.mli Outdated
val import_rw : Fd.t -> [< rw_ty ] r
(** [import_rw fd] is a read/write Eio file that uses [fd].
[fd] should be non-blocking (at least for pipes).

@avsm avsm Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that pipes do actually block in our current implementation of them on Windows (#929), at least until we shift to IOCP (which does support it I think but is a huge change for that backend)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Does the comment need changing then? What happens if you open a pipe in non-blocking mode and pass it to the Windows backend?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It raises ENOTSOCK and all hell breaks loose. But #929 does fix this now by running them in a systhread (i.e. treat it like a file). It does mark a pipe fd as blocking, though (which is what contradicts the comment above)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK, I've removed the stuff about pipes and blocking modes. It's now the backend's responsibility to set it to be non-blocking, if appropriate. Opening a pipe as a file doesn't really make sense anyway.

Comment thread tests/fs.md Outdated

@avsm avsm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@talex5
talex5 force-pushed the unix-file branch 3 times, most recently from be96c70 to 08dcd49 Compare September 11, 2026 14:58
Allows creating Eio files and flows from FDs.

In fact, it was possible to do this before using
`Eio_unix.Net.import_socket_stream`, but that wasn't obvious.
@talex5
talex5 merged commit 2ae74d1 into ocaml-multicore:main Sep 11, 2026
4 of 5 checks passed
@talex5
talex5 deleted the unix-file branch September 11, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API design decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants