package riot

  1. Overview
  2. Docs
An actor-model multi-core scheduler for OCaml 5

Install

Dune Dependency

Authors

Maintainers

Sources

riot-0.0.4.tbz
sha256=bd196369f74bbc42f23d262030d5fa04c03f5f00c46bf944f0dcbc193745976f
sha512=f1ca69e05b57e83a1bd173efe51b745d331355a83381e6068743a7626e45dcf515cdd8947180051bddfe9f5727c2732aa0f01a093b04cf33fa4081d32f24fd65

doc/src/lib_net/addr.ml.html

Source file addr.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
open Runtime
open Net
include Addr

let of_addr_info
    Unix.{ ai_family; ai_addr; ai_socktype; ai_protocol; ai_canonname } =
  match (ai_family, ai_socktype, ai_addr) with
  | ( (Unix.PF_INET | Unix.PF_INET6),
      (Unix.SOCK_DGRAM | Unix.SOCK_STREAM),
      Unix.ADDR_INET (addr, port) ) -> (
      Logger.error (fun f ->
          f "of_addr_info %s or %s" ai_canonname (Obj.magic addr));
      match ai_protocol with 6 -> Some (tcp (Obj.magic addr) port) | _ -> None)
  | _ -> None

let rec get_info host service =
  match Io.getaddrinfo host service with
  | `Ok info -> List.filter_map of_addr_info info
  | `Retry ->
      yield ();
      get_info host service
  | `Abort _err -> failwith "getaddrinfo failed"

let of_uri uri =
  let port =
    match Uri.port uri with
    | Some port -> Int.to_string port
    | _ -> Uri.scheme uri |> Option.value ~default:"http"
  in
  let host = Uri.host_with_default ~default:"0.0.0.0" uri in
  Logger.error (fun f -> f "host: %s port: %s" host port);
  match get_info host port with ip :: _ -> Some ip | [] -> None

let get_info (`Tcp (host, port)) = get_info host (Int.to_string port)
OCaml

Innovation. Community. Security.