module Lwt_unix:sig..end
Unix module, to cooperative ones, which will not block
the program.
The semantics of all operations is the following: if the action (for example reading from a file descriptor) can be performed immediately, it is done and returns immediately, otherwise it returns a sleeping thread which is woken up when the operation completes.
Most operations on sockets and pipes (on Windows it is only
sockets) are cancelable, meaning you can cancel them
with Lwt.cancel. For example if you want to read something from
a file descriptor with a timeout, you can cancel the action
after the timeout and the reading will not be performed if not
already done.
For example, consider that you have two sockets sock1 and
sock2. You want to read something from sock1 or exclusively
from sock2 and fail with an exception if a timeout of 1 second
expires, without reading anything from sock1 and sock2, even
if they become readable in the future.
Then you can do:
Lwt.pick
[Lwt_unix.timeout 1.0;
read sock1 buf1 ofs1 len1;
read sock2 buf2 ofs2 len2]
In this case, it is guaranteed that exactly one of the three
operations will complete, and the others will be cancelled.
val handle_unix_error : ('a -> 'b Lwt.t) -> 'a -> 'b Lwt.tUnix.handle_unix_error but catches lwt-level
exceptionstype async_method =
| |
Async_none |
(* |
System calls are made synchronously, and may block the
entire program.
| *) |
| |
Async_detach |
(* |
System calls are made in another system thread, thus without
blocking other Lwt threads. The drawback is that it may
degrade performance in some cases.
This is the default. | *) |
| |
Async_switch |
(* |
System calls are made in the main thread, and if one blocks
the execution continue in another system thread. This method
is the most efficient, also you will get better performance
if you force all threads to run on the same cpu. On linux
this can be done by using the command
taskset.
Note that this method is still experimental. | *) |
val default_async_method : unit -> async_method
This can be initialized using the environment variable
"LWT_ASYNC_METHOD" with possible values "none",
"detach" and "switch".
val set_default_async_method : async_method -> unitval async_method : unit -> async_methodasync_method () returns the async method used in the current
thread.val async_method_key : async_method Lwt.keyval with_async_none : (unit -> 'a) -> 'awith_async_none f is a shorthand for:
Lwt.with_value async_method_key (Some Async_none) f
val with_async_detach : (unit -> 'a) -> 'awith_async_detach f is a shorthand for:
Lwt.with_value async_method_key (Some Async_detach) f
val with_async_switch : (unit -> 'a) -> 'awith_async_switch f is a shorthand for:
Lwt.with_value async_method_key (Some Async_switch) f
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
val timeout : float -> 'a Lwt.t
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 ()]
type file_descr
Unix.file_descr) and a state.
A file descriptor may be:
type state =
| |
Opened |
(* |
The file descriptor is opened
| *) |
| |
Closed |
(* |
The file descriptor has been closed by
Lwt_unix.close. It must
not be used for any operation. | *) |
| |
Aborted of |
(* |
The file descriptor has been aborted, the only operation
possible is
Lwt_unix.close, all others will fail. | *) |
val state : file_descr -> statestate fd returns the state of fdval unix_file_descr : file_descr -> Unix.file_descrOpen.val of_unix_file_descr : ?blocking:bool -> ?set_flags:bool -> Unix.file_descr -> file_descrUnix file descriptor fd in an Lwt_unix.file_descr fd'.
~blocking controls the internal strategy Lwt uses to perform I/O on
the underlying fd. Regardless of ~blocking, at the API level,
Lwt_unix.read, Lwt_unix.write, etc. on fd' always block the Lwt
thread, but never block the whole process. However, for performance
reasons, it is important that ~blocking match the actual blocking mode of
fd.
If ~blocking is not specified, of_unix_file_descr chooses non-blocking
mode for Unix sockets, Unix pipes, and Windows sockets, and blocking mode
for everything else.
of_unix_file_descr runs a system call to set the specified or chosen
blocking mode on the underlying fd.
To prevent of_unix_file_descr from running this system call, you can pass
~set_flags:false. Note that, in this case, if ~blocking, whether passed
explicitly or chosen by Lwt, does not match the true blocking mode of the
underlying fd, I/O on fd' will suffer performance degradation.
Note that ~set_flags is effectively always false if running on Windows
and fd is not a socket.
Generally, non-blocking I/O is faster: for blocking I/O, Lwt typically has
to run system calls in worker threads to avoid blocking the process. See
your system documentation for whether particular kinds of file descriptors
support non-blocking I/O.
val blocking : file_descr -> bool Lwt.tblocking fd indicates whether Lwt is internally using blocking or
non-blocking I/O with fd.
Note that this may differ from the blocking mode of the underlying Unix
file descriptor (i.e. unix_file_descr fd).
See Lwt_unix.of_unix_file_descr for details.
val set_blocking : ?set_flags:bool -> file_descr -> bool -> unitset_blocking fd b causes Lwt to internally use blocking or non-blocking
I/O with fd, according to the value of b.
If ~set_flags is true (the default), Lwt also makes a system call to set
the underlying file descriptor's blocking mode to match. Otherwise,
set_blocking is only informational for Lwt.
It is important that the underlying file descriptor actually have the same
blocking mode as that indicated by b.
See Lwt_unix.of_unix_file_descr for details.
val abort : file_descr -> exn -> unitabort fd exn makes all current and further uses of the file
descriptor fail with the given exception. This put the file
descriptor into the Aborted state.
If the file descriptor is closed, this does nothing, if it is
aborted, this replace the abort exception by exn.
Note that this only works for reading and writing operations on
file descriptors supporting non-blocking mode.
val fork : unit -> intfork () does the same as Unix.fork. You must use this
function instead of Unix.fork when you want to use Lwt in the
child process.
Notes:
Lwt_io.flush_all before callling
Lwt_unix.fork to avoid double-flush.typeprocess_status =Unix.process_status=
| |
WEXITED of |
| |
WSIGNALED of |
| |
WSTOPPED of |
typewait_flag =Unix.wait_flag=
| |
WNOHANG |
| |
WUNTRACED |
val wait : unit -> (int * process_status) Lwt.tUnix.waitval waitpid : wait_flag list -> int -> (int * process_status) Lwt.tUnix.waitpidtype resource_usage = {
|
ru_utime : |
(* |
User time used
| *) |
|
ru_stime : |
(* |
System time used
| *) |
val wait4 : wait_flag list ->
int -> (int * process_status * resource_usage) Lwt.twait4 flags pid returns (pid, status, rusage) where (pid,
status) is the same result as Unix.waitpid flags pid, and
rusage contains accounting information about the child.
On windows it will always returns { utime = 0.0; stime = 0.0 }.
val wait_count : unit -> intval system : string -> process_status Lwt.t/bin/sh on Unix and cmd.exe on Windows. The result
WEXITED 127 indicates that the shell couldn't be executed.val stdin : file_descrval stdout : file_descrval stderr : file_descrtypefile_perm =Unix.file_perm
typeopen_flag =Unix.open_flag=
| |
O_RDONLY |
| |
O_WRONLY |
| |
O_RDWR |
| |
O_NONBLOCK |
| |
O_APPEND |
| |
O_CREAT |
| |
O_TRUNC |
| |
O_EXCL |
| |
O_NOCTTY |
| |
O_DSYNC |
| |
O_SYNC |
| |
O_RSYNC |
| |
O_SHARE_DELETE |
| |
O_CLOEXEC |
| |
O_KEEPEXEC |
val openfile : string ->
open_flag list -> file_perm -> file_descr Lwt.tUnix.openfile.val close : file_descr -> unit Lwt.tClosedval read : file_descr -> bytes -> int -> int -> int Lwt.tread fd buf ofs len reads up to len bytes from fd, and writes them to
buf, starting at offset ofs. The function immediately evaluates to an
Lwt thread, which waits for the operation to complete. If it completes
successfully, the thread indicates the number of bytes actually read, or
zero if the end of file has been reached.
Note that the Lwt thread waits for data (or end of file) even if the
underlying file descriptor is in non-blocking mode. See
Lwt_unix.of_unix_file_descr for a discussion of non-blocking I/O and Lwt.
If Lwt is using blocking I/O on fd, read writes data into a temporary
buffer, then copies it into buf.
The thread can fail with any exception that can be raised by Unix.read,
except Unix.Unix_error Unix.EAGAIN, Unix.Unix_error Unix.EWOULDBLOCK or
Unix.Unix_error Unix.EINTR.
val write : file_descr -> bytes -> int -> int -> int Lwt.twrite fd buf ofs len writes up to len bytes to fd from buf, starting
at buffer offset ofs. The function immediately evaluates to an Lwt thread,
which waits for the operation to complete. If the operation completes
successfully, the thread indicates the number of bytes actually written,
which may be less than len.
Note that the Lwt thread waits to write even if the underlying file
descriptor is in non-blocking mode. See Lwt_unix.of_unix_file_descr for a
discussion of non-blocking I/O and Lwt.
If Lwt is using blocking I/O on fd, buf is copied before writing.
The thread can fail with any exception that can be raised by
Unix.single_write, except Unix.Unix_error Unix.EAGAIN,
Unix.Unix_error Unix.EWOULDBLOCK or Unix.Unix_error Unix.EINTR.
val write_string : file_descr -> string -> int -> int -> int Lwt.tLwt_unix.write.module IO_vectors:sig..end
Lwt_unix.writev.
val readv : file_descr -> IO_vectors.t -> int Lwt.treadv fd vs reads bytes from fd into the buffer slices vs. If the
operation completes successfully, the resulting thread indicates the number
of bytes read.
Data is always read directly into Bigarray slices. If the Unix file
descriptor underlying fd is in non-blocking mode, data is also read
directly into bytes slices. Otherwise, data for bytes slices is first
read into temporary buffers, then copied.
Note that the returned Lwt thread is blocked until failure or a successful
read, even if the underlying file descriptor is in non-blocking mode. See
Lwt_unix.of_unix_file_descr for a discussion of non-blocking I/O and Lwt.
If Lwt_unix.IO_vectors.system_limit is Some n and the count of slices in vs
exceeds n, then Lwt_unix.readv reads only into the first n slices of
vs.
Not implemented on Windows. It should be possible to implement, upon request, for Windows sockets only.
See readv(3p).
Since 2.7.0
val writev : file_descr -> IO_vectors.t -> int Lwt.twritev fd vs writes the bytes in the buffer slices vs to the file
descriptor fd. If the operation completes successfully, the resulting
thread indicates the number of bytes written.
If the Unix file descriptor underlying fd is in non-blocking mode,
writev does not make a copy the bytes before writing. Otherwise, it copies
bytes slices, but not Bigarray slices.
Note that the returned Lwt thread is blocked until failure or a successful
write, even if the underlying descriptor is in non-blocking mode. See
Lwt_unix.of_unix_file_descr for a discussion of non-blocking I/O and Lwt.
If Lwt_unix.IO_vectors.system_limit is Some n and the count of slices in vs
exceeds n, then Lwt_unix.writev passes only the first n slices in vs
to the underlying writev system call.
Not implemented on Windows. It should be possible to implement, upon request, for Windows sockets only.
The behavior of writev when vs has zero slices depends on the system,
and may change in future versions of Lwt. On Linux, writev will succeed
and write zero bytes. On BSD (including macOS), writev will fail with
Unix.Unix_error (Unix.EINVAL, "writev", ...).
See
writev(3p).
Since 2.7.0
val readable : file_descr -> boolval writable : file_descr -> boolval wait_read : file_descr -> unit Lwt.tval wait_write : file_descr -> unit Lwt.ttypeseek_command =Unix.seek_command=
| |
SEEK_SET |
| |
SEEK_CUR |
| |
SEEK_END |
val lseek : file_descr -> int -> seek_command -> int Lwt.tUnix.lseekval truncate : string -> int -> unit Lwt.tUnix.truncateval ftruncate : file_descr -> int -> unit Lwt.tUnix.ftruncateval fsync : file_descr -> unit Lwt.tFlushFileBuffers.val fdatasync : file_descr -> unit Lwt.t
Note that fdatasync is not available on Windows and OS X.
typefile_kind =Unix.file_kind=
| |
S_REG |
| |
S_DIR |
| |
S_CHR |
| |
S_BLK |
| |
S_LNK |
| |
S_FIFO |
| |
S_SOCK |
typestats =Unix.stats= {
|
st_dev : |
|
st_ino : |
|
st_kind : |
|
st_perm : |
|
st_nlink : |
|
st_uid : |
|
st_gid : |
|
st_rdev : |
|
st_size : |
|
st_atime : |
|
st_mtime : |
|
st_ctime : |
val stat : string -> stats Lwt.tUnix.statval lstat : string -> stats Lwt.tUnix.lstatval fstat : file_descr -> stats Lwt.tUnix.fstatval 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 Lwt_unix.stat raise a
Unix.Unix_error exception.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..
This function corresponds to
Unix.utimes. See also
utimes(3p).
Since 2.6.0
val isatty : file_descr -> bool Lwt.tUnix.isattymodule LargeFile:sig..end
val unlink : string -> unit Lwt.tUnix.unlinkval rename : string -> string -> unit Lwt.tUnix.renameval link : string -> string -> unit Lwt.tUnix.linkval chmod : string -> file_perm -> unit Lwt.tUnix.chmodval fchmod : file_descr -> file_perm -> unit Lwt.tUnix.fchmodval chown : string -> int -> int -> unit Lwt.tUnix.chownval fchown : file_descr -> int -> int -> unit Lwt.tUnix.fchowntypeaccess_permission =Unix.access_permission=
| |
R_OK |
| |
W_OK |
| |
X_OK |
| |
F_OK |
val access : string -> access_permission list -> unit Lwt.tUnix.accessval dup : file_descr -> file_descrUnix.dupval dup2 : file_descr -> file_descr -> unitUnix.dup2val set_close_on_exec : file_descr -> unitUnix.set_close_on_execval clear_close_on_exec : file_descr -> unitUnix.clear_close_on_execval mkdir : string -> file_perm -> unit Lwt.tUnix.mkdirval rmdir : string -> unit Lwt.tUnix.rmdirval chdir : string -> unit Lwt.tUnix.chdirval chroot : string -> unit Lwt.tUnix.chroottypedir_handle =Unix.dir_handle
val opendir : string -> dir_handle Lwt.tLwt_unix.closedir. This is a cooperative analog of
Unix.opendir.val readdir : dir_handle -> string Lwt.t. and .. are included. If all entries have been read, raises
End_of_file. This is a cooperative analog of
Unix.readdir.val readdir_n : dir_handle -> int -> string array Lwt.treaddir_n handle count reads at most count entries from the
given directory. It is more efficient than calling readdir
count times. If the length of the returned array is smaller
than count, this means that the end of the directory has been
reached.val rewinddir : dir_handle -> unit Lwt.tUnix.rewinddir.val closedir : dir_handle -> unit Lwt.tUnix.closedir.val files_of_directory : string -> string Lwt_stream.tfiles_of_directory dir returns the stream of all files of
dir.val pipe : unit -> file_descr * file_descrpipe () creates pipe using Unix.pipe and returns two lwt file descriptors created from unix file_descriptorval pipe_in : unit -> file_descr * Unix.file_descrpipe_in () is the same as 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 Lwt_unix.pipe_in. You usually want to
use this before forking to send data to the child processval mkfifo : string -> file_perm -> unit Lwt.tUnix.mkfifoval symlink : string -> string -> unit Lwt.tUnix.symlinkval readlink : string -> string Lwt.tUnix.readlinktypelock_command =Unix.lock_command=
| |
F_ULOCK |
| |
F_LOCK |
| |
F_TLOCK |
| |
F_TEST |
| |
F_RLOCK |
| |
F_TRLOCK |
val lockf : file_descr -> lock_command -> int -> unit Lwt.tUnix.lockftypepasswd_entry =Unix.passwd_entry= {
|
pw_name : |
|
pw_passwd : |
|
pw_uid : |
|
pw_gid : |
|
pw_gecos : |
|
pw_dir : |
|
pw_shell : |
typegroup_entry =Unix.group_entry= {
|
gr_name : |
|
gr_passwd : |
|
gr_gid : |
|
gr_mem : |
val getlogin : unit -> string Lwt.tUnix.getloginval getpwnam : string -> passwd_entry Lwt.tUnix.getpwnamval getgrnam : string -> group_entry Lwt.tUnix.getgrnamval getpwuid : int -> passwd_entry Lwt.tUnix.getpwuidval getgrgid : int -> group_entry Lwt.tUnix.getgrgidtype 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 -> unitval signal_count : unit -> intval reinstall_signal_handler : int -> unitreinstall_signal_handler signum if any signal handler is
registered for this signal with Lwt_unix.on_signal, it reinstall the
signal handler (with Sys.set_signal). This is usefull in case
another part of the program install another signal handler.typeinet_addr =Unix.inet_addr
typesocket_domain =Unix.socket_domain=
| |
PF_UNIX |
| |
PF_INET |
| |
PF_INET6 |
typesocket_type =Unix.socket_type=
| |
SOCK_STREAM |
| |
SOCK_DGRAM |
| |
SOCK_RAW |
| |
SOCK_SEQPACKET |
typesockaddr =Unix.sockaddr=
| |
ADDR_UNIX of |
| |
ADDR_INET of |
val socket : socket_domain -> socket_type -> int -> file_descrsocket domain type proto is the same as Unix.socket but maps
the result into a lwt file descriptorval socketpair : socket_domain ->
socket_type -> int -> file_descr * file_descrUnix.socketpairval bind : file_descr -> sockaddr -> unitLwt_unix.Versioned.bind_2, whose result type is
unit Lwt.t instead of unit.Unix.bind. See also
bind(3p).val listen : file_descr -> int -> unitUnix.listenval accept : file_descr -> (file_descr * sockaddr) Lwt.tUnix.acceptval accept_n : file_descr ->
int -> ((file_descr * sockaddr) list * exn option) Lwt.taccept_n fd count accepts up to count connections at one time.
count are available, it returns
all of themcount are available, it returns the next
count of themaccept_n has the advantage of improving performance. If you
want a more detailed description, you can have a look at:
val connect : file_descr -> sockaddr -> unit Lwt.tUnix.connecttypeshutdown_command =Unix.shutdown_command=
| |
SHUTDOWN_RECEIVE |
| |
SHUTDOWN_SEND |
| |
SHUTDOWN_ALL |
val shutdown : file_descr -> shutdown_command -> unitUnix.shutdownval getsockname : file_descr -> sockaddrUnix.getsocknameval getpeername : file_descr -> sockaddrUnix.getpeernametypemsg_flag =Unix.msg_flag=
| |
MSG_OOB |
| |
MSG_DONTROUTE |
| |
MSG_PEEK |
val recv : file_descr ->
bytes -> int -> int -> msg_flag list -> int Lwt.tUnix.recv.
On Windows, recv writes data into a temporary buffer, then copies it into
the given one.
val recvfrom : file_descr ->
bytes ->
int -> int -> msg_flag list -> (int * sockaddr) Lwt.tUnix.recvfrom.
On Windows, recvfrom writes data into a temporary buffer, then copies it
into the given one.
val send : file_descr ->
bytes -> int -> int -> msg_flag list -> int Lwt.tUnix.send.
On Windows, send copies the given buffer before writing.
val sendto : file_descr ->
bytes ->
int -> int -> msg_flag list -> sockaddr -> int Lwt.tUnix.sendto.
On Windows, sendto copies the given buffer before writing.
type io_vector = {
|
iov_buffer : |
|
iov_offset : |
|
iov_length : |
val io_vector : buffer:string -> offset:int -> length:int -> io_vectorval recv_msg : socket:file_descr ->
io_vectors:io_vector list -> (int * Unix.file_descr list) Lwt.trecv_msg ~socket ~io_vectors receives data into a list of
io-vectors, plus any file-descriptors that may accompany the
messages. It returns a tuple whose first field is the number of
bytes received and second is a list of received file
descriptors. The messages themselves will be recorded in the
provided io_vectors list. Data is written directly into the
iov_buffer buffers.
Not implemented on Windows.
val send_msg : socket:file_descr ->
io_vectors:io_vector list -> fds:Unix.file_descr list -> int Lwt.tsend_msg ~socket ~io_vectors ~fds sends data from a list of
io-vectors, accompanied with a list of file-descriptors. It
returns the number of bytes sent. If fd-passing is not possible on
the current system and fds is not empty, it raises
Lwt_sys.Not_available "fd_passing". Data is written directly from
the iov_buffer buffers.
Not implemented on Windows.
type credentials = {
|
cred_pid : |
|
cred_uid : |
|
cred_gid : |
val get_credentials : file_descr -> credentialsget_credentials fd returns credentials information from the
given socket. On some platforms, obtaining the peer pid is not
possible and it will be set to -1. If obtaining credentials
is not possible on the current system, it raises
Lwt_sys.Not_available "get_credentials".
This call is not available on windows.
typesocket_bool_option =Unix.socket_bool_option=
| |
SO_DEBUG |
| |
SO_BROADCAST |
| |
SO_REUSEADDR |
| |
SO_KEEPALIVE |
| |
SO_DONTROUTE |
| |
SO_OOBINLINE |
| |
SO_ACCEPTCONN |
| |
TCP_NODELAY |
| |
IPV6_ONLY |
typesocket_int_option =Unix.socket_int_option=
| |
SO_SNDBUF |
| |
SO_RCVBUF |
| |
SO_ERROR |
| |
SO_TYPE |
| |
SO_RCVLOWAT |
| |
SO_SNDLOWAT |
typesocket_optint_option =Unix.socket_optint_option=
| |
SO_LINGER |
typesocket_float_option =Unix.socket_float_option=
| |
SO_RCVTIMEO |
| |
SO_SNDTIMEO |
val getsockopt : file_descr -> socket_bool_option -> boolUnix.getsockoptval setsockopt : file_descr -> socket_bool_option -> bool -> unitUnix.setsockoptval getsockopt_int : file_descr -> socket_int_option -> intUnix.getsockopt_intval setsockopt_int : file_descr -> socket_int_option -> int -> unitUnix.setsockopt_intval getsockopt_optint : file_descr -> socket_optint_option -> int optionUnix.getsockopt_optintval setsockopt_optint : file_descr -> socket_optint_option -> int option -> unitUnix.setsockopt_optintval getsockopt_float : file_descr -> socket_float_option -> floatUnix.getsockopt_floatval setsockopt_float : file_descr -> socket_float_option -> float -> unitUnix.setsockopt_floatval getsockopt_error : file_descr -> Unix.error optionUnix.getsockopt_errorval mcast_set_loop : file_descr -> bool -> unitval mcast_set_ttl : file_descr -> int -> unitval mcast_add_membership : file_descr -> ?ifname:Unix.inet_addr -> Unix.inet_addr -> unitmcast_add_membership fd ~ifname addr joins the multicast group addr
on the network interface ifname.val mcast_drop_membership : file_descr -> ?ifname:Unix.inet_addr -> Unix.inet_addr -> unitmcast_drop_membership fd ~ifname addr leaves the multicast group addr
on the network interface ifname.typehost_entry =Unix.host_entry= {
|
h_name : |
|
h_aliases : |
|
h_addrtype : |
|
h_addr_list : |
typeprotocol_entry =Unix.protocol_entry= {
|
p_name : |
|
p_aliases : |
|
p_proto : |
typeservice_entry =Unix.service_entry= {
|
s_name : |
|
s_aliases : |
|
s_port : |
|
s_proto : |
val gethostname : unit -> string Lwt.tUnix.gethostnameval gethostbyname : string -> host_entry Lwt.tUnix.gethostbynameval gethostbyaddr : inet_addr -> host_entry Lwt.tUnix.gethostbyaddrval getprotobyname : string -> protocol_entry Lwt.tUnix.getprotobynameval getprotobynumber : int -> protocol_entry Lwt.tUnix.getprotobynumberval getservbyname : string -> string -> service_entry Lwt.tUnix.getservbynameval getservbyport : int -> string -> service_entry Lwt.tUnix.getservbyporttypeaddr_info =Unix.addr_info= {
|
ai_family : |
|
ai_socktype : |
|
ai_protocol : |
|
ai_addr : |
|
ai_canonname : |
typegetaddrinfo_option =Unix.getaddrinfo_option=
| |
AI_FAMILY of |
| |
AI_SOCKTYPE of |
| |
AI_PROTOCOL of |
| |
AI_NUMERICHOST |
| |
AI_CANONNAME |
| |
AI_PASSIVE |
val getaddrinfo : string ->
string -> getaddrinfo_option list -> addr_info list Lwt.tUnix.getaddrinfotypename_info =Unix.name_info= {
|
ni_hostname : |
|
ni_service : |
typegetnameinfo_option =Unix.getnameinfo_option=
| |
NI_NOFQDN |
| |
NI_NUMERICHOST |
| |
NI_NAMEREQD |
| |
NI_NUMERICSERV |
| |
NI_DGRAM |
val getnameinfo : sockaddr ->
getnameinfo_option list -> name_info Lwt.tUnix.getnameinfotypeterminal_io =Unix.terminal_io= {
|
mutable c_ignbrk : |
|
mutable c_brkint : |
|
mutable c_ignpar : |
|
mutable c_parmrk : |
|
mutable c_inpck : |
|
mutable c_istrip : |
|
mutable c_inlcr : |
|
mutable c_igncr : |
|
mutable c_icrnl : |
|
mutable c_ixon : |
|
mutable c_ixoff : |
|
mutable c_opost : |
|
mutable c_obaud : |
|
mutable c_ibaud : |
|
mutable c_csize : |
|
mutable c_cstopb : |
|
mutable c_cread : |
|
mutable c_parenb : |
|
mutable c_parodd : |
|
mutable c_hupcl : |
|
mutable c_clocal : |
|
mutable c_isig : |
|
mutable c_icanon : |
|
mutable c_noflsh : |
|
mutable c_echo : |
|
mutable c_echoe : |
|
mutable c_echok : |
|
mutable c_echonl : |
|
mutable c_vintr : |
|
mutable c_vquit : |
|
mutable c_verase : |
|
mutable c_vkill : |
|
mutable c_veof : |
|
mutable c_veol : |
|
mutable c_vmin : |
|
mutable c_vtime : |
|
mutable c_vstart : |
|
mutable c_vstop : |
val tcgetattr : file_descr -> terminal_io Lwt.tUnix.tcgetattrtypesetattr_when =Unix.setattr_when=
| |
TCSANOW |
| |
TCSADRAIN |
| |
TCSAFLUSH |
val tcsetattr : file_descr ->
setattr_when -> terminal_io -> unit Lwt.tUnix.tcsetattrval tcsendbreak : file_descr -> int -> unit Lwt.tUnix.tcsendbreakval tcdrain : file_descr -> unit Lwt.tUnix.tcdraintypeflush_queue =Unix.flush_queue=
| |
TCIFLUSH |
| |
TCOFLUSH |
| |
TCIOFLUSH |
val tcflush : file_descr -> flush_queue -> unit Lwt.tUnix.tcflushtypeflow_action =Unix.flow_action=
| |
TCOOFF |
| |
TCOON |
| |
TCIOFF |
| |
TCION |
val tcflow : file_descr -> flow_action -> unit Lwt.tUnix.tcflowexception Retry
Lwt_unix.Retry, it will be requeued until the file descriptor becomes readable/writable again.exception Retry_read
Lwt_unix.Retry_read, it will be requeued until the
file descriptor becomes readable.exception Retry_write
Lwt_unix.Retry_read, it will be requeued until the
file descriptor becomes writables.type io_event =
| |
Read |
| |
Write |
val wrap_syscall : io_event -> file_descr -> (unit -> 'a) -> 'a Lwt.twrap_syscall set fd action wrap an action on a file
descriptor. It tries to execute action, and if it can not be
performed immediately without blocking, it is registered for
later.
In the latter case, if the thread is canceled, action is
removed from set.
val check_descriptor : file_descr -> unitcheck_descriptor fd raise an exception if fd is not in the
state Openval register_action : io_event -> file_descr -> (unit -> 'a) -> 'a Lwt.tregister_action set fd action registers action on fd. When
fd becomes readable/writable action is called.
Note:
check_descriptor fd before calling
register_actionLwt_unix.wrap_syscalltype 'a job
val run_job : ?async_method:async_method -> 'a job -> 'a Lwt.trun_job ?async_method job starts job and wait for its
termination.
The async method is choosen follow:
async_method is specified, it is
used,Lwt_unix.async_method_key is set in the
current thread, it is used,Lwt_unix.default_async_method) is used.Async_none then the job is run synchronously
and may block the current system thread, thus blocking all Lwt
threads.
If the method is Async_detach then the job is run in another
system thread, unless the the maximum number of worker threads
has been reached (as given by Lwt_unix.pool_size).
If the method is Async_switch then the job is run
synchronously and if it blocks, execution will continue in
another system thread (unless the limit is reached).
val abort_jobs : exn -> unitabort_jobs exn make all pending jobs to fail with exn. Note
that this does not abort the real job (i.e. the C function
executing it), just the lwt thread for it.val cancel_jobs : unit -> unitcancel_jobs () is the same as abort_jobs Lwt.Canceled.val wait_for_jobs : unit -> unit Lwt.tval execute_job : ?async_method:async_method ->
job:'a job ->
result:('a job -> 'b) -> free:('a job -> unit) -> 'b Lwt.trun_job.val make_notification : ?once:bool -> (unit -> unit) -> intnew_notifier ?once f registers a new notifier. It returns the
id of the notifier. Each time a notification with this id is
received, f is called.
if once is specified, then the notification is stopped after
the first time it is received. It defaults to false.
val send_notification : int -> unitsend_notification id sends a notification.
This function is thread-safe.
val stop_notification : int -> unitval call_notification : int -> unitonce = true it is removed.val set_notification : int -> (unit -> unit) -> unitset_notification id f replace the function associated to the
notification by f. It raises Not_found if the given
notification is not found.Async_detach or
Async_switch, Lwt will launch system threads to execute
blocking system calls asynchronously.val pool_size : unit -> intval set_pool_size : int -> unitval thread_count : unit -> intval thread_waiting_count : unit -> intval get_cpu : unit -> intget_cpu () returns the number of the CPU the current thread is
running on.val get_affinity : ?pid:int -> unit -> int listget_affinity ?pid () returns the list of CPUs the process with
pid pid is allowed to run on. If pid is not specified then
the affinity of the current process is returned.val set_affinity : ?pid:int -> int list -> unitset_affinity ?pid cpus sets the list of CPUs the given process
is allowed to run on.module Versioned:sig..end