Skip to content

Commit fb23848

Browse files
committed
Translate some Lwt_unix calls to blocking Unix calls
Using the Eio API in this case might not make sense.
1 parent 8204060 commit fb23848

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

bin/lwt_to_direct_style/ast_rewrite.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ let rewrite_apply ~backend ~state full_ident args =
314314
(( "printf" | "eprintf" | "stdout" | "stderr" | "fprintf" | "kfprintf"
315315
| "ifprintf" | "ikfprintf" ) as ident) ) ->
316316
transparent [ "Format"; ident ]
317+
| ( "Lwt_unix",
318+
(( "socket" | "socketpair" | "listen" | "shutdown" | "getsockname"
319+
| "getpeername" | "waitpid" | "wait4" | "wait" ) as ident) ) ->
320+
transparent [ "Unix"; ident ]
321+
| "Lwt_unix", (("connect" | "accept" | "bind") as ident) ->
322+
Printf.ksprintf (add_comment state)
323+
"This call to [Unix.%s] was [Lwt_unix.%s] before. It's now blocking."
324+
ident ident;
325+
transparent [ "Unix"; ident ]
317326
| "Lwt_list", ident -> (
318327
match string_drop_suffix ~suffix:"_s" ident with
319328
| Some ident -> transparent [ "List"; ident ]

test/lwt_to_direct_style/to_direct_style.t/run.t

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Make a writable directory tree:
230230
Lwt_mutex.lock (line 136 column 9)
231231
Lwt_mutex.unlock (line 137 column 9)
232232
Lwt_mutex.with_lock (line 138 column 9)
233-
lib/test_lwt_unix.ml: (47 occurrences)
233+
lib/test_lwt_unix.ml: (53 occurrences)
234234
Lwt_io (line 7 column 8)
235235
Lwt.return (line 12 column 3)
236236
Lwt.return (line 46 column 11)
@@ -277,6 +277,12 @@ Make a writable directory tree:
277277
Lwt_unix.ADDR_UNIX (line 17 column 6)
278278
Lwt_unix.ADDR_INET (line 17 column 29)
279279
Lwt_unix.ADDR_INET (line 18 column 3)
280+
Lwt_unix.socket (line 50 column 3)
281+
Lwt_unix.socketpair (line 51 column 16)
282+
Lwt_unix.accept (line 53 column 12)
283+
Lwt_unix.connect (line 52 column 14)
284+
Lwt_unix.bind (line 54 column 14)
285+
Lwt_unix.listen (line 55 column 14)
280286
Lwt_unix.getaddrinfo (line 20 column 9)
281287
lib/test.mli: (17 occurrences)
282288
Lwt (line 12 column 26)
@@ -835,3 +841,23 @@ Make a writable directory tree:
835841
(* TODO: lwt-to-direct-style: [env] must be propagated from the main loop *)
836842
(* TODO: lwt-to-direct-style: [sw] (of type Switch.t) must be propagated here. *)
837843
f 12))
844+
845+
let _f a b c = Unix.socket a b c
846+
let _f a b c = Unix.socketpair a b c
847+
848+
let _f a b =
849+
Unix.connect
850+
(* TODO: lwt-to-direct-style: This call to [Unix.connect] was [Lwt_unix.connect] before. It's now blocking. *)
851+
a b
852+
853+
let _f a =
854+
Unix.accept
855+
(* TODO: lwt-to-direct-style: This call to [Unix.accept] was [Lwt_unix.accept] before. It's now blocking. *)
856+
a
857+
858+
let _f a b =
859+
Unix.bind
860+
(* TODO: lwt-to-direct-style: This call to [Unix.bind] was [Lwt_unix.bind] before. It's now blocking. *)
861+
a b
862+
863+
let _f a b = Unix.listen a b

test/lwt_to_direct_style/to_direct_style.t/src/lib/test_lwt_unix.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ let _f = Lwt_preemptive.detach (fun () -> Lwt.return_unit) ()
4545
let _f =
4646
let f = Lwt.return in
4747
Lwt_preemptive.detach f 12
48+
49+
let _f a b c =
50+
Lwt_unix.socket a b c
51+
let _f a b c = Lwt_unix.socketpair a b c
52+
let _f a b = Lwt_unix.connect a b
53+
let _f a = Lwt_unix.accept a
54+
let _f a b = Lwt_unix.bind a b
55+
let _f a b = Lwt_unix.listen a b

0 commit comments

Comments
 (0)