-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let () = | ||
Helpers.with_pipe @@ fun pipe -> | ||
Luv.Pipe.bind pipe Helpers.filename |> ok "bind" @@ fun () -> | ||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(cram | ||
(alias runtest-windows) | ||
(deps | ||
trivial.exe | ||
bind.exe | ||
listen_accept.exe | ||
)) | ||
|
||
(executables | ||
(names | ||
trivial | ||
bind | ||
listen_accept | ||
) | ||
(libraries luv unit_helpers) | ||
(flags -open Unit_helpers)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let filename = | ||
if Sys.win32 then | ||
{|\\.\pipe\pipe|} | ||
else | ||
"pipe" | ||
|
||
let with_pipe f = | ||
Luv.Pipe.init () |> ok "init" @@ fun tcp -> | ||
f tcp; | ||
Luv.Handle.close tcp ignore | ||
|
||
let with_server_and_client ~server ~client = | ||
Luv.Pipe.init () |> ok "server init" @@ fun server_pipe -> | ||
Luv.Pipe.bind server_pipe filename |> ok "bind" @@ fun () -> | ||
Luv.Stream.listen server_pipe begin fun result -> | ||
result |> ok "listen" @@ fun () -> | ||
Luv.Pipe.init () |> ok "accept init" @@ fun accept_pipe -> | ||
Luv.Stream.accept ~server:server_pipe ~client:accept_pipe | ||
|> ok "accept" @@ fun () -> | ||
server server_pipe accept_pipe | ||
end; | ||
|
||
Luv.Pipe.init () |> ok "client init" @@ fun client_pipe -> | ||
Luv.Pipe.connect client_pipe filename begin fun result -> | ||
result |> ok "connect" @@ fun () -> | ||
client client_pipe | ||
end; | ||
|
||
Luv.Loop.run () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let () = | ||
Helpers.with_server_and_client | ||
~server:begin fun server_pipe accept_pipe -> | ||
Luv.Handle.close server_pipe ignore | ||
end | ||
~client:begin fun client_tcp -> | ||
prerr_endline "Connected" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$ dune exec ./trivial.exe | ||
Ok | ||
|
||
$ dune exec ./bind.exe | ||
Ok | ||
|
||
$ dune exec ./listen_accept.exe | ||
Accepted | ||
Connected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let () = | ||
Helpers.with_pipe ignore; | ||
print_endline "Ok" |