Skip to content

Commit b7f2b7b

Browse files
committed
Adapt to janestreet 0.17 series
1 parent bbff936 commit b7f2b7b

File tree

12 files changed

+89
-82
lines changed

12 files changed

+89
-82
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.12.0
2+
3+
* Adapt to Janestreet's 0.17 series.
4+
15
# 0.11.0
26

37
* Forward a server context object to all http services. This can be used to lookup peer-socket address and ssl details (if using ssl) for the underlying connection.

dune-project

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(generate_opam_files true)
66

77
(source
8-
(sourcehut soni/shuttle_http))
8+
(github anuragsoni/shuttle_http))
99

1010
(maintainers "Anurag Soni <anurag@sonianurag.com>")
1111

@@ -22,19 +22,21 @@
2222
"Shuttle_http is a low level library for implementing HTTP/1.1 web services and clients in OCaml.")
2323
(depends
2424
(async
25-
(>= v0.16.0))
25+
(>= v0.17.0))
26+
(async_log
27+
(>= v0.17.0))
2628
(async_ssl
27-
(>= v0.16.0))
29+
(>= v0.17.0))
2830
(core
29-
(>= v0.16.0))
31+
(>= v0.17.0))
3032
(jane_rope
31-
(>= v0.16.0))
33+
(>= v0.17.0))
3234
(ocaml
33-
(>= 4.14.0))
35+
(>= 5.1.0))
3436
(ppx_jane
35-
(>= v0.16.0))
37+
(>= v0.17.0))
3638
(re2
37-
(>= v0.16.0))
39+
(>= v0.17.0))
3840
(core_unix :with-test)))
3941

4042
(package

http/src/client.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ module Connection = struct
232232
in
233233
match verification_result with
234234
| Error err ->
235-
Ivar.fill ivar (Error err);
235+
Ivar.fill_exn ivar (Error err);
236236
Deferred.unit
237237
| Ok () ->
238238
let conn = { reader; writer; address } in
239239
let t = Sequencer.create conn in
240240
Throttle.at_kill t (fun conn ->
241241
let%bind () = Output_channel.close conn.writer in
242242
Input_channel.close conn.reader);
243-
Ivar.fill ivar (Ok t);
243+
Ivar.fill_exn ivar (Ok t);
244244
closed t));
245245
Ivar.read ivar)
246246
;;
@@ -277,7 +277,7 @@ module Connection = struct
277277
let response = Response0.with_body response body in
278278
if not (Response.keep_alive response && Request.keep_alive request)
279279
then close t;
280-
Ivar.fill ivar response;
280+
Ivar.fill_exn ivar response;
281281
(match Response.body response with
282282
| Body.Fixed _ | Empty -> return (`Finished ())
283283
| Stream stream ->

http/src/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
(public_name shuttle_http)
33
(preprocess
44
(pps ppx_jane))
5-
(libraries core async re2 async_ssl jane_rope))
5+
(libraries core async re2 async_ssl jane_rope async_log))

http/src/input_channel0.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let close t =
4545
if not t.is_closed
4646
then (
4747
t.is_closed <- true;
48-
Fd.close t.fd >>> fun () -> Ivar.fill t.closed ());
48+
Fd.close t.fd >>> fun () -> Ivar.fill_exn t.closed ());
4949
closed t
5050
;;
5151

http/src/output_channel.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open! Core
22
open! Async_kernel
33
open Async_unix
4-
module Logger : Log.Global_intf
4+
module Logger : Async_log.Global.S
55

66
type t [@@deriving sexp_of]
77

http/src/output_channel0.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open! Async_kernel
33
open Async_unix
44
module Unix = Core_unix
55
open! Async_kernel_require_explicit_time_source
6-
module Logger = Log.Make_global ()
6+
module Logger = Async_log.Global.Make ()
77

88
module Flush_result = struct
99
type t =
@@ -86,7 +86,7 @@ let create ?max_buffer_size ?buf_len ?write_timeout ?time_source fd =
8686

8787
let wakeup_flushes_with_error t error =
8888
while not (Queue.is_empty t.flushes) do
89-
Ivar.fill (Queue.dequeue_exn t.flushes).ivar error
89+
Ivar.fill_exn (Queue.dequeue_exn t.flushes).ivar error
9090
done
9191
;;
9292

@@ -125,14 +125,14 @@ let close' t =
125125
| Closed | Start_close -> ()
126126
| Open ->
127127
t.close_state <- Start_close;
128-
Ivar.fill t.close_started ();
128+
Ivar.fill_exn t.close_started ();
129129
Deferred.any_unit
130130
[ Time_source.after t.time_source (Time_ns.Span.of_sec 5.)
131131
; Deferred.ignore_m (flushed_or_fail t)
132132
]
133133
>>> fun () ->
134134
t.close_state <- Closed;
135-
Fd.close t.fd >>> fun () -> Ivar.fill t.close_finished ()
135+
Fd.close t.fd >>> fun () -> Ivar.fill_exn t.close_finished ()
136136
;;
137137

138138
let close t =
@@ -155,7 +155,7 @@ let dequeue_flushes t =
155155
(not (Queue.is_empty t.flushes))
156156
&& Int63.( <= ) (Queue.peek_exn t.flushes).pos t.bytes_written
157157
do
158-
Ivar.fill (Queue.dequeue_exn t.flushes).ivar Flush_result.Flushed
158+
Ivar.fill_exn (Queue.dequeue_exn t.flushes).ivar Flush_result.Flushed
159159
done
160160
;;
161161

@@ -187,7 +187,7 @@ let rec write_everything t =
187187
else (
188188
match write_nonblocking t with
189189
| `Eof ->
190-
Ivar.fill t.remote_closed ();
190+
Ivar.fill_exn t.remote_closed ();
191191
stop_writer t Flush_result.Remote_closed
192192
| `Poll_again -> wait_and_write_everything t
193193
| `Ok n ->
@@ -293,7 +293,7 @@ let write_from_pipe t reader =
293293
then (
294294
(* use [read_now'] as [iter] doesn't allow working on chunks of values at a time. *)
295295
match Pipe.read_now' ~consumer reader with
296-
| `Eof -> Ivar.fill finished ()
296+
| `Eof -> Ivar.fill_exn finished ()
297297
| `Nothing_available -> Pipe.values_available reader >>> fun _ -> loop ()
298298
| `Ok bufs ->
299299
Queue.iter bufs ~f:(fun buf -> write t buf);

http/src/server.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open! Core
22
open! Async
3-
module Logger = Log.Make_global ()
3+
module Logger = Async_log.Global.Make ()
44
module Ssl_conn = Ssl
55

66
module Ssl = struct
@@ -109,7 +109,7 @@ type 'a t =
109109
type 'addr service = 'addr t -> Request.t -> Response.t Deferred.t [@@deriving sexp_of]
110110

111111
let closed t = Ivar.read t.closed
112-
let close t = if Ivar.is_empty t.closed then Ivar.fill t.closed ()
112+
let close t = if Ivar.is_empty t.closed then Ivar.fill_exn t.closed ()
113113
let is_ssl t = Option.is_some t.ssl
114114

115115
let ssl_peer_certificate t =
@@ -179,14 +179,14 @@ let run_server_loop t handler =
179179
| Error Partial ->
180180
Input_channel.refill t.reader
181181
>>> (function
182-
| `Eof -> Ivar.fill t.closed ()
183-
| `Ok -> parse_request t)
182+
| `Eof -> Ivar.fill_exn t.closed ()
183+
| `Ok -> parse_request t)
184184
| Error (Fail error) ->
185185
t.error_handler ~exn:(Error.to_exn error) `Bad_request
186186
>>> fun response ->
187187
(write_response t response;
188188
Io_util.write_body (Response.body response) t.writer)
189-
>>> fun () -> Ivar.fill t.closed ()
189+
>>> fun () -> Ivar.fill_exn t.closed ()
190190
| Ok (req, consumed) ->
191191
Input_channel.consume t.reader consumed;
192192
create_request_body_reader t req
@@ -198,7 +198,7 @@ let run_server_loop t handler =
198198
Input_channel.refill_with_timeout t.reader span
199199
>>> fun v ->
200200
(match v with
201-
| `Eof -> Ivar.fill t.closed ()
201+
| `Eof -> Ivar.fill_exn t.closed ()
202202
| `Ok ->
203203
let now' = Time_ns.now () in
204204
let diff = Time_ns.abs_diff now now' in
@@ -208,7 +208,7 @@ let run_server_loop t handler =
208208
>>> fun response ->
209209
(write_response t response;
210210
Io_util.write_body (Response.body response) t.writer)
211-
>>> fun () -> Ivar.fill t.closed ()
211+
>>> fun () -> Ivar.fill_exn t.closed ()
212212
| Ok (req, consumed) ->
213213
Input_channel.consume t.reader consumed;
214214
create_request_body_reader t req
@@ -219,7 +219,7 @@ let run_server_loop t handler =
219219
>>> fun response ->
220220
(write_response t response;
221221
Io_util.write_body (Response.body response) t.writer)
222-
>>> fun () -> Ivar.fill t.closed ()
222+
>>> fun () -> Ivar.fill_exn t.closed ()
223223
| Ok req_body ->
224224
let req = Request.with_body req req_body in
225225
let promise = handler t req in
@@ -248,7 +248,7 @@ let run_server_loop t handler =
248248
| Ok () -> ()
249249
| Error exn ->
250250
Logger.error "Error while running upgrade handler: %s" (Exn.to_string exn));
251-
Ivar.fill t.closed ()
251+
Ivar.fill_exn t.closed ()
252252
| Response _ ->
253253
if is_keep_alive
254254
then (
@@ -265,7 +265,7 @@ let run_server_loop t handler =
265265
if Time_ns.Span.is_positive t.read_header_timeout
266266
then parse_request_with_timeout t t.read_header_timeout
267267
else parse_request t)
268-
else Ivar.fill t.closed ()
268+
else Ivar.fill_exn t.closed ()
269269
in
270270
Monitor.detach t.monitor;
271271
Scheduler.within ~priority:Priority.normal ~monitor:t.monitor (fun () ->
@@ -281,7 +281,7 @@ let run_server_loop t handler =
281281
then
282282
(write_response t response;
283283
Io_util.write_body (Response.body response) t.writer)
284-
>>> fun () -> Ivar.fill t.closed ());
284+
>>> fun () -> Ivar.fill_exn t.closed ());
285285
Ivar.read t.closed
286286
;;
287287

http/src/server.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open! Core
22
open! Async
3-
module Logger : Log.Global_intf
3+
module Logger : Async_log.Global.S
44

55
(** [error_handler] can be used to customize how the server deals with any unhandled
66
exceptions. A default implementation is provided that will respond with a status code

http/src/tcp_channel.ml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ let listen
3737
~on_handler_error
3838
where_to_listen
3939
(fun addr socket ->
40-
let fd = Socket.fd socket in
41-
let input_channel =
42-
Input_channel.create ?max_buffer_size ?buf_len ?time_source fd
43-
in
44-
let output_channel =
45-
Output_channel.create ?max_buffer_size ?buf_len ?write_timeout ?time_source fd
46-
in
47-
let%bind res =
48-
Deferred.any
49-
[ collect_errors output_channel (fun () ->
50-
handler addr input_channel output_channel)
51-
; Output_channel.remote_closed output_channel |> Deferred.ok
52-
]
53-
in
54-
let%bind () = close_channels input_channel output_channel in
55-
match res with
56-
| Ok () -> Deferred.unit
57-
| Error exn -> raise exn)
40+
let fd = Socket.fd socket in
41+
let input_channel =
42+
Input_channel.create ?max_buffer_size ?buf_len ?time_source fd
43+
in
44+
let output_channel =
45+
Output_channel.create ?max_buffer_size ?buf_len ?write_timeout ?time_source fd
46+
in
47+
let%bind res =
48+
Deferred.any
49+
[ collect_errors output_channel (fun () ->
50+
handler addr input_channel output_channel)
51+
; Output_channel.remote_closed output_channel |> Deferred.ok
52+
]
53+
in
54+
let%bind () = close_channels input_channel output_channel in
55+
match res with
56+
| Ok () -> Deferred.unit
57+
| Error exn -> raise exn)
5858
;;
5959

6060
let listen_inet
@@ -79,24 +79,24 @@ let listen_inet
7979
~on_handler_error
8080
where_to_listen
8181
(fun addr socket ->
82-
let fd = Socket.fd socket in
83-
let input_channel =
84-
Input_channel.create ?max_buffer_size ?buf_len ?time_source fd
85-
in
86-
let output_channel =
87-
Output_channel.create ?max_buffer_size ?buf_len ?write_timeout ?time_source fd
88-
in
89-
let%bind res =
90-
Deferred.any
91-
[ collect_errors output_channel (fun () ->
92-
handler addr input_channel output_channel)
93-
; Output_channel.remote_closed output_channel |> Deferred.ok
94-
]
95-
in
96-
let%bind () = close_channels input_channel output_channel in
97-
match res with
98-
| Ok () -> Deferred.unit
99-
| Error exn -> raise exn)
82+
let fd = Socket.fd socket in
83+
let input_channel =
84+
Input_channel.create ?max_buffer_size ?buf_len ?time_source fd
85+
in
86+
let output_channel =
87+
Output_channel.create ?max_buffer_size ?buf_len ?write_timeout ?time_source fd
88+
in
89+
let%bind res =
90+
Deferred.any
91+
[ collect_errors output_channel (fun () ->
92+
handler addr input_channel output_channel)
93+
; Output_channel.remote_closed output_channel |> Deferred.ok
94+
]
95+
in
96+
let%bind () = close_channels input_channel output_channel in
97+
match res with
98+
| Ok () -> Deferred.unit
99+
| Error exn -> raise exn)
100100
;;
101101

102102
let with_connection

0 commit comments

Comments
 (0)