package luv

  1. Overview
  2. Docs
Binding to libuv: cross-platform asynchronous I/O

Install

dune-project
 Dependency

Authors

Maintainers

Sources

luv-0.5.5.tar.gz
sha256=a81268ceb85b8cffbeb5e5a9fdb4c6e724266ce0dee1f39afc4bb4a17703d749
md5=5d2335fb57ffe228151cc492888ca2dc

doc/index.html

Luv

Luv is a binding to libuv, the cross-platform C library that does asynchronous I/O in Node.js and runs Node's main loop.

let () =
  Luv.DNS.getaddrinfo ~family:`INET ~node:"google.com" ~service:"80" ()
      begin fun result ->

    let address = (List.hd (Result.get_ok result)).addr in
    let socket = Luv.TCP.init () |> Result.get_ok in
    Luv.TCP.connect socket address begin fun _ ->

      Luv.Stream.write socket [Luv.Buffer.from_string "GET / HTTP/1.1\r\n\r\n"]
        (fun _ _ -> Luv.Stream.shutdown socket ignore);

      Luv.Stream.read_start socket (function
        | Error `EOF -> Luv.Handle.close socket ignore
        | Error _ -> exit 2
        | Ok response -> print_string (Luv.Buffer.to_string response))

    end
  end;

  ignore (Luv.Loop.run () : bool)

This is the auto-generated API reference. For more conceptual information and examples, see:

API reference

Basics

Main interface

System threads

Miscellaneous

OCaml

Innovation. Community. Security.