package uwt

  1. Overview
  2. Docs

Lwt_unix compatibility layer

Everything inside Lwt_unix is implemented with funcions from Uwt. The purpose is to make it easier to test or use existing code with uwt instead of lwt.unix

type file_descr
val to_file_descr : [ `File of Uwt.file | `Pipe of Uwt.Pipe.t | `Tcp of Uwt.Tcp.t ] -> file_descr
val from_file_descr : file_descr -> [ `File of Uwt.file | `Pipe of Uwt.Pipe.t | `Tcp of Uwt.Tcp.t ]
type dir_handle
val handle_unix_error : ('a -> 'b Lwt.t) -> 'a -> 'b Lwt.t

Same as Unix.handle_unix_error but catches lwt-level exceptions

val sleep : float -> unit Lwt.t

sleep d is a thread that remains suspended for d seconds and then terminates.

val yield : unit -> unit Lwt.t

yield () is a thread that suspends itself and then resumes as soon as possible and terminates.

val auto_yield : float -> unit -> unit Lwt.t

auto_yield timeout returns a function f that will yield every timeout seconds.

exception Timeout

Exception raised by timeout operations

val timeout : float -> 'a Lwt.t

timeout d is a thread that remains suspended for d seconds and then fails with Timeout.

val with_timeout : float -> (unit -> 'a Lwt.t) -> 'a Lwt.t

with_timeout d f is a short-hand for:

Lwt.pick [Lwt_unix.timeout d; f ()]
val stdin : file_descr

The standard file descriptor for input

val stdout : file_descr

The standard file descriptor for output

val stderr : file_descr

The standard file descriptor for printing error messages

val openfile : string -> Unix.open_flag list -> Unix.file_perm -> file_descr Lwt.t

Wrapper for Unix.openfile.

val close : file_descr -> unit Lwt.t

Close a file descriptor. This close the underlying unix file descriptor

val read : file_descr -> bytes -> int -> int -> int Lwt.t

read fd buff ofs len reads len bytes from descriptor fd, storing them in byte sequence buff, starting at position ofs in buff. Return the number of bytes actually read.

val write : file_descr -> bytes -> int -> int -> int Lwt.t

write fd buff ofs len writes len bytes to descriptor fd, taking them from byte sequence buff, starting at position ofs in buff. Return the number of bytes actually written. write repeats the writing operation until all bytes have been written or an error occurs (but only for streams)

val write_string : file_descr -> string -> int -> int -> int Lwt.t

See write.

val lseek : file_descr -> int -> Unix.seek_command -> int Lwt.t

Set the current position for a file descriptor, and return the resulting offset (from the beginning of the file).

val truncate : string -> int -> unit Lwt.t

Truncates the named file to the given size.

val ftruncate : file_descr -> int -> unit Lwt.t

Truncates the file corresponding to the given descriptor to the given size.

val fsync : file_descr -> unit Lwt.t

Synchronise all data and metadata of the file descriptor with the disk.

val fdatasync : file_descr -> unit Lwt.t

Synchronise all data (but not metadata) of the file descriptor with the disk.

val stat : string -> Unix.stats Lwt.t

Return the information for the named file.

val lstat : string -> Unix.stats Lwt.t

Same as stat, but in case the file is a symbolic link, return the information for the link itself.

val fstat : file_descr -> Unix.stats Lwt.t

Return the information for the file associated with the given descriptor.

val isatty : file_descr -> bool Lwt.t

Return true if the given file descriptor refers to a terminal or console window, false otherwise.

val file_exists : string -> bool Lwt.t

file_exists name tests if a file named name exists.

Note that file_exists behaves similarly to Sys.file_exists:

  • "file" is interpreted as "directory entry" in this context
  • file_exists name will return false in circumstances that would make stat raise a Unix.Unix_error exception.
module LargeFile : sig ... end

Removes the named file.

val rename : string -> string -> unit Lwt.t

rename old new changes the name of a file from old to new.

link source dest creates a hard link named dest to the file named source.

val chmod : string -> Unix.file_perm -> unit Lwt.t

Change the permissions of the named file.

val fchmod : file_descr -> Unix.file_perm -> unit Lwt.t

Change the permissions of an opened file.

val chown : string -> int -> int -> unit Lwt.t

Change the owner uid and owner gid of the named file. On Windows: not implemented (make no sense on a DOS file system).

val fchown : file_descr -> int -> int -> unit Lwt.t

Change the owner uid and owner gid of an opened file. On Windows: not implemented (make no sense on a DOS file system).

val access : string -> Unix.access_permission list -> unit Lwt.t

Check that the process has the given permissions over the named file.

val mkdir : string -> Unix.file_perm -> unit Lwt.t

Create a directory with the given permissions.

val rmdir : string -> unit Lwt.t

Remove an empty directory.

val opendir : string -> dir_handle Lwt.t

This not really opens a descriptor on a directory. Uwt.Fs.scandir is used internally

val readdir : dir_handle -> string Lwt.t
val readdir_n : dir_handle -> int -> string array Lwt.t
val closedir : dir_handle -> unit Lwt.t
val files_of_directory : string -> string Lwt_stream.t

files_of_directory dir returns the stream of all files of dir.

symlink source dest creates the file dest as a symbolic link to the file source.

Read the contents of a symbolic link.

val getlogin : unit -> string Lwt.t

Return the login name of the user executing the process.

val getpwnam : string -> Unix.passwd_entry Lwt.t

Find an entry in passwd with the given name.

val getgrnam : string -> Unix.group_entry Lwt.t

Find an entry in group with the given name.

val getpwuid : int -> Unix.passwd_entry Lwt.t

Find an entry in passwd with the given user id.

val getgrgid : int -> Unix.group_entry Lwt.t

Find an entry in group with the given group id.

val chdir : string -> unit Lwt.t

Change the process working directory.

val gethostname : unit -> string Lwt.t

Return the name of the local host.

val gethostbyname : string -> Unix.host_entry Lwt.t

Find an entry in hosts with the given name.

val gethostbyaddr : Unix.inet_addr -> Unix.host_entry Lwt.t

Find an entry in hosts with the given address.

val getprotobyname : string -> Unix.protocol_entry Lwt.t

Find an entry in services with the given name.

val getprotobynumber : int -> Unix.protocol_entry Lwt.t

Find an entry in protocols with the given protocol number.

val getservbyname : string -> string -> Unix.service_entry Lwt.t

Find an entry in services with the given name.

val getservbyport : int -> string -> Unix.service_entry Lwt.t

Find an entry in services with the given service number.

val getaddrinfo : string -> string -> Unix.getaddrinfo_option list -> Unix.addr_info list Lwt.t

getaddrinfo host service opts returns a list of Unix.addr_info records describing socket parameters and addresses suitable for communicating with the given host and service. The empty list is returned if the host or service names are unknown, or the constraints expressed in opts cannot be satisfied.

val getnameinfo : Unix.sockaddr -> Unix.getnameinfo_option list -> Unix.name_info Lwt.t

getnameinfo addr opts returns the host name and service name corresponding to the socket address addr. opts is a possibly empty list of options that governs how these names are obtained. Lwt.fails with Not_found if an error occurs.

val pipe : unit -> file_descr * file_descr

pipe () creates pipe using Unix.pipe and returns two file descriptors created from unix file_descriptor

val pipe_in : unit -> file_descr * Unix.file_descr

pipe_in () is the same as pipe but maps only the unix file descriptor for reading into a lwt one. The second is not put into non-blocking mode. You usually want to use this before forking to receive data from the child process.

val pipe_out : unit -> Unix.file_descr * file_descr

pipe_out () is the inverse of pipe_in. You usually want to use this before forking to send data to the child process

val system : string -> Unix.process_status Lwt.t

Executes the given command, waits until it terminates, and return its termination status. The string is interpreted by the shell /bin/sh on Unix and cmd.exe on Windows. The result WEXITED 127 indicates that the shell couldn't be executed.

val utimes : string -> float -> float -> unit Lwt.t

utimes path atime mtime updates the access and modification times of the file at path. The access time is set to atime and the modification time to mtime. To set both to the current time, call utimes path 0. 0..

OCaml

Innovation. Community. Security.