-
-
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
17 changed files
with
229 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,6 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.TCP.simultaneous_accepts tcp true |> ok "accepts" @@ 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,7 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5100 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.bind tcp address |> 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,10 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5107 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.connect tcp address (fun result -> | ||
result |> error [`ECANCELED] "connect" @@ fun () -> | ||
print_endline "Ok"); | ||
|
||
Luv.Handle.close tcp ignore; | ||
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,11 @@ | ||
(* Fails with a segfault if the binding doesn't retain a reference to the | ||
callback. *) | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5103 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.connect tcp address (fun _ -> print_endline "Ok"); | ||
|
||
Gc.full_major (); | ||
|
||
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,11 @@ | ||
let () = | ||
Luv.Sockaddr.ipv4 "127.0.0.1" 5104 |> ok "ipv4" @@ fun address -> | ||
|
||
no_memory_leak begin fun _n -> | ||
Helpers.with_tcp @@ fun tcp -> | ||
let callback = fresh_callback () in | ||
Luv.TCP.connect tcp address (fun _ -> callback ()); | ||
Luv.Loop.run () |> ignore | ||
end; | ||
|
||
print_endline "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,10 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5105 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.connect tcp address ignore; | ||
Luv.TCP.connect tcp address (fun result -> | ||
result |> error [`EALREADY; `EINVAL] "connect" @@ fun () -> | ||
print_endline "Ok"); | ||
|
||
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,11 @@ | ||
let () = | ||
Luv.Sockaddr.ipv4 "127.0.0.1" 5106 |> ok "ipv4" @@ fun address -> | ||
|
||
no_memory_leak begin fun _n -> | ||
Helpers.with_tcp @@ fun tcp -> | ||
Luv.TCP.connect tcp address ignore; | ||
Luv.TCP.connect tcp address ignore; | ||
Luv.Loop.run () |> ignore | ||
end; | ||
|
||
print_endline "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,38 @@ | ||
(cram | ||
(alias runtest-windows) | ||
(deps | ||
trivial.exe | ||
nodelay.exe | ||
keepalive.exe | ||
accepts.exe | ||
bind.exe | ||
getsockname.exe | ||
econnrefused.exe | ||
connect_gc.exe | ||
connect_leak.exe | ||
connect_sync_error.exe | ||
connect_sync_error_leak.exe | ||
connect_cancel.exe | ||
listen_accept.exe | ||
getpeername.exe | ||
)) | ||
|
||
(executables | ||
(names | ||
trivial | ||
nodelay | ||
keepalive | ||
accepts | ||
bind | ||
getsockname | ||
econnrefused | ||
connect_gc | ||
connect_leak | ||
connect_sync_error | ||
connect_sync_error_leak | ||
connect_cancel | ||
listen_accept | ||
getpeername | ||
) | ||
(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,9 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5102 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.connect tcp address (fun result -> | ||
result |> error [`ECONNREFUSED] "connect" @@ fun () -> | ||
print_endline "Ok"); | ||
|
||
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,12 @@ | ||
let () = | ||
Helpers.with_server_and_client | ||
~port:5109 | ||
~server:begin fun server_tcp accept_tcp -> | ||
Luv.Handle.close server_tcp ignore | ||
end | ||
~client:begin fun client_tcp address -> | ||
Luv.TCP.getpeername client_tcp |> ok "getpeername" @@ fun address' -> | ||
let address = Luv.Sockaddr.to_string address in | ||
let address' = Luv.Sockaddr.to_string address' in | ||
Printf.printf "%b\n" (address' = address) | ||
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,12 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.Sockaddr.ipv4 "127.0.0.1" 5101 |> ok "ipv4" @@ fun address -> | ||
Luv.TCP.bind tcp address |> ok "bind" @@ fun () -> | ||
|
||
Luv.TCP.getsockname tcp |> ok "getsockname" @@ fun address' -> | ||
|
||
let address = Luv.Sockaddr.to_string address in | ||
let address' = Luv.Sockaddr.to_string address' in | ||
|
||
Printf.printf "%b\n" (address' = address) |
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,25 @@ | ||
let with_tcp f = | ||
Luv.TCP.init () |> ok "init" @@ fun tcp -> | ||
f tcp; | ||
Luv.Handle.close tcp ignore | ||
|
||
let with_server_and_client ~port ~server ~client = | ||
Luv.Sockaddr.ipv4 "127.0.0.1" port |> ok "ipv4" @@ fun address -> | ||
|
||
Luv.TCP.init () |> ok "server init" @@ fun server_tcp -> | ||
Luv.TCP.bind server_tcp address |> ok "bind" @@ fun () -> | ||
Luv.Stream.listen server_tcp begin fun result -> | ||
result |> ok "listen" @@ fun () -> | ||
Luv.TCP.init () |> ok "accept init" @@ fun accept_tcp -> | ||
Luv.Stream.accept ~server:server_tcp ~client:accept_tcp | ||
|> ok "accept" @@ fun () -> | ||
server server_tcp accept_tcp | ||
end; | ||
|
||
Luv.TCP.init () |> ok "client init" @@ fun client_tcp -> | ||
Luv.TCP.connect client_tcp address begin fun result -> | ||
result |> ok "connect" @@ fun () -> | ||
client client_tcp address | ||
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,6 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.TCP.keepalive tcp None |> ok "keepalive" @@ 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,10 @@ | ||
let () = | ||
Helpers.with_server_and_client | ||
~port:5108 | ||
~server:begin fun server_tcp accept_tcp -> | ||
prerr_endline "Accepted"; | ||
Luv.Handle.close server_tcp 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,6 @@ | ||
let () = | ||
Helpers.with_tcp @@ fun tcp -> | ||
|
||
Luv.TCP.nodelay tcp true |> ok "nodelay" @@ 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,42 @@ | ||
$ dune exec ./trivial.exe | ||
Ok | ||
|
||
$ dune exec ./nodelay.exe | ||
Ok | ||
|
||
$ dune exec ./keepalive.exe | ||
Ok | ||
|
||
$ dune exec ./accepts.exe | ||
Ok | ||
|
||
$ dune exec ./bind.exe | ||
Ok | ||
|
||
$ dune exec ./getsockname.exe | ||
true | ||
|
||
$ dune exec ./econnrefused.exe | ||
Ok | ||
|
||
$ dune exec ./connect_gc.exe | ||
Ok | ||
|
||
$ dune exec ./connect_leak.exe | ||
End | ||
|
||
$ dune exec ./connect_sync_error.exe | ||
Ok | ||
|
||
$ dune exec ./connect_sync_error_leak.exe | ||
End | ||
|
||
$ dune exec ./connect_cancel.exe | ||
Ok | ||
|
||
$ dune exec ./listen_accept.exe | ||
Accepted | ||
Connected | ||
|
||
$ dune exec ./getpeername.exe | ||
true |
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_tcp ignore; | ||
print_endline "Ok" |