Skip to content

Commit f4e9bd1

Browse files
committed
Add minimalist Cohttp implementation using Picos_stdio
1 parent 8c35155 commit f4e9bd1

File tree

11 files changed

+465
-18
lines changed

11 files changed

+465
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ scheduler agnostic libraries (e.g.
4444
[`picos.structured`](https://ocaml-multicore.github.io/picos/doc/picos/Picos_structured/index.html),
4545
[`picos.sync`](https://ocaml-multicore.github.io/picos/doc/picos/Picos_sync/index.html),
4646
[`picos.stdio`](https://ocaml-multicore.github.io/picos/doc/picos/Picos_stdio/index.html),
47+
[`picos.stdio.cohttp`](https://ocaml-multicore.github.io/picos/doc/picos/Picos_stdio_cohttp/index.html),
4748
and
4849
[`picos.select`](https://ocaml-multicore.github.io/picos/doc/picos/Picos_select/index.html)),
4950
or auxiliary libraries.

dune-project

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
;; For picos.lwt
4141
(lwt
4242
(>= 5.7.0))
43+
;; For picos.stdio.cohttp
44+
(cohttp
45+
(>= 6.0.0~beta2))
46+
(uri
47+
(>= 4.4.0))
48+
(fmt
49+
(>= 0.9.0))
4350
;; Test dependencies
4451
(multicore-bench
4552
(and
@@ -99,10 +106,6 @@
99106
(ocaml
100107
(>= 4.14.0)))
101108
(depopts
102-
(cohttp
103-
(and
104-
(>= 5.3.1)
105-
:with-test))
106109
(cohttp-lwt
107110
(and
108111
(>= 5.3.0)
@@ -114,8 +117,4 @@
114117
(conduit-lwt-unix
115118
(and
116119
(>= 6.2.2)
117-
:with-test))
118-
(uri
119-
(and
120-
(>= 4.4.0)
121120
:with-test))))

lib/index.mld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ These are examples of libraries implemented in Picos.
167167
Picos_structured
168168
Picos_sync
169169
Picos_stdio
170+
Picos_stdio_cohttp
170171
Picos_select
171172
}
172173

lib/picos_select/picos_select.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
open Picos
22
open Picos_sync
33

4-
let handle_sigchld_bit = 0b01
5-
let select_thread_running_on_main_domain_bit = 0b10
4+
let handle_sigchld_bit = 0b001
5+
let select_thread_running_on_main_domain_bit = 0b010
6+
let ignore_sigpipe_bit = 0b100
67

78
type config = {
89
mutable bits : int;
@@ -267,10 +268,12 @@ let select_thread s =
267268
if s.pipe_out != Unix.stdin then Unix.close s.pipe_out
268269

269270
let[@poll error] [@inline never] try_configure ~intr_sig ~intr_sigs
270-
~handle_sigchld =
271+
~handle_sigchld ~ignore_sigpipe =
271272
config.intr_sigs == []
272273
&& begin
273-
config.bits <- Bool.to_int handle_sigchld;
274+
config.bits <-
275+
Bool.to_int handle_sigchld
276+
lor (ignore_sigpipe_bit land -Bool.to_int ignore_sigpipe);
274277
config.intr_sig <- intr_sig;
275278
config.intr_sigs <- intr_sigs;
276279
true
@@ -296,17 +299,24 @@ let reconfigure_signal_handlers () =
296299
if config.bits land handle_sigchld_bit <> 0 then begin
297300
Sys.signal Sys.sigchld (Sys.Signal_handle handle_signal) |> ignore;
298301
Thread.sigmask SIG_BLOCK [ Sys.sigchld ] |> ignore
302+
end;
303+
if config.bits land ignore_sigpipe_bit <> 0 then begin
304+
Sys.signal Sys.sigpipe Signal_ignore |> ignore
299305
end
300306
end
301307

302-
let configure ?(intr_sig = Sys.sigusr2) ?(handle_sigchld = true) () =
308+
let configure ?(intr_sig = Sys.sigusr2) ?(handle_sigchld = true)
309+
?(ignore_sigpipe = true) () =
303310
if not (Picos_thread.is_main_thread ()) then
304311
invalid_arg "must be called from the main thread on the main domain";
305312
assert (Sys.sigabrt = -1 && Sys.sigxfsz < Sys.sigabrt);
306313
if intr_sig < Sys.sigxfsz || 0 <= intr_sig || intr_sig = Sys.sigchld then
307314
invalid_arg "invalid interrupt signal number";
308-
if not (try_configure ~intr_sig ~intr_sigs:[ intr_sig ] ~handle_sigchld) then
309-
invalid_arg "already configured";
315+
if
316+
not
317+
(try_configure ~intr_sig ~intr_sigs:[ intr_sig ] ~handle_sigchld
318+
~ignore_sigpipe)
319+
then invalid_arg "already configured";
310320

311321
reconfigure_signal_handlers ()
312322

lib/picos_select/picos_select.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ val on_sigchld : unit Event.t
9999

100100
(** {2 Configuration} *)
101101

102-
val configure : ?intr_sig:int -> ?handle_sigchld:bool -> unit -> unit
102+
val configure :
103+
?intr_sig:int -> ?handle_sigchld:bool -> ?ignore_sigpipe:bool -> unit -> unit
103104
(** [configure ~intr_sig ~handle_sigchld ()] can, and sometimes must, be called
104105
by an application to configure the use of signals by this module.
105106
@@ -111,6 +112,10 @@ val configure : ?intr_sig:int -> ?handle_sigchld:bool -> unit -> unit
111112
When explicitly specified as [~handle_sigchld:false], the application should
112113
arrange to call {!handle_signal} whenever a {!Sys.sigchld} signal occurs.
113114
115+
The optional [ignore_sigpipe] argument can be used to specify whether
116+
{!Sys.sigpipe} will be configured to be ignored or not. The default is
117+
[true].
118+
114119
⚠️ This module must always be configured before use. Unless this module has
115120
been explicitly configured, calling a method of this module from the main
116121
thread on the main domain will automatically configure this module with

lib/picos_stdio_cohttp/dune

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(library
2+
(name picos_stdio_cohttp)
3+
(public_name picos.stdio.cohttp)
4+
(libraries
5+
(re_export picos.stdio)
6+
(re_export cohttp)
7+
(re_export uri)
8+
fmt
9+
picos.finally
10+
picos.structured))

0 commit comments

Comments
 (0)