Skip to content

Commit 430494e

Browse files
committed
Manual changes
1 parent dc6680b commit 430494e

16 files changed

+60
-64
lines changed

src/lib/client/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
logs.browser
2929
cohttp
3030
tyxml
31-
reactiveData)
31+
reactiveData
32+
eio)
3233
(foreign_stubs
3334
(language c)
3435
(names eliom_stubs))

src/lib/eliom_comet.client.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ module Configuration = struct
170170
let () =
171171
Fiber.any
172172
[ (fun () -> Js_of_ocaml_lwt.Lwt_js.sleep t)
173-
; (fun () ->
174-
!
175-
(* TODO: lwt-to-direct-style: This computation might not be suspended correctly. *)
176-
update_configuration_waiter)
173+
; (fun () -> Promise.await !update_configuration_waiter)
177174
; active_waiter ]
178175
in
179176
let remaining_time = sleep_duration () -. (Sys.time () -. time) in

src/lib/eliom_common.server.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ type 'a cookie_info1 =
242242
(* None = new cookie
243243
(not sent by the browser) *)
244244
* one_persistent_cookie_info session_cookie ref)
245-
Promise.t
246245
(* SCNo_data = the session has been closed
247246
SCData_session_expired = the cookie has not been found in the table.
248247
For both of them, ask the browser to remove the cookie.
@@ -300,7 +299,8 @@ let network_of_ip k mask4 mask6 =
300299

301300
let network_of_request r ~mask4 ~mask6 =
302301
match Ocsigen_request.client_conn r with
303-
| `Inet (ip, _) -> network_of_ip ip mask4 mask6
302+
| `Inet (ip, _) ->
303+
network_of_ip (Ipaddr.of_string_exn (ip :> string)) mask4 mask6
304304
| _ -> Ipaddr.(V6 V6.localhost)
305305

306306
module Net_addr_Hashtbl : sig
@@ -831,7 +831,7 @@ let empty_tables max forsession =
831831
Ocsigen_request.client_conn
832832
sp.sp_request.Ocsigen_extensions.request_info
833833
with
834-
| `Inet (ip, _) -> ip
834+
| `Inet (ip, _) -> Ipaddr.of_string_exn (ip :> string)
835835
| _ -> default_ip_table_key
836836
in
837837
( ip

src/lib/eliom_common.server.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ type 'a cookie_info1 =
360360
ref
361361
* ((string * timeout * float option * perssessgrp option) option
362362
* one_persistent_cookie_info session_cookie ref)
363-
Promise.t
364363
Lazy.t
365364
Full_state_name_table.t
366365
ref

src/lib/eliom_cscache.eliom

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
open Eio.Std
1+
open%server Eio.Std
22

33
(* Copyright Vincent Balat *)
44

55
[%%shared.start]
66

7-
type ('a, 'b) t = (unit -> ('a, 'b Promise.t) Hashtbl.t) Eliom_shared.Value.t
7+
type ('a, 'b) t = (unit -> ('a, 'b Promise.or_exn) Hashtbl.t) Eliom_shared.Value.t
88

99
let%client create_ () =
1010
let c = Hashtbl.create 100 in
@@ -37,26 +37,27 @@ let%server do_cache cache id v =
3737
ignore [%client.unsafe (do_cache ~%cache ~%id ~%v : unit)]
3838

3939
let%server find cache get_data id =
40-
try Hashtbl.find ((Eliom_shared.Value.local cache) ()) id
40+
try Promise.await_exn (Hashtbl.find ((Eliom_shared.Value.local cache) ()) id)
4141
with Not_found ->
4242
let th =
43-
let v = get_data id in
44-
ignore [%client.unsafe (do_cache ~%cache ~%id ~%v : unit)];
45-
v
43+
Fiber.fork_promise
44+
~sw:(Stdlib.Option.get (Fiber.get Ocsigen_lib.current_switch))
45+
(fun () ->
46+
let v = get_data id in
47+
ignore [%client.unsafe (do_cache ~%cache ~%id ~%v : unit)];
48+
v)
4649
in
47-
(* On server side, we put immediately in table the thread that is
48-
fetching the data. in order to avoid fetching it several
49-
times. *)
50-
do_cache_raw cache id th;
51-
th
50+
(* On server side, we put immediately in table the thread that is fetching
51+
the data. in order to avoid fetching it several times. *)
52+
do_cache_raw cache id th; Promise.await_exn th
5253

5354
let%client load cache get_data id =
5455
let th = get_data id in
5556
(* On client side, we put immediately in table the thread that is
5657
fetching the data. Thus, [get_data_from_cache] returns
5758
immediately (in order to display a spinner). *)
5859
do_cache_raw cache id th;
59-
th
60+
Promise.await_exn th
6061

6162
let%client find cache get_data id =
6263
try Hashtbl.find ((Eliom_shared.Value.local cache) ()) id
@@ -68,4 +69,7 @@ let local_find cache id = Hashtbl.find ((Eliom_shared.Value.local cache) ()) id
6869

6970
let find_if_ready cache id =
7071
let v = local_find cache id in
71-
match Promise.peek v with Some v -> v | _ -> raise Not_ready
72+
match Promise.peek v with
73+
| Some (Ok v) -> v
74+
| Some (Error e) -> raise e
75+
| _ -> raise Not_ready

src/lib/eliom_cscache.eliomi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ val find : ('a, 'b) t -> ('a -> 'b) -> 'a -> 'b
4040
result in a single call to [get_from_db]. Exceptions are not
4141
cached. *)
4242

43-
val do_cache : ('a, 'b) t -> 'a -> 'b -> unit
43+
val do_cache : ('a, 'b) t -> 'a -> 'b Eio.Promise.or_exn -> unit
4444
(** [do_cache cache key value] adds the association from [key] to
4545
[value] in [cache], or replaces it if not already present. Called
4646
from client side, it affects only client side cache. Called from
4747
server side, it will have effect both on the server cache (scope:
4848
request) and the client side cache. *)
4949

50-
val local_find : ('a, 'b) t -> 'a -> 'b
50+
val local_find : ('a, 'b) t -> 'a -> 'b Eio.Promise.or_exn
5151
(** Find a piece of data in local cache, without trying to fetch it
5252
from server. Raises [Not_found] instead. If the value is currently
5353
being retrieved, it waits for it to be ready before returning. *)

src/lib/eliom_form.eliom

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
open Eio.Std
2-
31
(* Ocsigen
42
* http://www.ocsigen.org
53
* Module Eliom_form
@@ -124,6 +122,7 @@ module Make_links (Html : Html) = struct
124122
let f =
125123
[%client.unsafe
126124
fun ev ->
125+
let open Eio.Std in
127126
if not (Eliom_client.middleClick ev) then (
128127
Dom.preventDefault ev;
129128
Dom_html.stopPropagation ev;

src/lib/eliom_parameter.server.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
include
2121
Eliom_parameter_sigs.S
2222
with type raw_post_data =
23-
((string * string) * (string * string) list) option * Cohttp_lwt.Body.t
23+
((string * string) * (string * string) list) option * Cohttp_eio.Body.t
2424

2525
val user_type :
2626
?client_to_and_of:'a to_and_of Eliom_client_value.t

src/lib/eliom_parameter_sigs.shared.mli

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
open Eio.Std
2-
31
(* Ocsigen
42
* http://www.ocsigen.org
53
* Copyright (C) 2007-2016 Vincent Balat
@@ -379,8 +377,8 @@ module type S = sig
379377
val reconstruct_params :
380378
sp:Eliom_common.server_params
381379
-> ('a, [< `WithSuffix | `WithoutSuffix], 'c) params_type
382-
-> (string * string) list Promise.t option
383-
-> (string * Eliom_lib.file_info) list Promise.t option
380+
-> (string * string) list option
381+
-> (string * Eliom_lib.file_info) list option
384382
-> bool
385383
-> Eliom_lib.Url.path option
386384
-> 'a

src/lib/eliom_reference.server.ml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
open Eio.Std
2-
31
(* Ocsigen
42
* http://www.ocsigen.org
53
* Copyright (C) 2010 Vincent Balat
@@ -29,16 +27,16 @@ module Ocsipersist = struct
2927
include Eliom_common.Ocsipersist.Polymorphic
3028
end
3129

32-
let pers_ref_store = Ocsipersist.open_store "eliom__persistent_refs"
30+
let pers_ref_store = lazy (Ocsipersist.open_store "eliom__persistent_refs")
3331

3432
type 'a eref_kind =
3533
| Req of 'a Polytables.key
3634
| Sit of 'a Polytables.key
3735
| Ref of 'a lazy_t ref (* Ocaml reference *)
3836
| Vol of 'a volatile_table Lazy.t (* Vol. table (group, session, process) *)
39-
| Ocsiper of 'a option Ocsipersist.t Promise.t (* Global persist. table *)
40-
| Ocsiper_sit of 'a Ocsipersist.table Promise.t (* Persist. table for site *)
41-
| Per of 'a persistent_table Promise.t
37+
| Ocsiper of 'a option Ocsipersist.t Lazy.t (* Global persist. table *)
38+
| Ocsiper_sit of 'a Ocsipersist.table Lazy.t (* Persist. table for site *)
39+
| Per of 'a persistent_table Lazy.t
4240
(* Persist. table for group session or process *)
4341

4442
type volatile = [`Volatile]
@@ -175,18 +173,20 @@ let eref_from_fun_ ~ext ~scope ?secure ?persistent f : 'a eref =
175173
( f
176174
, ext
177175
, Ocsiper
178-
(let store = pers_ref_store in
179-
Ocsipersist.make_persistent ~store ~name ~default:None) ))
176+
(lazy
177+
(let (lazy store) = pers_ref_store in
178+
Ocsipersist.make_persistent ~store ~name ~default:None)) ))
180179
| `Site -> (
181180
match persistent with
182181
| None -> (Volatile.eref_from_fun_ ~ext ~scope ?secure f :> _ eref)
183182
| Some name ->
184183
(*VVV!!! ??? CHECK! *)
185-
f, ext, Ocsiper_sit (Ocsipersist.open_table name))
184+
f, ext, Ocsiper_sit (lazy (Ocsipersist.open_table name)))
186185
| #Eliom_common.user_scope as scope -> (
187186
match persistent with
188187
| None -> (Volatile.eref_from_fun_ ~ext ~scope ?secure f :> _ eref)
189-
| Some name -> f, ext, Per (create_persistent_table ~scope ?secure name))
188+
| Some name ->
189+
f, ext, Per (lazy (create_persistent_table ~scope ?secure name)))
190190

191191
let eref_from_fun ~scope ?secure ?persistent f : 'a eref =
192192
eref_from_fun_ ~ext:false ~scope ?secure ?persistent f
@@ -202,23 +202,23 @@ let get_site_id () =
202202
let get ((f, _, table) as eref) =
203203
match table with
204204
| Per t -> (
205-
let t = t in
205+
let (lazy t) = t in
206206
match get_persistent_data ~table:t () with
207207
| Data d -> d
208208
| _ ->
209209
let value = f () in
210210
set_persistent_data ~table:t value;
211211
value)
212212
| Ocsiper r -> (
213-
let r = r in
213+
let (lazy r) = r in
214214
match Ocsipersist.get r with
215215
| Some v -> v
216216
| None ->
217217
let value = f () in
218218
Ocsipersist.set r (Some value);
219219
value)
220220
| Ocsiper_sit t -> (
221-
let t = t in
221+
let (lazy t) = t in
222222
let site_id = get_site_id () in
223223
try Ocsipersist.find t site_id
224224
with Not_found ->
@@ -230,13 +230,13 @@ let get ((f, _, table) as eref) =
230230
let set ((_, _, table) as eref) value =
231231
match table with
232232
| Per t ->
233-
let t = t in
233+
let (lazy t) = t in
234234
set_persistent_data ~table:t value
235235
| Ocsiper r ->
236-
let r = r in
236+
let (lazy r) = r in
237237
Ocsipersist.set r (Some value)
238238
| Ocsiper_sit t ->
239-
let t = t in
239+
let (lazy t) = t in
240240
Ocsipersist.add t (get_site_id ()) value
241241
| _ -> Volatile.set eref value
242242

@@ -247,13 +247,13 @@ let modify eref f =
247247
let unset ((_, _, table) as eref) =
248248
match table with
249249
| Per t ->
250-
let t = t in
250+
let (lazy t) = t in
251251
remove_persistent_data ~table:t ()
252252
| Ocsiper r ->
253-
let r = r in
253+
let (lazy r) = r in
254254
Ocsipersist.set r None
255255
| Ocsiper_sit t ->
256-
let t = t in
256+
let (lazy t) = t in
257257
Ocsipersist.remove t (get_site_id ())
258258
| _ -> Volatile.unset eref
259259

@@ -263,7 +263,7 @@ module Ext = struct
263263
match table with
264264
| Vol _ -> Volatile.Ext.get state r
265265
| Per t -> (
266-
let t = t in
266+
let (lazy t) = t in
267267
try Eliom_state.Ext.Low_level.get_persistent_data ~state ~table:t with
268268
| Not_found ->
269269
if ext (* We can run the function from another state *)
@@ -281,7 +281,7 @@ module Ext = struct
281281
match table with
282282
| Vol _ -> Volatile.Ext.set state r value
283283
| Per t ->
284-
let t = t in
284+
let (lazy t) = t in
285285
Eliom_state.Ext.Low_level.set_persistent_data ~state ~table:t value
286286
| _ -> raise (Failure "wrong eref for this function")
287287

@@ -294,7 +294,7 @@ module Ext = struct
294294
match table with
295295
| Vol _ -> Volatile.Ext.unset state r
296296
| Per t ->
297-
let t = t in
297+
let (lazy t) = t in
298298
Eliom_state.Ext.Low_level.remove_persistent_data ~state ~table:t
299299
| _ -> failwith "wrong eref for this function"
300300
end

0 commit comments

Comments
 (0)