Skip to content

WIP: Transition from Lwt to Eio #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ INCS= -I ${BLD}/server/.ocsigenserver.objs/byte \
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
## but also to generate src/baselib/ocsigen_config_static.ml

SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,logs,logs-syslog,syslog-message,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix,http
SERVER_PACKAGE := bytes,logs,logs-syslog.unix,syslog-message,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-eio,http,eio,eio_main,ipaddr.unix,magic-mime

LIBS := -package ${SERVER_PACKAGE} ${INCS}
8 changes: 3 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,13 @@ check_ocamlversion
check_binary ocamlfind "See: http://projects.camlcity.org/projects/findlib.html"

check_library cohttp "See: https://github.com/mirage/ocaml-cohttp"
check_library cohttp-lwt-unix "Missing support for 'lwt' in cohttp."
check_library cohttp-eio "Missing support for 'eio' in cohttp."
check_library react "See: http://erratique.ch/software/react"
check_library ssl "See: http://sourceforge.net/projects/savonet/files/ocaml-ssl"
check_library http ""

check_library lwt "See: http://ocsigen.org/lwt"
check_library lwt.unix "Missing support for 'unix' in lwt."
check_library lwt_react "See: http://ocsigen.org/lwt"
check_library lwt_ssl "See: http://ocsigen.org/lwt"
check_library eio ""
check_library eio_main ""
check_library logs ""
check_library logs-syslog "Missing syslog support."

Expand Down
9 changes: 5 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
(depends
(ocaml (>= 4.08.1))
(camlzip (>= 1.04))
(cohttp-lwt-unix (and (>= 5.0) (< 6.0)))
(conduit-lwt-unix (and (>= 2.0) (< 7.0)))
(cohttp-eio (>= 6.0.0))
http
cryptokit
(ipaddr (>= 2.1))
(lwt (>= 3.0))
(eio (>= 0.13))
eio_main
lwt_react
lwt_ssl
ocamlfind
Expand All @@ -33,6 +33,7 @@
xml-light
logs
logs-syslog
syslog-message)
syslog-message
magic-mime)
(conflicts
(pgocaml (< 2.2))))
7 changes: 4 additions & 3 deletions ocsigenserver.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ depends: [
"dune" {>= "3.19"}
"ocaml" {>= "4.08.1"}
"camlzip" {>= "1.04"}
"cohttp-lwt-unix" {>= "5.0" & < "6.0"}
"conduit-lwt-unix" {>= "2.0" & < "7.0"}
"cohttp-eio" {>= "6.0.0"}
"http"
"cryptokit"
"ipaddr" {>= "2.1"}
"lwt" {>= "3.0"}
"eio" {>= "0.13"}
"eio_main"
"lwt_react"
"lwt_ssl"
"ocamlfind"
Expand All @@ -29,6 +29,7 @@ depends: [
"logs"
"logs-syslog"
"syslog-message"
"magic-mime"
"odoc" {with-doc}
]
conflicts: [
Expand Down
6 changes: 4 additions & 2 deletions src/baselib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(flags
(:standard -no-keep-locs))
(modules ocsigen_lib_base)
(libraries lwt))
(libraries eio eio.unix))

(library
(name baselib)
Expand All @@ -22,10 +22,12 @@
(libraries
str
findlib
lwt.unix
eio
cryptokit
re
ocsigen_lib_base
cohttp
cohttp-eio
logs
(select
dynlink_wrapper.ml
Expand Down
29 changes: 16 additions & 13 deletions src/baselib/ocsigen_cache.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Eio.Std

(* Ocsigen
* Copyright (C) 2009
*
Expand All @@ -22,8 +24,6 @@
@author Raphaël Proust (adding timers)
*)

open Lwt.Infix

module Dlist : sig
type 'a t
type 'a node
Expand Down Expand Up @@ -120,7 +120,8 @@ end = struct
; mutable finaliser_after : 'a node -> unit
; time_bound : time_bound option }

and time_bound = {timer : float; mutable collector : unit Lwt.t option}
and time_bound =
{timer : float; mutable collector : (unit, exn) result Promise.t option}

(* Checks (by BY):

Expand Down Expand Up @@ -214,7 +215,7 @@ end = struct
| None -> assert false (* collection is set to None and collector to Some *)
| Some t ->
let duration = t -. Unix.gettimeofday () in
if duration <= 0. then Lwt.return () else Lwt_unix.sleep duration
if duration <= 0. then () else Eio_unix.sleep duration

(* a function to set the collector. *)
let rec update_collector r =
Expand All @@ -227,11 +228,13 @@ end = struct
| Some n ->
t.collector <-
Some
( sleep_until n.collection >>= fun () ->
collect r n;
t.collector <- None;
update_collector r;
Lwt.return () ))
(Fiber.fork_promise
~sw:(Option.get (Fiber.get Ocsigen_lib.current_switch))
(fun () ->
sleep_until n.collection;
collect r n;
t.collector <- None;
update_collector r)))

(* Add a node that do not belong to any list to a list.
The fields [succ] and [prev] are overridden.
Expand Down Expand Up @@ -399,7 +402,7 @@ functor
type t =
{ mutable pointers : A.key Dlist.t
; mutable table : (A.value * A.key Dlist.node) H.t
; finder : A.key -> A.value Lwt.t
; finder : A.key -> A.value
; clear : unit -> unit
(* This function clears the cache. It is put inside the
cache structure so that it is garbage-collected only when the cache
Expand Down Expand Up @@ -460,14 +463,14 @@ functor
let size c = Dlist.size c.pointers

let find cache k =
try Lwt.return (find_in_cache cache k)
try find_in_cache cache k
with Not_found ->
cache.finder k >>= fun r ->
let r = cache.finder k in
(try
(* it may have been added during cache.finder *)
ignore (find_in_cache cache k : A.value)
with Not_found -> add_no_remove cache k r);
Lwt.return r
r

class cache f ?timer size_c =
let c = create f ?timer size_c in
Expand Down
4 changes: 2 additions & 2 deletions src/baselib/ocsigen_cache.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ module Make : functor
Using [timer] allow one to create a cache
bounded both in space and time. It is to be noted that real lifespan
of values is always slightly greater than [timer]. *)
class cache : (A.key -> A.value Lwt.t) -> ?timer:float -> int -> object
method find : A.key -> A.value Lwt.t
class cache : (A.key -> A.value) -> ?timer:float -> int -> object
method find : A.key -> A.value
(** Find the cached value associated to the key, or binds this
value in the cache using the function [finder] passed as argument
to [create], and returns this value *)
Expand Down
21 changes: 12 additions & 9 deletions src/baselib/ocsigen_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,30 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

open Eio.Std
include Ocsigen_lib_base
module String = String_base

let current_switch = Eio.Fiber.create_key ()
let env = Eio.Fiber.create_key ()

(*****************************************************************************)

module Ip_address = struct
exception No_such_host

let get_inet_addr ?(v6 = false) host =
let rec aux = function
| [] -> Lwt.fail No_such_host
| {Unix.ai_addr = Unix.ADDR_INET (inet_addr, _); _} :: _ ->
Lwt.return inet_addr
| [] -> raise No_such_host
| `Tcp (ipv4v6, _port) :: tl ->
Eio.Net.Ipaddr.fold
~v4:(fun ip -> if v6 then aux tl else ip)
~v6:(fun ip -> if v6 then ip else aux tl)
ipv4v6
| _ :: l -> aux l
in
let options =
[ (if v6
then Lwt_unix.AI_FAMILY Lwt_unix.PF_INET6
else Lwt_unix.AI_FAMILY Lwt_unix.PF_INET) ]
in
Lwt.bind (Lwt_unix.getaddrinfo host "" options) aux
let env = Stdlib.Option.get (Fiber.get env) in
(aux (Eio.Net.getaddrinfo env#net host) : _ Eio.Net.Ipaddr.t :> string)
end

(*****************************************************************************)
Expand Down
5 changes: 4 additions & 1 deletion src/baselib/ocsigen_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ include
and type 'a Clist.t = 'a Ocsigen_lib_base.Clist.t
and type 'a Clist.node = 'a Ocsigen_lib_base.Clist.node

val current_switch : Eio.Switch.t Eio.Fiber.key
val env : Eio_unix.Stdenv.base Eio.Fiber.key

val make_cryptographic_safe_string : unit -> string
(** Generate an unique and cryptographically safe random string.
It is impossible to guess for other people and
Expand All @@ -39,7 +42,7 @@ module String : module type of String_base
module Ip_address : sig
exception No_such_host

val get_inet_addr : ?v6:bool -> string -> Unix.inet_addr Lwt.t
val get_inet_addr : ?v6:bool -> string -> string
end

module Filename : sig
Expand Down
5 changes: 1 addition & 4 deletions src/baselib/ocsigen_lib_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ exception Ocsigen_Request_too_long

external id : 'a -> 'a = "%identity"

include Lwt.Infix

let ( !! ) = Lazy.force
let ( |> ) x f = f x
let ( @@ ) f x = f x
Expand All @@ -47,8 +45,7 @@ type yesnomaybe = Yes | No | Maybe
type ('a, 'b) leftright = Left of 'a | Right of 'b

let advert =
"Page generated by OCaml with Ocsigen.
See http://ocsigen.org/ and http://caml.inria.fr/ for information"
"Page generated by OCaml with Ocsigen.\nSee http://ocsigen.org/ and http://caml.inria.fr/ for information"

(*****************************************************************************)

Expand Down
2 changes: 0 additions & 2 deletions src/baselib/ocsigen_lib_base.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ exception Input_is_too_large
exception Ocsigen_Bad_Request
exception Ocsigen_Request_too_long

include module type of Lwt.Infix

val ( !! ) : 'a Lazy.t -> 'a
val ( |> ) : 'a -> ('a -> 'b) -> 'b
val ( @@ ) : ('a -> 'b) -> 'a -> 'b
Expand Down
Loading