package uwt
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
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 ]
Same as Unix.handle_unix_error
but catches lwt-level exceptions
sleep d
is a thread that remains suspended for d
seconds and then terminates.
yield ()
is a thread that suspends itself and then resumes as soon as possible and terminates.
auto_yield timeout
returns a function f
that will yield every timeout
seconds.
timeout d
is a thread that remains suspended for d
seconds and then fails with Timeout
.
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.
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 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.
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.
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 returnfalse
in circumstances that would makestat
raise aUnix.Unix_error
exception.
module LargeFile : sig ... end
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 fchmod : file_descr -> Unix.file_perm -> unit Lwt.t
Change the permissions of an opened file.
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).
Check that the process has the given permissions over the named file.
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
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
.
Find an entry in hosts
with the given address.
Find an entry in services
with the given name.
Find an entry in protocols
with the given protocol number.
Find an entry in services
with the given name.
Find an entry in services
with the given service number.
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.
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
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.