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.t
Unix.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 -> unit
val async_method : unit -> async_method
async_method ()
returns the async method used in the current
thread.val async_method_key : async_method Lwt.key
val with_async_none : (unit -> 'a) -> 'a
with_async_none f
is a shorthand for:
Lwt.with_value async_method_key (Some Async_none) f
val with_async_detach : (unit -> 'a) -> 'a
with_async_detach f
is a shorthand for:
Lwt.with_value async_method_key (Some Async_detach) f
val with_async_switch : (unit -> 'a) -> 'a
with_async_switch f
is a shorthand for:
Lwt.with_value async_method_key (Some Async_switch) f
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
val timeout : float -> 'a Lwt.t
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 ()]
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 -> state
state fd
returns the state of fd
val unix_file_descr : file_descr -> Unix.file_descr
Open
.val of_unix_file_descr : ?blocking:bool -> ?set_flags:bool -> Unix.file_descr -> file_descr
blocking
is the blocking mode of the file-descriptor, and
describes how Lwt will use it. In non-blocking mode, read/write
on this file descriptor are made using non-blocking IO; in
blocking mode they are made using the current async method. If
blocking
is not specified it is guessed according to the file
kind: socket and pipes are in non-blocking mode and others are
in blocking mode.
If set_flags
is true
(the default) then the file flags are
modified according to the blocking
argument, otherwise they
are left unchanged.
Note that the blocking mode is less efficient than the
non-blocking one, so it should be used only for file descriptors
that does not support asynchronous operations, such as regular
files, or for shared descriptors such as Lwt_unix.stdout
, Lwt_unix.stderr
or
Lwt_unix.stdin
.
val blocking : file_descr -> bool Lwt.t
blocking fd
returns whether fd
is used in blocking or
non-blocking mode.val set_blocking : ?set_flags:bool -> file_descr -> bool -> unit
set_blocking fd b
puts fd
in blocking or non-blocking
mode. If set_flags
is true
(the default) then the file flags
are modified, otherwise the modification is only done at the
application level.val abort : file_descr -> exn -> unit
abort 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 -> int
fork ()
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.t
Unix.wait
val waitpid : wait_flag list -> int -> (int * process_status) Lwt.t
Unix.waitpid
type
resource_usage = {
|
ru_utime : |
(* |
User time used
| *) |
|
ru_stime : |
(* |
System time used
| *) |
val wait4 : wait_flag list ->
int -> (int * process_status * resource_usage) Lwt.t
wait4 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 -> int
val 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_descr
val stdout : file_descr
val stderr : file_descr
typefile_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 |
val openfile : string ->
open_flag list -> file_perm -> file_descr Lwt.t
Unix.openfile
.val close : file_descr -> unit Lwt.t
Closed
val read : file_descr -> Bytes.t -> int -> int -> int Lwt.t
read fd buf ofs len
has the same semantic as Unix.read
, but
is cooperativeval write : file_descr -> Bytes.t -> int -> int -> int Lwt.t
write fd buf ofs len
has the same semantic as Unix.write
, but
is cooperativeval write_string : file_descr -> string -> int -> int -> int Lwt.t
Lwt_unix.write
.val readable : file_descr -> bool
val writable : file_descr -> bool
val wait_read : file_descr -> unit Lwt.t
val wait_write : file_descr -> unit Lwt.t
typeseek_command =
Unix.seek_command
=
| |
SEEK_SET |
| |
SEEK_CUR |
| |
SEEK_END |
val lseek : file_descr -> int -> seek_command -> int Lwt.t
Unix.lseek
val truncate : string -> int -> unit Lwt.t
Unix.truncate
val ftruncate : file_descr -> int -> unit Lwt.t
Unix.ftruncate
val fsync : file_descr -> unit Lwt.t
FlushFileBuffers
.val fdatasync : file_descr -> unit Lwt.t
Note that fdatasync
is not available on all platforms.
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.t
Unix.stat
val lstat : string -> stats Lwt.t
Unix.lstat
val fstat : file_descr -> stats Lwt.t
Unix.fstat
val file_exists : string -> bool Lwt.t
file_exists name
tests if a file named name
exists.val isatty : file_descr -> bool Lwt.t
Unix.isatty
module LargeFile:sig
..end
val unlink : string -> unit Lwt.t
Unix.unlink
val rename : string -> string -> unit Lwt.t
Unix.rename
val link : string -> string -> unit Lwt.t
Unix.link
val chmod : string -> file_perm -> unit Lwt.t
Unix.chmod
val fchmod : file_descr -> file_perm -> unit Lwt.t
Unix.fchmod
val chown : string -> int -> int -> unit Lwt.t
Unix.chown
val fchown : file_descr -> int -> int -> unit Lwt.t
Unix.fchown
typeaccess_permission =
Unix.access_permission
=
| |
R_OK |
| |
W_OK |
| |
X_OK |
| |
F_OK |
val access : string -> access_permission list -> unit Lwt.t
Unix.access
val dup : file_descr -> file_descr
Unix.dup
val dup2 : file_descr -> file_descr -> unit
Unix.dup2
val set_close_on_exec : file_descr -> unit
Unix.set_close_on_exec
val clear_close_on_exec : file_descr -> unit
Unix.clear_close_on_exec
val mkdir : string -> file_perm -> unit Lwt.t
Unix.mkdir
val rmdir : string -> unit Lwt.t
Unix.rmdir
val chdir : string -> unit Lwt.t
Unix.chdir
val chroot : string -> unit Lwt.t
Unix.chroot
typedir_handle =
Unix.dir_handle
val opendir : string -> dir_handle Lwt.t
Unix.opendir
val readdir : dir_handle -> string Lwt.t
Unix.readdir
.val readdir_n : dir_handle -> int -> string array Lwt.t
readdir_n handle count
reads at most count
entry 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.t
Unix.rewinddir
val closedir : dir_handle -> unit Lwt.t
Unix.closedir
val files_of_directory : string -> string Lwt_stream.t
files_of_directory dir
returns the stream of all files of
dir
.val pipe : unit -> file_descr * file_descr
pipe ()
creates pipe using Unix.pipe
and returns two lwt file descriptors created from unix file_descriptorval pipe_in : unit -> file_descr * Unix.file_descr
pipe_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_descr
pipe_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.t
Unix.mkfifo
val symlink : string -> string -> unit Lwt.t
Unix.symlink
val readlink : string -> string Lwt.t
Unix.readlink
typelock_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.t
Unix.lockf
typepasswd_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.t
Unix.getlogin
val getpwnam : string -> passwd_entry Lwt.t
Unix.getpwnam
val getgrnam : string -> group_entry Lwt.t
Unix.getgrnam
val getpwuid : int -> passwd_entry Lwt.t
Unix.getpwuid
val getgrgid : int -> group_entry Lwt.t
Unix.getgrgid
type
signal_handler_id
val on_signal : int -> (int -> unit) -> signal_handler_id
on_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_id
on_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 -> unit
val signal_count : unit -> int
val reinstall_signal_handler : int -> unit
reinstall_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_descr
socket 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_descr
Unix.socketpair
val bind : file_descr -> sockaddr -> unit
Unix.bind
val listen : file_descr -> int -> unit
Unix.listen
val accept : file_descr -> (file_descr * sockaddr) Lwt.t
Unix.accept
val accept_n : file_descr ->
int -> ((file_descr * sockaddr) list * exn option) Lwt.t
accept_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.t
Unix.connect
typeshutdown_command =
Unix.shutdown_command
=
| |
SHUTDOWN_RECEIVE |
| |
SHUTDOWN_SEND |
| |
SHUTDOWN_ALL |
val shutdown : file_descr -> shutdown_command -> unit
Unix.shutdown
val getsockname : file_descr -> sockaddr
Unix.getsockname
val getpeername : file_descr -> sockaddr
Unix.getpeername
typemsg_flag =
Unix.msg_flag
=
| |
MSG_OOB |
| |
MSG_DONTROUTE |
| |
MSG_PEEK |
val recv : file_descr ->
Bytes.t -> int -> int -> msg_flag list -> int Lwt.t
Unix.recv
val recvfrom : file_descr ->
Bytes.t ->
int -> int -> msg_flag list -> (int * sockaddr) Lwt.t
Unix.recvfrom
val send : file_descr ->
Bytes.t -> int -> int -> msg_flag list -> int Lwt.t
Unix.send
val sendto : file_descr ->
Bytes.t ->
int -> int -> msg_flag list -> sockaddr -> int Lwt.t
Unix.sendto
type
io_vector = {
|
iov_buffer : |
|
iov_offset : |
|
iov_length : |
val io_vector : buffer:string -> offset:int -> length:int -> io_vector
val recv_msg : socket:file_descr ->
io_vectors:io_vector list -> (int * Unix.file_descr list) Lwt.t
recv_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.
This call is not available on windows.
val send_msg : socket:file_descr ->
io_vectors:io_vector list -> fds:Unix.file_descr list -> int Lwt.t
send_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"
.
This call is not available on windows.
type
credentials = {
|
cred_pid : |
|
cred_uid : |
|
cred_gid : |
val get_credentials : file_descr -> credentials
get_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 -> bool
Unix.getsockopt
val setsockopt : file_descr -> socket_bool_option -> bool -> unit
Unix.setsockopt
val getsockopt_int : file_descr -> socket_int_option -> int
Unix.getsockopt_int
val setsockopt_int : file_descr -> socket_int_option -> int -> unit
Unix.setsockopt_int
val getsockopt_optint : file_descr -> socket_optint_option -> int option
Unix.getsockopt_optint
val setsockopt_optint : file_descr -> socket_optint_option -> int option -> unit
Unix.setsockopt_optint
val getsockopt_float : file_descr -> socket_float_option -> float
Unix.getsockopt_float
val setsockopt_float : file_descr -> socket_float_option -> float -> unit
Unix.setsockopt_float
val getsockopt_error : file_descr -> Unix.error option
Unix.getsockopt_error
val mcast_set_loop : file_descr -> bool -> unit
val mcast_set_ttl : file_descr -> int -> unit
val mcast_add_membership : file_descr -> ?ifname:Unix.inet_addr -> Unix.inet_addr -> unit
mcast_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 -> unit
mcast_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.t
Unix.gethostname
val gethostbyname : string -> host_entry Lwt.t
Unix.gethostbyname
val gethostbyaddr : inet_addr -> host_entry Lwt.t
Unix.gethostbyaddr
val getprotobyname : string -> protocol_entry Lwt.t
Unix.getprotobyname
val getprotobynumber : int -> protocol_entry Lwt.t
Unix.getprotobynumber
val getservbyname : string -> string -> service_entry Lwt.t
Unix.getservbyname
val getservbyport : int -> string -> service_entry Lwt.t
Unix.getservbyport
typeaddr_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.t
Unix.getaddrinfo
typename_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.t
Unix.getnameinfo
typeterminal_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.t
Unix.tcgetattr
typesetattr_when =
Unix.setattr_when
=
| |
TCSANOW |
| |
TCSADRAIN |
| |
TCSAFLUSH |
val tcsetattr : file_descr ->
setattr_when -> terminal_io -> unit Lwt.t
Unix.tcsetattr
val tcsendbreak : file_descr -> int -> unit Lwt.t
Unix.tcsendbreak
val tcdrain : file_descr -> unit Lwt.t
Unix.tcdrain
typeflush_queue =
Unix.flush_queue
=
| |
TCIFLUSH |
| |
TCOFLUSH |
| |
TCIOFLUSH |
val tcflush : file_descr -> flush_queue -> unit Lwt.t
Unix.tcflush
typeflow_action =
Unix.flow_action
=
| |
TCOOFF |
| |
TCOON |
| |
TCIOFF |
| |
TCION |
val tcflow : file_descr -> flow_action -> unit Lwt.t
Unix.tcflow
exception 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.t
wrap_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 -> unit
check_descriptor fd
raise an exception if fd
is not in the
state Open
val register_action : io_event -> file_descr -> (unit -> 'a) -> 'a Lwt.t
register_action set fd action
registers action
on fd
. When
fd
becomes readable
/writable
action
is called.
Note:
check_descriptor fd
before calling
register_action
Lwt_unix.wrap_syscall
type 'a
job
val execute_job : ?async_method:async_method ->
job:'a job ->
result:('a job -> 'b) -> free:('a job -> unit) -> 'b Lwt.t
Lwt_unix.run_job
in new code.val run_job : ?async_method:async_method -> 'a job -> 'a Lwt.t
run_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 -> unit
abort_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 -> unit
cancel_jobs ()
is the same as abort_jobs Lwt.Canceled
.val wait_for_jobs : unit -> unit Lwt.t
val make_notification : ?once:bool -> (unit -> unit) -> int
new_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 -> unit
send_notification id
sends a notification.
This function is thread-safe.
val stop_notification : int -> unit
val call_notification : int -> unit
once = true
it is removed.val set_notification : int -> (unit -> unit) -> unit
set_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 -> int
val set_pool_size : int -> unit
val thread_count : unit -> int
val thread_waiting_count : unit -> int
val get_cpu : unit -> int
get_cpu ()
returns the number of the CPU the current thread is
running on.val get_affinity : ?pid:int -> unit -> int list
get_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 -> unit
set_affinity ?pid cpus
sets the list of CPUs the given process
is allowed to run on.