Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arogbonlo committed Oct 16, 2024
1 parent 456b43b commit daad30e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib_eio/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Pi = struct
val pipe :
t ->
sw:Switch.t ->
([< Flow.source_ty | Resource.close_ty] r) * ([< Flow.sink_ty | Resource.close_ty] r)
[< `Flow_source | `Resource_close] r * [< `Flow_sink | `Resource_close] r

val spawn :
t ->
Expand Down
13 changes: 8 additions & 5 deletions lib_eio/process.mli
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ val parse_out :

(** {2 Pipes} *)

val pipe : sw:Switch.t -> _ mgr -> ([< Flow.source_ty | Resource.close_ty] r) * ([< Flow.sink_ty | Resource.close_ty] r)
val pipe :
sw:Switch.t ->
_ mgr ->
([< Flow.source_ty | Resource.close_ty] r * [< Flow.sink_ty | Resource.close_ty] r)
(** [pipe ~sw mgr] creates a pipe backed by the OS.
The flows can be used by {!spawn} without the need for extra fibers to copy the data.
Expand Down Expand Up @@ -168,10 +171,10 @@ module Pi : sig
type tag
type t

val pipe :
t ->
sw:Switch.t ->
([< Flow.source_ty | Resource.close_ty] r) * ([< Flow.sink_ty | Resource.close_ty] r)
val pipe :
t ->
sw:Switch.t ->
[< Flow.source_ty | Resource.close_ty] r * [< Flow.sink_ty | Resource.close_ty] r

val spawn :
t ->
Expand Down
11 changes: 4 additions & 7 deletions lib_eio/unix/eio_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[@@@alert "-unstable"]

open Eio.Std
open Eio.Flow
open Eio.Resource


type Eio.Exn.Backend.t += Unix_error of Unix.error * string * string
(** Wrapper for embedding {!Unix.Unix_error} errors. *)
Expand All @@ -27,8 +24,6 @@ module Resource : sig
val fd : _ t -> Fd.t
(** [fd t] returns the FD being wrapped by a resource. *)

type close_ty = [`Close]

val fd_opt : _ Eio.Resource.t -> Fd.t option
(** [fd_opt t] returns the FD being wrapped by a generic resource, if any.
Expand Down Expand Up @@ -63,7 +58,9 @@ val run_in_systhread : ?label:string -> (unit -> 'a) -> 'a
@param label The operation name to use in trace output. *)

val pipe : Switch.t -> ([< Eio.Flow.source_ty | Resource.close_ty] r * [< Eio.Flow.sink_ty | Resource.close_ty] r)
val pipe :
Switch.t ->
[< Flow.source_ty | Resource.close_ty] r * [< Flow.sink_ty | Resource.close_ty] r
(** [pipe sw] returns a connected pair of flows [src] and [sink]. Data written to [sink]
can be read from [src].
Note that, like all FDs created by Eio, they are both marked as close-on-exec by default. *)
Expand Down Expand Up @@ -102,7 +99,7 @@ module Private : sig
| Await_readable : Unix.file_descr -> unit Effect.t (** See {!await_readable} *)
| Await_writable : Unix.file_descr -> unit Effect.t (** See {!await_writable} *)
| Get_monotonic_clock : Eio.Time.Mono.ty r Effect.t
| Pipe : Eio.Switch.t -> ([< Eio.Flow.source_ty | Resource.close_ty] r * [< Eio.Flow.sink_ty | Resource.close_ty] r) Effect.t (** See {!pipe} *)
| Pipe : Eio.Switch.t -> (source_ty r * sink_ty r) Effect.t (** See {!pipe} *)

module Rcfd = Rcfd

Expand Down
11 changes: 2 additions & 9 deletions lib_eio/unix/private.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@

open Eio.Std
open Types
open Eio.Flow
open Eio.Resource

type close_ty = [`Close]


type _ Effect.t +=
| Await_readable : Unix.file_descr -> unit Effect.t
| Await_writable : Unix.file_descr -> unit Effect.t
| Get_monotonic_clock : Eio.Time.Mono.ty r Effect.t
| Pipe : Switch.t -> ([< Eio.Flow.source_ty | Resource.close_ty] r * [< Eio.Flow.sink_ty | Resource.close_ty] r) Effect.t
| Pipe : Switch.t -> ([< Flow.source_ty | Resource.close_ty] r * [< Flow.sink_ty | Resource.close_ty] r) Effect.t

let await_readable fd = Effect.perform (Await_readable fd)
let await_writable fd = Effect.perform (Await_writable fd)

let pipe ~sw =
perform (Pipe sw : ([< Eio.Flow.source_ty | Resource.close_ty] r * [< Eio.Flow.sink_ty | Resource.close_ty] r))
let pipe sw = Effect.perform (Pipe sw)

module Rcfd = Rcfd
module Fork_action = Fork_action
module Thread_pool = Thread_pool


external eio_readlinkat : Unix.file_descr -> string -> Cstruct.t -> int = "eio_unix_readlinkat"

let read_link_unix fd path =
Expand Down
5 changes: 3 additions & 2 deletions lib_eio/unix/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ end) = struct
type tag = [ `Generic | `Unix ]

let pipe _ ~sw =
(Private.pipe sw :> ([Eio.Resource.close_ty | Eio.Flow.source_ty] r *
[Eio.Resource.close_ty | Eio.Flow.sink_ty] r))
(Eio.Process.pipe ~sw :> ([< Eio.Resource.close_ty | Eio.Flow.source_ty] r *
[< Eio.Resource.close_ty | Eio.Flow.sink_ty] r))


let spawn v ~sw ?cwd ?stdin ?stdout ?stderr ?env ?executable args =
let executable = get_executable executable ~args in
Expand Down

0 comments on commit daad30e

Please sign in to comment.