Skip to content

Commit

Permalink
Client: use generic_channel for Mux
Browse files Browse the repository at this point in the history
because in the future, the client may upgrade to TLS, and then Mux will
use a TLS channel converted into a generic_channel type.

Signed-off-by: Iglói Gábor <gabor.igloi@citrix.com>
  • Loading branch information
gaborigloi committed Sep 14, 2017
1 parent c5e1da3 commit d1b349f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/client.ml
Expand Up @@ -26,7 +26,7 @@ let get_handle =
this

module NbdRpc = struct
type transport = cleartext_channel
type transport = generic_channel
type id = int64
type request_hdr = Request.t
type request_body = Cstruct.t option
Expand All @@ -35,7 +35,7 @@ module NbdRpc = struct

let recv_hdr sock =
let buf = Cstruct.create 16 in
sock.read_clear buf
sock.read buf
>>= fun () ->
match Reply.unmarshal buf with
| `Ok x -> Lwt.return (Some x.Reply.handle, x)
Expand All @@ -48,7 +48,7 @@ module NbdRpc = struct
begin match req_hdr.Request.ty with
| Command.Read ->
(* TODO: use a page-aligned memory allocator *)
Lwt_list.iter_s sock.read_clear response_body
Lwt_list.iter_s sock.read response_body
>>= fun () ->
Lwt.return (`Ok ())
| _ -> Lwt.return (`Ok ())
Expand All @@ -57,12 +57,12 @@ module NbdRpc = struct
let send_one sock req_hdr req_body =
let buf = Cstruct.create Request.sizeof in
Request.marshal buf req_hdr;
sock.write_clear buf
sock.write buf
>>= fun () ->
match req_body with
| None -> Lwt.return ()
| Some data ->
sock.write_clear data
sock.write data

let id_of_request req = req.Request.handle

Expand All @@ -87,6 +87,7 @@ type t = {
type id = unit

let make channel size_bytes flags =
let channel = generic_of_cleartext_channel channel in
Rpc.create channel
>>= fun client ->
let read_write = not (List.mem PerExportFlag.Read_only flags) in
Expand Down

0 comments on commit d1b349f

Please sign in to comment.