Skip to content

Commit

Permalink
TEST: Test Windows getaddrinfo_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
talex5 committed Nov 20, 2024
1 parent 9b939ab commit d02d7d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib_eio_posix/test/test_await.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
open Eio.Std

let () =
Eio_posix.run @@ fun env ->
Eio.Net.getaddrinfo_stream env#net "127.0.0.1" ~service:"7000"
|> List.iter (traceln "Got: %a" Eio.Net.Sockaddr.pp);
traceln "getaddrinfo: %d" (List.length (Unix.getaddrinfo "127.0.0.1" "7000" []));
traceln "gethostbyname: %d" (Array.length ((Unix.gethostbyname "127.0.0.1").h_addr_list))

let () =
Eio_posix.run @@ fun _ ->
let a, b = Unix.(socketpair PF_UNIX SOCK_STREAM 0) in
Expand Down
2 changes: 2 additions & 0 deletions lib_eio_windows/net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ let datagram_socket fd =
(* https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml *)
let getaddrinfo ~service node =
let to_eio_sockaddr_t {Unix.ai_family; ai_addr; ai_socktype; ai_protocol; _ } =
Fmt.epr "to_eio_sockaddr_t: ai_protocol=%d@." ai_protocol;
match ai_family, ai_socktype, ai_addr with
| (Unix.PF_INET | PF_INET6),
(Unix.SOCK_STREAM | SOCK_DGRAM),
Unix.ADDR_INET (inet_addr,port) -> (
Fmt.epr "to_eio_sockaddr_t: ADDR_INET@.";
match ai_protocol with
| 6 -> Some (`Tcp (Eio_unix.Net.Ipaddr.of_unix inet_addr, port))
| 17 -> Some (`Udp (Eio_unix.Net.Ipaddr.of_unix inet_addr, port))
Expand Down
10 changes: 9 additions & 1 deletion lib_eio_windows/test/test_net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ let test_eio_socketpair () =
let msg = Eio.Buf_read.of_flow b ~max_size:10 |> Eio.Buf_read.take_all in
Alcotest.(check string) "same messagw" "foo" msg

let test_getaddrinfo env () =
Eio.Net.getaddrinfo_stream env#net "127.0.0.1" ~service:"7000"
|> List.iter (traceln "Got: %a" Eio.Net.Sockaddr.pp);
traceln "getaddrinfo: %d" (List.length (Unix.getaddrinfo "127.0.0.1" "7000" []));
traceln "gethostbyname: %d" (Array.length ((Unix.gethostbyname "127.0.0.1").h_addr_list));
assert false

let tests env = [
"tcp-ip4", `Quick, test_client_server env (`Tcp (Eio.Net.Ipaddr.V4.loopback, 8081));
"tcp-ip6", `Quick, test_client_server env (`Tcp (Eio.Net.Ipaddr.V6.loopback, 8081));
Expand All @@ -114,5 +121,6 @@ let tests env = [
"fds", `Quick, test_fd env Eio.Net.Ipaddr.V4.loopback;
"wrap-pipe", `Quick, test_wrap_socket `Pipe;
"wrap-socketpair", `Quick, test_wrap_socket `Socketpair;
"eio-socketpair", `Quick, test_eio_socketpair
"eio-socketpair", `Quick, test_eio_socketpair;
"getaddrinfo", `Quick, test_getaddrinfo env;
]

0 comments on commit d02d7d3

Please sign in to comment.