package riot

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

Install

Dune Dependency

Authors

Maintainers

Sources

riot-0.0.3.tbz
sha256=6201ce27997ec1c4b4509782c6be2fa2bf102b804b11dcbf9ebdb49a123c19c3
sha512=ad70a67601a892700e461efe57484d109b1d08e30d15464ad8611e71dd568c934d3f948afd645e096e4f97ad1935aaeaf5d9b6d9d59c52a82eeb5c4995421646

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.