package uwt

  1. Overview
  2. Docs

Uwt main module

Basic overview:

  • naming conventions mirror the conventions of libuv, so you can easily consult the official libuv manual. Selected parts of the manual are now included inside the mli files (credits to Authors), the libuv manual is however more up-to-date.
  • Requests are translated to lwt-threads, therefore uv_req_t is kept internal.
  • Callbacks that are called continually are most of the time not translated to the usual lwt semantic.
  • Uwt is not compatible with lwt.unix. It's not a further Lwt_engine in addition to select and libev.
  • Uwt is not thread safe. All uwt functions should be called from your main thread.

Please notice, that there are subtle differences compared to lwt.unix. Because all requests are accomplished by libuv (sometimes in parallel in different threads), you don't have that kind of low level control, that you have with lwt.unix. Also Lwt.cancel behaves differently and you won't notice it by looking at the type information.

  • Stream.write and related functions can never be canceled. The analogous write functions in Lwt_unix however are cancelable as long as the underlying file descriptor is not opened in blocking mode. (Stream.read currently returns the only cancelable thread inside Stream and its subclasses. But there is no guarantee that Tcp.read will continue to be cancelable under Windows in future libuv versions.)
  • Everything that is done in work threads (e.g. File I/O, DNS resolution, etc.) is cancelable, as long as the task is just queued for execution and not already running in a parallel thread. However, it's never possible to cancel a background task in Lwt_unix.
include module type of Uwt_base with type error = Uwt_base.error with type 'a uv_result = 'a Uwt_base.uv_result with type file = Uwt_base.file with type sockaddr = Uwt_base.sockaddr with type 'a Int_result.t = 'a Uwt_base.Int_result.t with type Fs_types.uv_open_flag = Uwt_base.Fs_types.uv_open_flag with type Fs_types.file_kind = Uwt_base.Fs_types.file_kind with type Fs_types.symlink_mode = Uwt_base.Fs_types.symlink_mode with type Fs_types.access_permission = Uwt_base.Fs_types.access_permission with type Fs_types.stats = Uwt_base.Fs_types.stats with type Misc.timeval = Uwt_base.Misc.timeval with type Misc.rusage = Uwt_base.Misc.rusage with type Misc.cpu_times = Uwt_base.Misc.cpu_times with type Misc.cpu_info = Uwt_base.Misc.cpu_info with type Misc.interface_address = Uwt_base.Misc.interface_address with type Misc.handle_type = Uwt_base.Misc.handle_type with type Misc.version = Uwt_base.Misc.version with type Iovec_write.t = Uwt_base.Iovec_write.t

Uwt_base contains type definitions and functions that are shared by Uwt and Uv_fs_sync

type error = Uwt_base.error =
  1. | E2BIG
    (*

    argument list too long

    *)
  2. | EACCES
    (*

    permission denied

    *)
  3. | EADDRINUSE
    (*

    address already in use

    *)
  4. | EADDRNOTAVAIL
    (*

    address not available

    *)
  5. | EAFNOSUPPORT
    (*

    address family not supported

    *)
  6. | EAGAIN
    (*

    resource temporarily unavailable

    *)
  7. | EAI_ADDRFAMILY
    (*

    address family not supported

    *)
  8. | EAI_AGAIN
    (*

    temporary failure

    *)
  9. | EAI_BADFLAGS
    (*

    bad ai_flags value

    *)
  10. | EAI_BADHINTS
    (*

    invalid value for hints

    *)
  11. | EAI_CANCELED
    (*

    request canceled

    *)
  12. | EAI_FAIL
    (*

    permanent failure

    *)
  13. | EAI_FAMILY
    (*

    ai_family not supported

    *)
  14. | EAI_MEMORY
    (*

    out of memory

    *)
  15. | EAI_NODATA
    (*

    no address

    *)
  16. | EAI_NONAME
    (*

    unknown node or service

    *)
  17. | EAI_OVERFLOW
    (*

    argument buffer overflow

    *)
  18. | EAI_PROTOCOL
    (*

    resolved protocol is unknown

    *)
  19. | EAI_SERVICE
    (*

    service not available for socket type

    *)
  20. | EAI_SOCKTYPE
    (*

    socket type not supported

    *)
  21. | EALREADY
    (*

    connection already in progress

    *)
  22. | EBADF
    (*

    bad file descriptor

    *)
  23. | EBUSY
    (*

    resource busy or locked

    *)
  24. | ECANCELED
    (*

    operation canceled

    *)
  25. | ECHARSET
    (*

    Windows filenames (and similar parameters) are expected to be utf-8 encoded. ECHARSET is returned, if one parameter contains invalid byte sequences. Furthermore, ECHARSET will be returned, if your strings contain null bytes (on *nix, too).

    *)
  26. | ECONNABORTED
    (*

    software caused connection abort

    *)
  27. | ECONNREFUSED
    (*

    connection refused

    *)
  28. | ECONNRESET
    (*

    connection reset by peer

    *)
  29. | EDESTADDRREQ
    (*

    destination address required

    *)
  30. | EEXIST
    (*

    file already exists

    *)
  31. | EFAULT
    (*

    bad address in system call argument

    *)
  32. | EFBIG
    (*

    file too large

    *)
  33. | EHOSTUNREACH
    (*

    host is unreachable

    *)
  34. | EINTR
    (*

    interrupted system call

    *)
  35. | EINVAL
    (*

    invalid argument

    *)
  36. | EIO
    (*

    i/o error

    *)
  37. | EISCONN
    (*

    socket is already connected

    *)
  38. | EISDIR
    (*

    illegal operation on a directory

    *)
  39. | ELOOP
    (*

    too many symbolic links encountered

    *)
  40. | EMFILE
    (*

    too many open files

    *)
  41. | EMSGSIZE
    (*

    message too long

    *)
  42. | ENAMETOOLONG
    (*

    name too long

    *)
  43. | ENETDOWN
    (*

    network is down

    *)
  44. | ENETUNREACH
    (*

    network is unreachable

    *)
  45. | ENFILE
    (*

    file table overflow

    *)
  46. | ENOBUFS
    (*

    no buffer space available

    *)
  47. | ENODEV
    (*

    no such device

    *)
  48. | ENOENT
    (*

    no such file or directory

    *)
  49. | ENOMEM
    (*

    not enough memory

    *)
  50. | ENONET
    (*

    machine is not on the network

    *)
  51. | ENOPROTOOPT
    (*

    protocol not available

    *)
  52. | ENOSPC
    (*

    no space left on device

    *)
  53. | ENOSYS
    (*

    function not implemented

    *)
  54. | ENOTCONN
    (*

    socket is not connected

    *)
  55. | ENOTDIR
    (*

    not a directory

    *)
  56. | ENOTEMPTY
    (*

    directory not empty

    *)
  57. | ENOTSOCK
    (*

    socket operation on non-socket

    *)
  58. | ENOTSUP
    (*

    operation not supported on socket

    *)
  59. | EPERM
    (*

    operation not permitted

    *)
  60. | EPIPE
    (*

    broken pipe

    *)
  61. | EPROTO
    (*

    protocol error

    *)
  62. | EPROTONOSUPPORT
    (*

    protocol not supported

    *)
  63. | EPROTOTYPE
    (*

    protocol wrong type for socket

    *)
  64. | ERANGE
    (*

    result too large

    *)
  65. | EROFS
    (*

    read-only file system

    *)
  66. | ESHUTDOWN
    (*

    cannot send after transport endpoint shutdown

    *)
  67. | ESPIPE
    (*

    invalid seek

    *)
  68. | ESRCH
    (*

    no such process

    *)
  69. | ETIMEDOUT
    (*

    connection timed out

    *)
  70. | ETXTBSY
    (*

    text file is busy

    *)
  71. | EXDEV
    (*

    cross-device link not permitted

    *)
  72. | UNKNOWN
    (*

    unknown error

    *)
  73. | EOF
    (*

    end of file

    *)
  74. | ENXIO
    (*

    no such device or address

    *)
  75. | UWT_EFATAL
    (*

    something happened that the author of uwt didn't expect. Probably a bug or the api of libuv has changed in the meanwhile

    *)
val strerror : error -> string

error message for the given error code

val err_name : error -> string

error name for the given error code

val to_unix_error : error -> Unix.error

map error to Unix.error , Unix.EUNKNOWNERR is used, if the mapping is not possible

val of_unix_error : Unix.error -> error

get back the original Uwt.error from an exception raised by a Uwt function

type 'a uv_result = 'a Uwt_base.uv_result
module Int_result : sig ... end

Int_result.t is used instead of 'a result, if a function returns either an error or a non-negative integer (including unit/bool).

type file = Uwt_base.file

Abstract type for a file descriptor. Unlike Unix.file_descr it is not intended to wrap a SOCKET.

type sockaddr = Uwt_base.sockaddr
val stdin : file

File descriptor for standard input.

val stdout : file

File descriptor for standard output.

val stderr : file

File descriptor for standard error.

module Iovec_write : sig ... end

pass multiple buffers at once to a libuv write function.

module Fs_types : sig ... end
module type Fs_functions = sig ... end
module Conv : sig ... end
module Misc : sig ... end

This section contains miscellaneous functions that don't really belong in any other section.

module Sys_info : sig ... end

Information about your operating system.

module Main : sig ... end

Analogue of Lwt_main

module Fs : sig ... end
module Handle : sig ... end

Handle.t is the base type for all libuv handle types.

module Handle_ext : sig ... end
module Handle_fileno : sig ... end

The usage of fileno is unsafe and strongly discouraged. But it's sometimes necessary, if you need to interact with third parties libraries. Rules:

module Stream : sig ... end

Stream handles provide an abstraction of a duplex communication channel. Stream.t is an abstract type, libuv provides 3 stream implementations in the form of Tcp.t, Pipe.t and Tty.t.

module Tcp : sig ... end

TCP handles are used to represent both TCP streams and servers.

module Udp : sig ... end

UDP handles encapsulate UDP communication for both clients and servers.

module Tty : sig ... end

TTY handles represent a stream for the console.

module Pipe : sig ... end

Pipe handles provide an abstraction over local domain sockets on Unix and named pipes on Windows.

module Timer : sig ... end

Timer handles are used to schedule callbacks to be called in the future.

module Signal : sig ... end

Signal handles implement Unix style signal handling on a per-event loop bases.

module Poll : sig ... end

Poll handles are used to watch file descriptors for readability, writability and disconnection similar to the purpose of poll(2).

module Fs_event : sig ... end

FS Event handles allow the user to monitor a given path for changes, for example, if the file was renamed or there was a generic change in it. This handle uses the best backend for the job on each platform.

module Fs_poll : sig ... end

FS Poll handles allow the user to monitor a given path for changes. Unlike Fs_event.t, fs poll handles use stat to detect when a file has changed so they can work on file systems where fs event handles can't.

module Process : sig ... end

Process handles will spawn a new process and allow the user to control it and establish communication channels with it using streams.

module Dns : sig ... end

libuv provides asynchronous variants of getaddrinfo and getnameinfo.

module Unix : sig ... end

Popular functions from the standard Unix module, but all calls are executed in work threads.

module C_worker : sig ... end
module Async : sig ... end

Async handles allow the user to "wakeup" the event loop and get a callback called from another (system) thread.

module Debug : sig ... end

Common helper for ad hoc debugging. Don't use them inside production code.

OCaml

Innovation. Community. Security.