Skip to content

Commit 42debd5

Browse files
authored
Merge pull request #227 from mseri/master
xcp: update and simplify interface using fd-send-recv >= 2.0.0
2 parents 25b33cc + 9708499 commit 42debd5

File tree

7 files changed

+26
-31
lines changed

7 files changed

+26
-31
lines changed

example/jbuild

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ let () = Printf.ksprintf Jbuild_plugin.V1.send {|
3232
((name example)
3333
(flags (:standard -w -39 %s))
3434
(libraries
35-
(lwt
36-
lwt.unix
37-
rpclib
35+
(rpclib
3836
xcp))
3937
%s))
4038

lib/jbuild

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let () = Printf.ksprintf Jbuild_plugin.V1.send {|
4646
((name xcp)
4747
(public_name xcp)
4848
(flags (:standard -w -39 %s -warn-error -3))
49-
(modules (:standard \ channel_helper scheduler task_server updates))
49+
(modules (:standard \ scheduler task_server updates))
5050
(c_names (syslog_stubs))
5151
(libraries
5252
(%s
@@ -78,19 +78,7 @@ let () = Printf.ksprintf Jbuild_plugin.V1.send {|
7878
(public_name xcp.updates)
7979
(flags (:standard -w -39 %s))
8080
(modules (updates task_server scheduler))
81-
(libraries
82-
(lwt
83-
xcp))
81+
(libraries (xcp))
8482
(wrapped false)
8583
%s))
86-
87-
(executable
88-
((name channel_helper)
89-
(flags (:standard -w -39 %s))
90-
(modules (channel_helper))
91-
(libraries
92-
(cmdliner
93-
lwt
94-
lwt.unix
95-
xcp))))
96-
|} runtime_coverage_enabled flags coverage_dep coverage_rewriter flags coverage_rewriter flags
84+
|} runtime_coverage_enabled flags coverage_dep coverage_rewriter flags coverage_rewriter

lib/posix_channel.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ let send proxy_socket =
149149
let n = Unix.recv fd buffer 0 (Bytes.length buffer) [] in
150150
let token' = Bytes.sub_string buffer 0 n in
151151
if token = token' then begin
152-
let (_: int) = Fd_send_recv.send_fd fd token 0 (String.length token) [] proxy_socket in
152+
let (_: int) = Fd_send_recv.send_fd_substring fd token 0 (String.length token) [] proxy_socket in
153153
()
154154
end
155155
end else if List.mem s_ip readable then begin
@@ -203,8 +203,9 @@ let receive protocols =
203203
finally
204204
(fun () ->
205205
Unix.connect s (Unix.ADDR_UNIX path);
206-
let (_: int) = Unix.send s (Bytes.unsafe_of_string token) 0 (String.length token) [] in
207-
let (_, _, fd) = Fd_send_recv.recv_fd s token 0 (String.length token) [] in
206+
let (_: int) = Unix.send_substring s token 0 (String.length token) [] in
207+
let buf = Bytes.create (String.length token) in
208+
let (_, _, fd) = Fd_send_recv.recv_fd s buf 0 (Bytes.length buf) [] in
208209
fd
209210
) (fun () -> Unix.close s)
210211

lib_test/jbuild

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ let () = Printf.ksprintf Jbuild_plugin.V1.send {|
3232
((names (test test_alco))
3333
(flags (:standard -w -39 %s))
3434
(libraries
35-
(lwt
36-
lwt.unix
37-
alcotest
35+
(alcotest
3836
oUnit
3937
rpclib
4038
rpclib.markdown

lib/channel_helper.ml renamed to misc/channel_helper.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ exception End_of_file
99
exception No_useful_protocol
1010

1111
let copy_all src dst =
12-
let buffer = String.make 16384 '\000' in
12+
let buffer = Bytes.make 16384 '\000' in
1313
let rec loop () =
14-
Lwt_unix.read src buffer 0 (String.length buffer) >>= fun n ->
14+
Lwt_unix.read src buffer 0 (Bytes.length buffer) >>= fun n ->
1515
if n = 0
1616
then Lwt.fail End_of_file
1717
else
@@ -116,11 +116,11 @@ let advertise_t _common_options_t proxy_socket =
116116
proxy fd (Lwt_unix.of_unix_file_descr proxy_socket) in
117117
let t_unix =
118118
Lwt_unix.accept s_unix >>= fun (fd, _peer) ->
119-
let buffer = String.make (String.length token) '\000' in
120-
let io_vector = Lwt_unix.io_vector ~buffer ~offset:0 ~length:(String.length buffer) in
119+
let buffer = Bytes.make (String.length token) '\000' in
120+
let io_vector = Lwt_unix.io_vector ~buffer:(Bytes.unsafe_to_string buffer) ~offset:0 ~length:(Bytes.length buffer) in
121121
Lwt_unix.recv_msg ~socket:fd ~io_vectors:[io_vector] >>= fun (n, fds) ->
122122
List.iter Unix.close fds;
123-
let token' = String.sub buffer 0 n in
123+
let token' = Bytes.sub_string buffer 0 n in
124124
let io_vector' = Lwt_unix.io_vector ~buffer:token' ~offset:0 ~length:(String.length token') in
125125
if token = token'
126126
then

misc/jbuild

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(jbuild_version 1)
2+
(executable
3+
((name channel_helper)
4+
(modules (channel_helper))
5+
(libraries
6+
(cmdliner
7+
lwt
8+
lwt.unix
9+
xcp))
10+
(preprocess (pps (ppx_deriving_rpc)))
11+
))

xcp.opam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ depends: [
1212
"base-unix"
1313
"cmdliner"
1414
"cohttp"
15-
"fd-send-recv"
15+
"fd-send-recv" {>= "2.0.0"}
1616
"jbuilder" {build & >= "1.0+beta11"}
17-
"lwt" {>= "3.0.0"}
1817
"message-switch-core"
1918
"message-switch-unix"
2019
"ocamlfind" {build}

0 commit comments

Comments
 (0)