From feeeac9e55fc31799f3c080f62488c6b516a8e1d Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 8 Jun 2023 11:06:00 +0100 Subject: [PATCH] Remove deprecated features --- lib_eio/core/eio__core.mli | 3 -- lib_eio/core/fiber.ml | 16 ----------- lib_eio/unix/eio_unix.ml | 25 ----------------- lib_eio/unix/eio_unix.mli | 34 ----------------------- lib_eio_linux/eio_linux.ml | 34 ++++++++++------------- lib_eio_linux/eio_linux.mli | 20 -------------- lib_eio_linux/fd.ml | 14 ---------- lib_eio_posix/fd.ml | 14 ---------- lib_eio_posix/fd.mli | 47 -------------------------------- lib_eio_posix/low_level.ml | 2 +- lib_eio_posix/low_level.mli | 3 -- lib_eio_windows/test/test_net.ml | 2 +- 12 files changed, 17 insertions(+), 197 deletions(-) delete mode 100644 lib_eio_linux/fd.ml delete mode 100644 lib_eio_posix/fd.ml delete mode 100644 lib_eio_posix/fd.mli diff --git a/lib_eio/core/eio__core.mli b/lib_eio/core/eio__core.mli index 4b842da63..b69ec3b0c 100644 --- a/lib_eio/core/eio__core.mli +++ b/lib_eio/core/eio__core.mli @@ -234,9 +234,6 @@ module Fiber : sig [fn] runs immediately, without switching to any other fiber first. The calling fiber is placed at the head of the run queue, ahead of any previous items. *) - val fork_sub : sw:Switch.t -> on_error:(exn -> unit) -> (Switch.t -> unit) -> unit - [@@deprecated "Use Fiber.fork and Switch.run separately instead"] - val fork_promise : sw:Switch.t -> (unit -> 'a) -> 'a Promise.or_exn (** [fork_promise ~sw fn] schedules [fn ()] to run in a new fiber and returns a promise for its result. diff --git a/lib_eio/core/fiber.ml b/lib_eio/core/fiber.ml index 7ed9101a2..14e40f44d 100644 --- a/lib_eio/core/fiber.ml +++ b/lib_eio/core/fiber.ml @@ -83,22 +83,6 @@ let pair f g = let y = g () in (Promise.await_exn x, y) -let fork_sub ~sw ~on_error f = - fork ~sw (fun () -> - try Switch.run f - with - | ex when Cancel.is_on sw.cancel -> - (* Typically the caller's context is within [sw], but it doesn't have to be. - It's possible that the original context has finished by now, - but [fork] is keeping [sw] alive so we can use that report the error. *) - Switch.run_in sw @@ fun () -> - try on_error ex - with ex2 -> - (* The [run_in] ensures [adopting_sw] isn't finished here *) - Switch.fail sw ex; - Switch.fail sw ex2 - ) - exception Not_first let await_cancel () = diff --git a/lib_eio/unix/eio_unix.ml b/lib_eio/unix/eio_unix.ml index 017b92698..73aa432c8 100644 --- a/lib_eio/unix/eio_unix.ml +++ b/lib_eio/unix/eio_unix.ml @@ -23,35 +23,10 @@ let sleep d = let run_in_systhread = Private.run_in_systhread -(* Deprecated *) -module FD = struct - let peek t = Fd.use_exn "peek" (Resource.fd t) Fun.id - - let peek_opt t = - match Resource.fd_opt t with - | None -> None - | Some fd -> Some (Fd.use_exn "peek_opt" fd Fun.id) - - let take t = Fd.remove (Resource.fd t) |> Option.get - - let take_opt t = - match Resource.fd_opt t with - | None -> None - | Some fd -> Fd.remove fd - - let as_socket = Net.import_socket_stream -end - module Ipaddr = Net.Ipaddr -let socketpair ~sw ?domain ?(ty=Unix.SOCK_STREAM) ?protocol () = - assert (ty = Unix.SOCK_STREAM); - Net.socketpair_stream ~sw ?domain ?protocol () - module Ctf = Ctf_unix -let getnameinfo = Net.getnameinfo - module Process = Process module Net = Net diff --git a/lib_eio/unix/eio_unix.mli b/lib_eio/unix/eio_unix.mli index 4f88ad0f3..717c27cee 100644 --- a/lib_eio/unix/eio_unix.mli +++ b/lib_eio/unix/eio_unix.mli @@ -44,40 +44,6 @@ val await_readable : Unix.file_descr -> unit val await_writable : Unix.file_descr -> unit (** [await_writable fd] blocks until [fd] is writable (or has an error). *) -(**/**) -module FD : sig - val peek : < Resource.t; .. > -> Unix.file_descr - [@@deprecated "Use Eio_unix.Resource.fd instead"] - - val peek_opt : #Eio.Generic.t -> Unix.file_descr option - [@@deprecated "Use Eio_unix.Resource.fd_opt instead"] - - val take : < Resource.t; .. > -> Unix.file_descr - [@@deprecated "Use Eio_unix.Resource.fd and Fd.remove instead"] - - val take_opt : #Eio.Generic.t -> Unix.file_descr option - [@@deprecated "Use Eio_unix.Resource.fd_opt and Fd.remove instead"] - - val as_socket : sw:Switch.t -> close_unix:bool -> Unix.file_descr -> Net.stream_socket - [@@deprecated "Use Eio_unix.Net.import_socket_stream instead"] -end - -module Ipaddr = Net.Ipaddr -[@@deprecated "Use Eio_unix.Net.Ipaddr instead"] - -val getnameinfo : Eio.Net.Sockaddr.t -> (string * string) -[@@deprecated "Use stdenv"] - -val socketpair : - sw:Switch.t -> - ?domain:Unix.socket_domain -> - ?ty:Unix.socket_type -> - ?protocol:int -> - unit -> - Net.stream_socket * Net.stream_socket -[@@@deprecated "Use Net.socketpair_stream"] -(**/**) - val sleep : float -> unit (** [sleep d] sleeps for [d] seconds, allowing other fibers to run. This is can be useful for debugging (e.g. to introduce delays to trigger a race condition) diff --git a/lib_eio_linux/eio_linux.ml b/lib_eio_linux/eio_linux.ml index 773f847fe..b6077291d 100644 --- a/lib_eio_linux/eio_linux.ml +++ b/lib_eio_linux/eio_linux.ml @@ -21,6 +21,7 @@ open Eio.Std module Fiber_context = Eio.Private.Fiber_context module Ctf = Eio.Private.Ctf +module Fd = Eio_unix.Fd module Suspended = Eio_utils.Suspended module Zzz = Eio_utils.Zzz @@ -28,11 +29,6 @@ module Lf_queue = Eio_utils.Lf_queue module Low_level = Low_level -(* Deprecated FD code *) -module FD = Fd -let get_fd = Eio_unix.Resource.fd -let get_fd_opt = Eio_unix.Resource.fd_opt - type _ Eio.Generic.ty += Dir_fd : Low_level.dir_fd Eio.Generic.ty let get_dir_fd_opt t = Eio.Generic.probe t Dir_fd @@ -112,7 +108,7 @@ let datagram_socket sock = object method fd = sock - method close = FD.close sock + method close = Fd.close sock method send ?dst buf = let dst = Option.map Eio_unix.Net.sockaddr_to_unix dst in @@ -125,10 +121,10 @@ let datagram_socket sock = object end let flow fd = - let is_tty = FD.use_exn "isatty" fd Unix.isatty in + let is_tty = Fd.use_exn "isatty" fd Unix.isatty in object (_ : ) method fd = fd - method close = FD.close fd + method close = Fd.close fd method stat = Low_level.fstat fd @@ -178,7 +174,7 @@ let sink fd = (flow fd :> sink) let listening_socket fd = object inherit Eio.Net.listening_socket - method close = FD.close fd + method close = Fd.close fd method accept ~sw = Switch.check sw; @@ -208,7 +204,7 @@ let socket_domain_of = function let connect ~sw connect_addr = let addr = Eio_unix.Net.sockaddr_to_unix connect_addr in let sock_unix = Unix.socket ~cloexec:true (socket_domain_of connect_addr) Unix.SOCK_STREAM 0 in - let sock = FD.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in + let sock = Fd.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in Low_level.connect sock addr; (flow sock :> Eio.Net.stream_socket) @@ -228,7 +224,7 @@ let net = object ); let addr = Eio_unix.Net.sockaddr_to_unix listen_addr in let sock_unix = Unix.socket ~cloexec:true (socket_domain_of listen_addr) Unix.SOCK_STREAM 0 in - let sock = FD.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in + let sock = Fd.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in (* For Unix domain sockets, remove the path when done (except for abstract sockets). *) begin match listen_addr with | `Unix path -> @@ -258,7 +254,7 @@ let net = object | exception Unix.Unix_error (code, name, arg) -> raise @@ Err.wrap code name arg ); let sock_unix = Unix.socket ~cloexec:true (socket_domain_of saddr) Unix.SOCK_DGRAM 0 in - let sock = FD.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in + let sock = Fd.of_unix ~sw ~seekable:false ~close_unix:true sock_unix in begin match saddr with | `Udp _ | `Unix _ as saddr -> let addr = Eio_unix.Net.sockaddr_to_unix saddr in @@ -418,7 +414,7 @@ class dir ~label (fd : Low_level.dir_fd) = object method close = match fd with - | FD x -> FD.close x + | FD x -> Fd.close x | Cwd | Fs -> failwith "Can't close non-FD directory!" method unlink path = Low_level.unlink ~rmdir:false fd path @@ -466,18 +462,18 @@ let run_event_loop (type a) ?fallback config (main : _ -> a) arg : a = match e with | Eio_unix.Private.Get_monotonic_clock -> Some (fun k -> continue k mono_clock) | Eio_unix.Net.Import_socket_stream (sw, close_unix, fd) -> Some (fun k -> - let fd = FD.of_unix ~sw ~seekable:false ~close_unix fd in + let fd = Fd.of_unix ~sw ~seekable:false ~close_unix fd in continue k (flow fd :> Eio_unix.Net.stream_socket) ) | Eio_unix.Net.Import_socket_datagram (sw, close_unix, fd) -> Some (fun k -> - let fd = FD.of_unix ~sw ~seekable:false ~close_unix fd in + let fd = Fd.of_unix ~sw ~seekable:false ~close_unix fd in continue k (datagram_socket fd) ) | Eio_unix.Net.Socketpair_stream (sw, domain, protocol) -> Some (fun k -> match let a, b = Unix.socketpair ~cloexec:true domain Unix.SOCK_STREAM protocol in - let a = FD.of_unix ~sw ~seekable:false ~close_unix:true a |> flow in - let b = FD.of_unix ~sw ~seekable:false ~close_unix:true b |> flow in + let a = Fd.of_unix ~sw ~seekable:false ~close_unix:true a |> flow in + let b = Fd.of_unix ~sw ~seekable:false ~close_unix:true b |> flow in ((a :> Eio_unix.Net.stream_socket), (b :> Eio_unix.Net.stream_socket)) with | r -> continue k r @@ -487,8 +483,8 @@ let run_event_loop (type a) ?fallback config (main : _ -> a) arg : a = | Eio_unix.Net.Socketpair_datagram (sw, domain, protocol) -> Some (fun k -> match let a, b = Unix.socketpair ~cloexec:true domain Unix.SOCK_DGRAM protocol in - let a = FD.of_unix ~sw ~seekable:false ~close_unix:true a |> datagram_socket in - let b = FD.of_unix ~sw ~seekable:false ~close_unix:true b |> datagram_socket in + let a = Fd.of_unix ~sw ~seekable:false ~close_unix:true a |> datagram_socket in + let b = Fd.of_unix ~sw ~seekable:false ~close_unix:true b |> datagram_socket in ((a :> Eio_unix.Net.datagram_socket), (b :> Eio_unix.Net.datagram_socket)) with | r -> continue k r diff --git a/lib_eio_linux/eio_linux.mli b/lib_eio_linux/eio_linux.mli index 70b6562b5..f9cff07c0 100644 --- a/lib_eio_linux/eio_linux.mli +++ b/lib_eio_linux/eio_linux.mli @@ -25,18 +25,6 @@ open Eio.Std type fd := Eio_unix.Fd.t -(**/**) -module FD : sig - type t = fd - - val is_open : t -> bool - val close : t -> unit - val of_unix : sw:Switch.t -> seekable:bool -> close_unix:bool -> Unix.file_descr -> t - val to_unix : [< `Peek | `Take] -> t -> Unix.file_descr -end -[@@deprecated "Use Eio_unix.Fd instead"] -(**/**) - (** {1 Eio API} *) type source = Eio_unix.source @@ -44,14 +32,6 @@ type sink = Eio_unix.sink type stdenv = Eio_unix.Stdenv.base -(**/**) -val get_fd : -> fd -[@@deprecated "Use Eio_unix.Resource.fd instead"] - -val get_fd_opt : #Eio.Generic.t -> fd option -[@@deprecated "Use Eio_unix.Resource.fd_opt instead"] -(**/**) - (** {1 Main Loop} *) val run : diff --git a/lib_eio_linux/fd.ml b/lib_eio_linux/fd.ml deleted file mode 100644 index 3bc8a70fc..000000000 --- a/lib_eio_linux/fd.ml +++ /dev/null @@ -1,14 +0,0 @@ -(* Deprecated *) - -include Eio_unix.Fd - -let is_open t = - use t (fun _ -> true) - ~if_closed:(fun () -> false) - -let to_unix op t = - match op with - | `Take -> remove t |> Option.get - | `Peek -> use_exn "to_unix" t Fun.id - -let of_unix ~sw ~seekable ~close_unix fd = of_unix ~sw ~seekable ~close_unix fd diff --git a/lib_eio_posix/fd.ml b/lib_eio_posix/fd.ml deleted file mode 100644 index 8a90e2c9c..000000000 --- a/lib_eio_posix/fd.ml +++ /dev/null @@ -1,14 +0,0 @@ -(* Deprecated *) - -include Eio_unix.Fd - -type has_fd = Eio_unix.Resource.t - -let to_unix op t = - match op with - | `Take -> remove t |> Option.get - | `Peek -> use_exn "to_unix" t Fun.id - -let of_unix ~sw ~blocking ~close_unix fd = of_unix ~sw ~blocking ~close_unix fd - -let get_fd_opt = Eio_unix.Resource.fd_opt diff --git a/lib_eio_posix/fd.mli b/lib_eio_posix/fd.mli deleted file mode 100644 index 733c4aa3b..000000000 --- a/lib_eio_posix/fd.mli +++ /dev/null @@ -1,47 +0,0 @@ -(** A safe wrapper for {!Unix.file_descr}. *) - -open Eio.Std - -type t = Eio_unix.Fd.t -(** A wrapper around a {!Unix.file_descr}. *) - -val of_unix : sw:Switch.t -> blocking:bool -> close_unix:bool -> Unix.file_descr -> t -(** [of_unix ~sw ~blocking ~close_unix fd] wraps [fd]. - - @param sw Close [fd] automatically when [sw] is finished. - @param blocking Indicates whether [fd] is in blocking mode. - Normally you should call [Unix.set_nonblock fd] first and pass [false] here. - @param close_unix Whether {!close} also closes [fd] (this should normally be [true]). *) - -val use_exn : string -> t -> (Unix.file_descr -> 'a) -> 'a -(** [use_exn op t fn] calls [fn wrapped_fd], ensuring that [wrapped_fd] will not be closed - before [fn] returns. - - If [t] is already closed, it raises an exception, using [op] as the name of the failing operation. *) - -val close : t -> unit -(** [close t] marks [t] as closed, so that {!use_exn} can no longer be used to start new operations. - - The wrapped FD will be closed once all current users of the FD have finished (unless [close_unix = false]). - - @raise Invalid_argument if [t] is closed by another fiber first. *) - -val is_blocking : t -> bool -(** [is_blocking t] returns the value of [blocking] passed to {!of_unix}. *) - -val stdin : t -val stdout : t -val stderr : t - -val to_unix : [`Peek | `Take] -> t -> Unix.file_descr -(** [to_unix `Take t] closes [t] without closing the wrapped FD, which it returns to the caller once all operations on it have finished. - - [to_unix `Peek t] returns the wrapped FD directly. You must ensure that it is not closed while using it. *) - -type has_fd = < fd : t > -(** Resources that have FDs are sub-types of [has_fd]. *) - -val get_fd_opt : #Eio.Generic.t -> t option -(** [get_fd_opt r] returns the [t] being wrapped by a resource, if any. - - This just probes [r] using {!FD}. *) diff --git a/lib_eio_posix/low_level.ml b/lib_eio_posix/low_level.ml index 70a12e2b7..4255c15ab 100644 --- a/lib_eio_posix/low_level.ml +++ b/lib_eio_posix/low_level.ml @@ -11,7 +11,7 @@ open Eio.Std type ty = Read | Write -module Fd = Fd +module Fd = Eio_unix.Fd (* todo: keeping a pool of workers is probably faster *) let in_worker_thread = Eio_unix.run_in_systhread diff --git a/lib_eio_posix/low_level.mli b/lib_eio_posix/low_level.mli index db107402d..e72a474a7 100644 --- a/lib_eio_posix/low_level.mli +++ b/lib_eio_posix/low_level.mli @@ -14,9 +14,6 @@ open Eio.Std type fd := Eio_unix.Fd.t -module Fd = Fd -[@@deprecated "Use Eio_unix.Fd instead"] - val await_readable : fd -> unit val await_writable : fd -> unit diff --git a/lib_eio_windows/test/test_net.ml b/lib_eio_windows/test/test_net.ml index 75ec83161..7dd8b85b1 100755 --- a/lib_eio_windows/test/test_net.ml +++ b/lib_eio_windows/test/test_net.ml @@ -97,7 +97,7 @@ let test_wrap_socket pipe_or_socketpair () = let test_eio_socketpair () = Switch.run @@ fun sw -> - let a, b = Eio_unix.socketpair ~sw () in + let a, b = Eio_unix.Net.socketpair_stream ~sw () in ignore (Eio_unix.Resource.fd a : Eio_unix.Fd.t); ignore (Eio_unix.Resource.fd b : Eio_unix.Fd.t); Eio.Flow.copy_string "foo" a;