Skip to content

Commit a1065f2

Browse files
committed
Compatibility with Lwt 4.x
1 parent e316444 commit a1065f2

File tree

15 files changed

+86
-77
lines changed

15 files changed

+86
-77
lines changed

Makefile.options

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BYTEDBG :=
22
OPTDBG :=
3-
THREAD :=
3+
THREAD := -thread
44

55
ifeq "$(DEBUG)" "YES"
66
BYTEDBG += -g
@@ -17,22 +17,15 @@ BYTEDBG := -p ${BYTEDBG}
1717
OPTDBG += -p
1818
endif
1919

20-
ifeq "$(PREEMPTIVE)" "YES"
21-
THREAD += -thread
22-
endif
23-
2420
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
2521
## but also to generate src/baselib/ocsigen_config.ml and src/files/META
2622

27-
ifeq "$(PREEMPTIVE)" "YES"
28-
LWT_PREEMPTIVE_PACKAGE:=lwt.preemptive
29-
endif
30-
3123
BASE_PACKAGE := lwt ipaddr bytes
3224

3325
SERVER_PACKAGE := lwt_ssl \
34-
bytes \
35-
${LWT_PREEMPTIVE_PACKAGE} \
26+
bytes \
27+
lwt.unix \
28+
lwt_log \
3629
ipaddr \
3730
netstring \
3831
netstring-pcre \

configure

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ set_defaults () {
8181
with_pgsql=1
8282
with_camlzip=1
8383
with_dbm=1
84-
with_preempt=1
8584
prefix="/usr/local"
8685
bindir=""
8786
logdir=""
@@ -412,7 +411,7 @@ check_library lwt "See: http://ocsigen.org/lwt"
412411
check_library lwt.unix "Missing support for 'unix' in lwt."
413412
check_library lwt_react "See: http://ocsigen.org/lwt"
414413
check_library lwt_ssl "See: http://ocsigen.org/lwt"
415-
check_library lwt.preemptive "Missing support for 'preemptive' in lwt."
414+
check_library lwt_log "See: http://ocsigen.org/lwt"
416415

417416
check_library netstring \
418417
"See ocamlnet: http://projects.camlcity.org/projects/ocamlnet.html"
@@ -462,22 +461,6 @@ if [ "$with_camlzip" -gt 0 ]; then
462461
fi
463462
fi
464463

465-
# Check Lwt.preemptive
466-
if [ "$with_preempt" -gt 0 ]; then
467-
if test_library lwt.preemptive; then
468-
echo -n
469-
elif [ "$with_preempt" -gt 1 ]; then
470-
fail_library lwt.preemptive "Missing support for 'preemptive' in lwt."
471-
else
472-
with_preempt=0
473-
fi
474-
fi
475-
476-
if [ "$with_sqlite" -eq 1 ] && [ "$with_preempt" -eq -1 ]; then
477-
echo "preemptive threads are needed by sqlite, enable it with -with-preempt"
478-
exit 1
479-
fi
480-
481464
# Check rlwrap or ledit
482465
if test_binary rlwrap; then
483466
rlwrap=rlwrap
@@ -532,11 +515,6 @@ if [ $with_camlzip -gt 0 ] ; then
532515
else
533516
with_camlzip="NO"
534517
fi
535-
if [ $with_preempt -gt 0 ] ; then
536-
with_preempt="YES"
537-
else
538-
with_preempt="NO"
539-
fi
540518

541519
ocamlinclude=`ocamlfind printconf stdlib`
542520

@@ -588,9 +566,6 @@ OCSIPERSISTPGSQL:=$with_pgsql
588566
# Do you want ocsipersist with dbm? YES/NO
589567
OCSIPERSISTDBM:=$with_dbm
590568
591-
# Do you want preemptive threads ? YES/NO
592-
PREEMPTIVE:=$with_preempt
593-
594569
# Do you want debugging information (-g) ? YES/NO
595570
DEBUG:=$enable_debug
596571

opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ depends: [
4848
"base-threads"
4949
"react"
5050
"ssl"
51-
"lwt" {>= "3.0.0" & < "4.0.0"}
51+
"lwt" {>= "3.0.0"}
5252
"lwt_ssl"
5353
"lwt_react"
54+
"lwt_log"
5455
"ocamlnet" {>= "4.0.2"}
5556
"pcre"
5657
"cryptokit"

src/baselib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include ../../Makefile.config
33
PACKAGE := \
44
bytes \
55
lwt.unix \
6+
lwt_log \
67
netstring \
78
netstring-pcre \
89
cryptokit \

src/baselib/ocsigen_stream.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ let of_file filename =
229229
let fd = Lwt_unix.of_unix_file_descr
230230
(Unix.openfile filename [Unix.O_RDONLY;Unix.O_NONBLOCK] 0o666)
231231
in
232-
let ch = Lwt_chan.in_channel_of_descr fd in
232+
let ch = Lwt_io.of_fd ~mode:Lwt_io.input fd in
233233
let buf = Bytes.create 1024 in
234234
let rec aux () =
235-
Lwt_chan.input ch buf 0 1024 >>= fun n ->
235+
Lwt_io.read_into ch buf 0 1024 >>= fun n ->
236236
if n = 0 then empty None else
237237
(* Streams should be immutable, thus we always make a copy
238238
of the buffer *)

src/extensions/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include ../../Makefile.config
33
PACKAGE := \
44
bytes \
55
lwt.unix \
6+
lwt_log \
67
ipaddr \
78
lwt_ssl \
89
lwt_react \

src/extensions/cgimod.ml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,25 @@ let create_process_cgi filename ri post_out cgi_in err_in re doc_root hostname =
307307
cgi_in
308308
err_in
309309

310-
310+
(* Copied from deprecated [Lwt_chan]. *)
311+
let lwt_chan_input_line ic =
312+
let rec loop buf =
313+
Lwt_io.read_char_opt ic >>= function
314+
| None | Some '\n' ->
315+
Lwt.return (Buffer.contents buf)
316+
| Some char ->
317+
Buffer.add_char buf char;
318+
loop buf
319+
in
320+
Lwt_io.read_char_opt ic >>= function
321+
| Some '\n' ->
322+
Lwt.return ""
323+
| Some char ->
324+
let buf = Buffer.create 128 in
325+
Buffer.add_char buf char;
326+
loop buf
327+
| None ->
328+
Lwt.fail End_of_file
311329

312330
(** This function makes it possible to launch a cgi script *)
313331

@@ -368,15 +386,15 @@ let recupere_cgi head re doc_root filename ri hostname =
368386
Lwt_timeout.start timeout;
369387

370388
(* A thread giving POST data to the CGI script: *)
371-
let post_in_ch = Lwt_chan.out_channel_of_descr post_in in
389+
let post_in_ch = Lwt_io.of_fd ~mode:Lwt_io.output post_in in
372390
ignore
373391
(catch
374392
(fun () ->
375393
(match (Ocsigen_request_info.http_frame ri).Ocsigen_http_frame.frame_content with
376394
| None -> Lwt_unix.close post_in
377395
| Some content_post ->
378396
Ocsigen_http_com.write_stream post_in_ch content_post >>= fun () ->
379-
Lwt_chan.flush post_in_ch >>= fun () ->
397+
Lwt_io.flush post_in_ch >>= fun () ->
380398
Lwt_unix.close post_in
381399
))
382400
(*XXX Check possible errors! *)
@@ -391,9 +409,9 @@ let recupere_cgi head re doc_root filename ri hostname =
391409

392410
(* A thread listening the error output of the CGI script
393411
and writing them in warnings.log *)
394-
let err_channel = Lwt_chan.in_channel_of_descr err_out in
412+
let err_channel = Lwt_io.of_fd ~mode:Lwt_io.input err_out in
395413
let rec get_errors () =
396-
Lwt_chan.input_line err_channel >>= fun err ->
414+
lwt_chan_input_line err_channel >>= fun err ->
397415
Lwt_log.ign_warning ~section err;
398416
get_errors ()
399417
in ignore

src/extensions/ocsipersist-dbm/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
include ../../../Makefile.config
22

3-
PACKAGE := ${LWT_PREEMPTIVE_PACKAGE} \
4-
lwt.unix \
5-
tyxml.parser \
6-
dbm \
3+
PACKAGE := lwt.unix lwt_log tyxml.parser dbm
74

85
LIBS := -I ../../baselib -I ../../http -I ../../server \
96
${addprefix -package ,${PACKAGE}}

src/extensions/ocsipersist-dbm/ocsidbm.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ let _ = Unix.setsid ()
198198
(** Communication functions: *)
199199

200200
let send outch v =
201-
Lwt_chan.output_value outch v >>=
202-
(fun () -> Lwt_chan.flush outch)
201+
Lwt_io.write_value outch v >>= fun () ->
202+
Lwt_io.flush outch
203203

204204
let execute outch =
205205
let handle_errors f = try f () with e -> send outch (Error e) in
@@ -241,9 +241,9 @@ let execute outch =
241241
let nb_clients = ref 0
242242

243243
let rec listen_client inch outch =
244-
Lwt_chan.input_value inch >>=
245-
(fun v -> execute outch v) >>=
246-
(fun () -> listen_client inch outch)
244+
Lwt_io.read_value inch >>= fun v ->
245+
execute outch v >>= fun () ->
246+
listen_client inch outch
247247

248248
let finish _ =
249249
nb_clients := !nb_clients - 1;
@@ -260,8 +260,8 @@ let rec loop socket =
260260
ignore (
261261
b := true;
262262
nb_clients := !nb_clients + 1;
263-
let inch = Lwt_chan.in_channel_of_descr indescr in
264-
let outch = Lwt_chan.out_channel_of_descr indescr in
263+
let inch = Lwt_io.of_fd ~mode:Lwt_io.input indescr in
264+
let outch = Lwt_io.of_fd ~mode:Lwt_io.output indescr in
265265
catch
266266
(fun () -> listen_client inch outch >>= finish)
267267
finish);
@@ -344,4 +344,3 @@ let _ = Lwt_main.run
344344
in ignore (f ())
345345
346346
*)
347-

src/extensions/ocsipersist-dbm/ocsipersist.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ let init_fun config =
151151
Lwt_log.ign_warning ~section "Initializing ...");
152152
let indescr = get_indescr 2 in
153153
if delay_loading then (
154-
inch := (indescr >>= fun r -> return (Lwt_chan.in_channel_of_descr r));
155-
outch := (indescr >>= fun r -> return (Lwt_chan.out_channel_of_descr r));
154+
inch := Lwt.map (Lwt_io.of_fd ~mode:Lwt_io.input) indescr;
155+
outch := Lwt.map (Lwt_io.of_fd ~mode:Lwt_io.output) indescr;
156156
) else (
157157
let r = Lwt_main.run indescr in
158-
inch := return (Lwt_chan.in_channel_of_descr r);
159-
outch := return (Lwt_chan.out_channel_of_descr r);
158+
inch := Lwt.return (Lwt_io.of_fd ~mode:Lwt_io.input r);
159+
outch := Lwt.return (Lwt_io.of_fd ~mode:Lwt_io.output r);
160160
Lwt_log.ign_warning ~section "...Initialization complete";
161161
)
162162

@@ -171,9 +171,9 @@ let send =
171171
!inch >>= fun inch ->
172172
!outch >>= fun outch ->
173173
previous :=
174-
(Lwt_chan.output_value outch v >>= fun () ->
175-
Lwt_chan.flush outch >>= fun () ->
176-
Lwt_chan.input_value inch);
174+
(Lwt_io.write_value outch v >>= fun () ->
175+
Lwt_io.flush outch >>= fun () ->
176+
Lwt_io.read_value inch);
177177
!previous)
178178

179179
let db_get (store, name) =

0 commit comments

Comments
 (0)