module Lwt_unix:sig..end
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
| `Udp of Uwt.Udp.t ] -> file_descr
val from_file_descr : file_descr ->
[ `File of Uwt.file
| `Pipe of Uwt.Pipe.t
| `Tcp of Uwt.Tcp.t
| `Udp of Uwt.Udp.t ]
type dir_handle
val handle_unix_error : ('a -> 'b Lwt.t) -> 'a -> 'b Lwt.tSame as Unix.handle_unix_error but catches lwt-level
exceptions
val sleep : float -> unit Lwt.tsleep d is a thread that remains suspended for d seconds
and then terminates.
val yield : unit -> unit Lwt.tyield () is a thread that suspends itself and then resumes
as soon as possible and terminates.
val auto_yield : float -> unit -> unit Lwt.tauto_yield timeout returns a function f that will yield
every timeout seconds.
exception Timeout
Exception raised by timeout operations
val timeout : float -> 'a Lwt.ttimeout d is a thread that remains suspended for d seconds
and then fails with Uwt_compat.Lwt_unix.Timeout.
val with_timeout : float -> (unit -> 'a Lwt.t) -> 'a Lwt.twith_timeout d f is a short-hand for:
Lwt.pick [Lwt_unix.timeout d; f ()]
val stdin : file_descrThe standard file descriptor for input
val stdout : file_descrThe standard file descriptor for output
val stderr : file_descrThe standard file descriptor for printing error messages
val openfile : string ->
Unix.open_flag list ->
file_perm -> file_descr Lwt.tWrapper for Unix.openfile.
val close : file_descr -> unit Lwt.tClose a file descriptor. This close the underlying unix file descriptor
val read : file_descr -> bytes -> int -> int -> int Lwt.tread 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.twrite 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
val lseek : file_descr -> int -> Unix.seek_command -> int Lwt.tSet the current position for a file descriptor, and return the resulting offset (from the beginning of the file).
val truncate : string -> int -> unit Lwt.tTruncates the named file to the given size.
val ftruncate : file_descr -> int -> unit Lwt.tTruncates the file corresponding to the given descriptor to the given size.
val fsync : file_descr -> unit Lwt.tSynchronise all data and metadata of the file descriptor with the disk.
val fdatasync : file_descr -> unit Lwt.tSynchronise all data (but not metadata) of the file descriptor with the disk.
val stat : string -> Unix.stats Lwt.tReturn the information for the named file.
val lstat : string -> Unix.stats Lwt.tSame as Uwt_compat.Lwt_unix.stat, but in case the file is a symbolic link,
return the information for the link itself.
val fstat : file_descr -> Unix.stats Lwt.tReturn the information for the file associated with the given descriptor.
val isatty : file_descr -> bool Lwt.tReturn true if the given file descriptor refers to a terminal or
console window, false otherwise.
val file_exists : string -> bool Lwt.tfile_exists name tests if a file named name exists.
Note that file_exists behaves similarly to
Sys.file_exists:
file_exists name will return false in
circumstances that would make Uwt_compat.Lwt_unix.stat raise a
Unix.Unix_error exception.module LargeFile:sig..end
val unlink : string -> unit Lwt.tRemoves the named file.
val rename : string -> string -> unit Lwt.trename old new changes the name of a file from old to new.
val link : string -> string -> unit Lwt.tlink source dest creates a hard link named dest to the file
named source.
val chmod : string -> file_perm -> unit Lwt.tChange the permissions of the named file.
val fchmod : file_descr -> file_perm -> unit Lwt.tChange the permissions of an opened file.
val chown : string -> int -> int -> unit Lwt.tChange 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.tChange 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.tCheck that the process has the given permissions over the named file.
val mkdir : string -> file_perm -> unit Lwt.tCreate a directory with the given permissions.
val rmdir : string -> unit Lwt.tRemove an empty directory.
val opendir : string -> dir_handle Lwt.tThis 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.tfiles_of_directory dir returns the stream of all files of
dir.
val symlink : string -> string -> unit Lwt.tsymlink source dest creates the file dest as a symbolic link
to the file source.
val readlink : string -> string Lwt.tRead the contents of a symbolic link.
val getlogin : unit -> string Lwt.tReturn the login name of the user executing the process.
val getpwnam : string -> Unix.passwd_entry Lwt.tFind an entry in passwd with the given name.
val getgrnam : string -> Unix.group_entry Lwt.tFind an entry in group with the given name.
val getpwuid : int -> Unix.passwd_entry Lwt.tFind an entry in passwd with the given user id.
val getgrgid : int -> Unix.group_entry Lwt.tFind an entry in group with the given group id.
val chdir : string -> unit Lwt.tChange the process working directory.
val chroot : string -> unit Lwt.tWrapper for Unix.chroot
val getcwd : unit -> string Lwt.tWrapper for Unix.getcwd
val gethostname : unit -> string Lwt.tReturn the name of the local host.
val gethostbyname : string -> Unix.host_entry Lwt.tFind an entry in hosts with the given name.
val gethostbyaddr : Unix.inet_addr -> Unix.host_entry Lwt.tFind an entry in hosts with the given address.
val getprotobyname : string -> Unix.protocol_entry Lwt.tFind an entry in services with the given name.
val getprotobynumber : int -> Unix.protocol_entry Lwt.tFind an entry in protocols with the given protocol number.
val getservbyname : string -> string -> Unix.service_entry Lwt.tFind an entry in services with the given name.
val getservbyport : int -> string -> Unix.service_entry Lwt.tFind an entry in services with the given service number.
val getaddrinfo : string -> string -> Unix.getaddrinfo_option list -> Unix.addr_info list Lwt.tgetaddrinfo 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.tgetnameinfo 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_descrpipe () creates pipe using Unix.pipe and returns two file
descriptors created from unix file_descriptor
val pipe_in : unit -> file_descr * Unix.file_descrpipe_in () is the same as Uwt_compat.Lwt_unix.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_descrpipe_out () is the inverse of Uwt_compat.Lwt_unix.pipe_in. You usually want to
use this before forking to send data to the child process
val system : string -> Unix.process_status Lwt.tExecutes 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.tutimes 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..
type signal_handler_id
val on_signal : int -> (int -> unit) -> signal_handler_idon_signal signum f calls f each time the signal with numnber
signum is received by the process. It returns a signal handler
identifier that can be used to stop monitoring signum.
val on_signal_full : int ->
(signal_handler_id -> int -> unit) ->
signal_handler_idon_signal_full f is the same as on_signal f except that f
also receive the signal handler identifier as argument so it can
disable it.
val disable_signal_handler : signal_handler_id -> unitStops receiving this signal