Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
===== 5.9.2 =====

====== Packaging ======

* lwt_ppx is compatible with newer versions of ppxlib. (Patrick Ferris, Kate Deplaix, Sora Morimoto, #1033)

====== Other ======

* Misc repository maintenance. (Sora Morimoto)

* Misc typo. (Kaustubh Maske Patil, #1056)

===== 5.9.1 =====

====== Fixes ======

* META files now carry version information. (Hugo Heuzard, #1042, #1053)

===== 5.9.0 =====

====== Additions ======
Expand All @@ -14,6 +32,12 @@

* Misc repository maintenance. (Sora Morimoto, Shon Feder, #1037, #1035)

===== 5.8.1 =====

====== Fixes ======

* META files now carry version information. (Hugo Heuzard, #1042, #1053)

===== 5.8.0 =====

====== Improvements ======
Expand Down
3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

(package
(name lwt_ppx)
(version 5.9.2)
(authors "Gabriel Radanne")
(synopsis "PPX syntax for Lwt, providing something similar to async/await from JavaScript")
(depends
(ocaml (>= 4.08))
Expand All @@ -51,6 +53,7 @@

(package
(name lwt)
(version 5.9.2)
(synopsis "Promises and event-driven I/O")
(description "A promise is a value that may become determined in the future.

Expand Down
1 change: 1 addition & 0 deletions lwt.opam
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "5.9.2"
synopsis: "Promises and event-driven I/O"
description: """
A promise is a value that may become determined in the future.
Expand Down
3 changes: 2 additions & 1 deletion lwt_ppx.opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "5.9.2"
synopsis:
"PPX syntax for Lwt, providing something similar to async/await from JavaScript"
maintainer: [
"Raphaël Proust <[email protected]>" "Anton Bachin <[email protected]>"
]
authors: ["Jérôme Vouillon" "Jérémie Dimino"]
authors: ["Gabriel Radanne"]
license: "MIT"
homepage: "https://github.com/ocsigen/lwt"
doc: "https://ocsigen.org/lwt"
Expand Down
40 changes: 9 additions & 31 deletions src/unix/lwt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1553,18 +1553,14 @@ let close_socket fd =
(fun () ->
Lwt_unix.close fd)

let open_connection ?fd ?(set_tcp_nodelay=true) ?(prepare_fd=ignore) ?in_buffer ?out_buffer sockaddr =
let open_connection ?fd ?in_buffer ?out_buffer sockaddr =
let fd =
match fd with
| None ->
Lwt_unix.socket (Unix.domain_of_sockaddr sockaddr) Unix.SOCK_STREAM 0
| Some fd ->
fd
in

if set_tcp_nodelay then Lwt_unix.setsockopt fd Unix.TCP_NODELAY true;
prepare_fd fd;

let close = lazy (close_socket fd) in
Lwt.catch
(fun () ->
Expand All @@ -1590,8 +1586,8 @@ let with_close_connection f (ic, oc) =
(fun () -> f (ic, oc))
(fun () -> close_if_not_closed ic <&> close_if_not_closed oc)

let with_connection ?fd ?set_tcp_nodelay ?prepare_fd ?in_buffer ?out_buffer sockaddr f =
open_connection ?fd ?set_tcp_nodelay ?prepare_fd ?in_buffer ?out_buffer sockaddr >>= fun channels ->
let with_connection ?fd ?in_buffer ?out_buffer sockaddr f =
open_connection ?fd ?in_buffer ?out_buffer sockaddr >>= fun channels ->
with_close_connection f channels

type server = {
Expand All @@ -1609,9 +1605,6 @@ let shutdown_server_deprecated server =
let establish_server_generic
bind_function
?fd:preexisting_socket_for_listening
?(set_tcp_nodelay=true)
?(prepare_listening_fd=ignore)
?(prepare_client_fd=ignore)
?(backlog = Lwt_unix.somaxconn () [@ocaml.warning "-3"])
listening_address
connection_handler_callback =
Expand All @@ -1625,7 +1618,6 @@ let establish_server_generic
socket
in
Lwt_unix.setsockopt listening_socket Unix.SO_REUSEADDR true;
prepare_listening_fd listening_socket;

(* This promise gets resolved with `Should_stop when the user calls
Lwt_io.shutdown_server. This begins the shutdown procedure. *)
Expand Down Expand Up @@ -1653,13 +1645,10 @@ let establish_server_generic
Lwt.pick [try_to_accept; should_stop] >>= function
| `Accepted (client_socket, client_address) ->
begin
try
Lwt_unix.set_close_on_exec client_socket
try Lwt_unix.set_close_on_exec client_socket
with Invalid_argument _ -> ()
end;

if set_tcp_nodelay then Lwt_unix.setsockopt client_socket Unix.TCP_NODELAY true;
prepare_client_fd client_socket;
connection_handler_callback client_address client_socket;

accept_loop ()
Expand Down Expand Up @@ -1701,9 +1690,7 @@ let establish_server_generic
server, server_has_started

let establish_server_with_client_socket
?server_fd ?backlog ?(no_close = false)
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr f =
?server_fd ?backlog ?(no_close = false) sockaddr f =
let handler client_address client_socket =
Lwt.async begin fun () ->
(* Not using Lwt.finalize here, to make sure that exceptions from [f]
Expand Down Expand Up @@ -1731,9 +1718,7 @@ let establish_server_with_client_socket

let server, server_started =
establish_server_generic
Lwt_unix.bind ?fd:server_fd ?backlog
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr handler
Lwt_unix.bind ?fd:server_fd ?backlog sockaddr handler
in
server_started >>= fun () ->
Lwt.return server
Expand All @@ -1744,7 +1729,6 @@ let establish_server_with_client_address_generic
?(buffer_size = !default_buffer_size)
?backlog
?(no_close = false)
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr
handler =

Expand Down Expand Up @@ -1800,19 +1784,13 @@ let establish_server_with_client_address_generic
best_effort_close output_channel)
in

establish_server_generic bind_function ?fd ?backlog
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr handler
establish_server_generic bind_function ?fd ?backlog sockaddr handler

let establish_server_with_client_address
?fd ?buffer_size ?backlog ?no_close
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr handler =
?fd ?buffer_size ?backlog ?no_close sockaddr handler =
let server, server_started =
establish_server_with_client_address_generic
Lwt_unix.bind ?fd ?buffer_size ?backlog ?no_close
?set_tcp_nodelay ?prepare_listening_fd ?prepare_client_fd
sockaddr handler
Lwt_unix.bind ?fd ?buffer_size ?backlog ?no_close sockaddr handler
in
server_started >>= fun () ->
Lwt.return server
Expand Down
29 changes: 1 addition & 28 deletions src/unix/lwt_io.mli
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ val delete_recursively : string -> unit Lwt.t

val open_connection :
?fd : Lwt_unix.file_descr ->
?set_tcp_nodelay:bool ->
?prepare_fd: (Lwt_unix.file_descr -> unit) ->
?in_buffer : Lwt_bytes.t -> ?out_buffer : Lwt_bytes.t ->
Unix.sockaddr -> (input_channel * output_channel) Lwt.t
(** [open_connection ?fd ?in_buffer ?out_buffer addr] opens a
Expand All @@ -571,31 +569,15 @@ val open_connection :
channels.

@raise Unix.Unix_error on error.

@param set_tcp_nodelay if true, [TCP_NODELAY] is set on the socket FD. This
avoids a surprising 40ms delay in some situations.
See for example https://brooker.co.za/blog/2024/05/09/nagle.html for why.

@param prepare_fd is a custom callback that can be used to modify the socket FD
before it is turned into high level channels.

For example passing
[~prepare_fd:(fun fd -> Lwt_unix.setsockopt_int fd SO_SNDBUF 65_536)]
will set the socket's send buffer's size to 64kiB.
*)

val with_connection :
?fd : Lwt_unix.file_descr ->
?set_tcp_nodelay:bool ->
?prepare_fd: (Lwt_unix.file_descr -> unit) ->
?in_buffer : Lwt_bytes.t -> ?out_buffer : Lwt_bytes.t ->
Unix.sockaddr -> (input_channel * output_channel -> 'a Lwt.t) -> 'a Lwt.t
(** [with_connection ?fd ?in_buffer ?out_buffer addr f] opens a
connection to the given address and passes the channels to
[f]

See {!open_connection} for more details about [set_tcp_nodelay]
and [prepare_fd]. *)
[f] *)

(**/**)

Expand All @@ -619,9 +601,6 @@ val establish_server_with_client_socket :
?server_fd:Lwt_unix.file_descr ->
?backlog:int ->
?no_close:bool ->
?set_tcp_nodelay:bool ->
?prepare_listening_fd:(Lwt_unix.file_descr -> unit) ->
?prepare_client_fd:(Lwt_unix.file_descr -> unit) ->
Unix.sockaddr ->
(Lwt_unix.sockaddr -> Lwt_unix.file_descr -> unit Lwt.t) ->
server Lwt.t
Expand Down Expand Up @@ -669,19 +648,13 @@ f client_address client_socket
started listening on [listen_address]: right after the internal call to
[listen], and right before the first internal call to [accept].

See {!open_connection} for more details about [set_tcp_nodelay]
and [prepare_fd].

@since 4.1.0 *)

val establish_server_with_client_address :
?fd:Lwt_unix.file_descr ->
?buffer_size:int ->
?backlog:int ->
?no_close:bool ->
?set_tcp_nodelay:bool ->
?prepare_listening_fd:(Lwt_unix.file_descr -> unit) ->
?prepare_client_fd:(Lwt_unix.file_descr -> unit) ->
Unix.sockaddr ->
(Lwt_unix.sockaddr -> input_channel * output_channel -> unit Lwt.t) ->
server Lwt.t
Expand Down
Loading