Skip to content

Commit

Permalink
Remove SHUTDOWNABLE signature
Browse files Browse the repository at this point in the history
This follows the clarification that `V1_LWT.close` follows the behaviour
of the Mirage tcp/ip stack i.e. it signals a "shutdown" to the remote
(like sending an `Eof`) while leaving the resources allocated and
the connection up. Implementations which associate extra resources with
a connection (such as a file descriptor or socket buffers) need provide
some other cleanup method (e.g. a `disconnect` function)

Fixes mirage#16

Signed-off-by: David Scott <dave@recoil.org>
  • Loading branch information
djs55 committed Jun 22, 2016
1 parent b91514c commit 118e382
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/mirage_flow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ val copy:

val proxy:
(module V1.CLOCK)
-> (module Mirage_flow_s.SHUTDOWNABLE with type flow = 'a) -> 'a
-> (module Mirage_flow_s.SHUTDOWNABLE with type flow = 'b) -> 'b
-> (module V1_LWT.FLOW with type flow = 'a) -> 'a
-> (module V1_LWT.FLOW with type flow = 'b) -> 'b
-> unit -> [ `Ok of (CopyStats.t * CopyStats.t) | `Error of [ `Msg of string ] ] Lwt.t
(** [proxy (module Clock) (module A) a (module B) b ()] proxies data between
[a] and [b] until both sides close. If either direction encounters an error
Expand Down
14 changes: 4 additions & 10 deletions lib/mirage_flow_proxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
open Lwt

let proxy (module Clock: V1.CLOCK)
(type a) (module A: Mirage_flow_s.SHUTDOWNABLE with type flow = a) (a: a)
(type b) (module B: Mirage_flow_s.SHUTDOWNABLE with type flow = b) (b: b)
(type a) (module A: V1_LWT.FLOW with type flow = a) (a: a)
(type b) (module B: V1_LWT.FLOW with type flow = b) (b: b)
() =
let a2b =
let t = Mirage_flow_copy.start (module Clock) (module A) a (module B) b () in
Mirage_flow_copy.wait t
>>= fun result ->
A.shutdown_read a
>>= fun () ->
B.shutdown_write b
>>= fun () ->
let _ = B.close b in (* signal Eof to the remote *)
let stats = Mirage_flow_copy.stats t in
match result with
| `Ok () -> return (`Ok stats)
Expand All @@ -36,10 +33,7 @@ let proxy (module Clock: V1.CLOCK)
let t = Mirage_flow_copy.start (module Clock) (module B) b (module A) a () in
Mirage_flow_copy.wait t
>>= fun result ->
B.shutdown_read b
>>= fun () ->
A.shutdown_write a
>>= fun () ->
let _ = A.close a in (* signal Eof to the remote *)
let stats = Mirage_flow_copy.stats t in
match result with
| `Ok () -> return (`Ok stats)
Expand Down
14 changes: 6 additions & 8 deletions lib/mirage_flow_s.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(*
* Copyright (C) 2015 David Scott <dave.scott@unikernel.com>
* Copyright (C) 2016 Docker Inc
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -15,14 +16,11 @@
*
*)

module type SHUTDOWNABLE = sig
module type DISCONNECTABLE = sig
include V1_LWT.FLOW

val shutdown_write: flow -> unit io
(** Close the [write] direction of the flow, flushing any buffered data and
causing future calls to [read] by the peer to return [`Eof]. *)

val shutdown_read: flow -> unit io
(** Close the [read] direction of the flow, such that future calls to [write]
by the peer will return [`Eof] *)
val disconnect: flow -> unit io
(** Close the flow and immediately release any local resources allocated for
it. This will drop any remaining in-flight data (see [close] for more
graceful shutdown) *)
end

0 comments on commit 118e382

Please sign in to comment.