Uwt.UdpUDP handles encapsulate UDP communication for both clients and servers.
include module type of Handle with type t := tval close : t -> Int_result.unitHandles are closed automatically, if they are not longer referenced from the OCaml heap. Nevertheless, you should nearly always close them with close, because:
However, it's safe to write code in this manner:
let s = Uwt.Tcp.init () in
let c = Uwt.Tcp.init () in
Uwt.Tcp.nodelay s false;
Uwt.Tcp.simultaneous_accepts true;
if foobar () then (* no file descriptor yet assigned, no need to worry
about exceptions inside foobar,... *)
Lwt.return_unit (* no need to close *)
else
...If you want - for whatever reason - keep a file descriptor open for the whole lifetime of your process, remember to keep a reference to its handle.
val close_noerr : t -> unitPrefer close or close_noerr to close_wait. close or close_noerr return immediately (there are no useful error messages, beside perhaps a notice, that you've already closed that handle).
close_wait is only useful, if you intend to wait until all concurrent write and read threads related to this handle are canceled.
val is_active : t -> boolReturns non-zero if the handle is active, zero if it's inactive. What "active" means depends on the type of handle:
Async.t handle is always active and cannot be deactivated, except by closing it with uv_close().Pipe.t, Tcp.t, Udp.t, etc. handle - basically any handle that deals with i/o - is active when it is doing something that involves i/o, like reading, writing, connecting, accepting new connections, etc.Rule of thumb: if a handle of type Uwt.Foo.t has a uv_foo_start() function, then it's active from the moment that function is called. Likewise, uv_foo_stop() deactivates the handle again.
val ref' : t -> unitReference the given handle. References are idempotent, that is, if a handle is already referenced calling this function again will have no effect.
val unref : t -> unitUn-reference the given handle. References are idempotent, that is, if a handle is not referenced calling this function again will have no effect.
val has_ref : t -> boolReturns non-zero if the handle is referenced, zero otherwise.
include module type of Handle_ext with type t := tval get_send_buffer_size : t -> Int_result.intGets the size of the send buffer that the operating system uses for the socket.
val get_send_buffer_size_exn : t -> intval get_recv_buffer_size : t -> Int_result.intGets the size of the receive buffer that the operating system uses for the socket.
val get_recv_buffer_size_exn : t -> intval set_send_buffer_size : t -> int -> Int_result.unitSets the size of the send buffer that the operating system uses for the socket.
val set_send_buffer_size_exn : t -> int -> unitval set_recv_buffer_size : t -> int -> Int_result.unitSets the size of the receive buffer that the operating system uses for the socket.
val set_recv_buffer_size_exn : t -> int -> unitinclude module type of Handle_fileno with type t := tval fileno : t -> Unix.file_descr uv_resultval fileno_exn : t -> Unix.file_descrval send_queue_size : t -> intNumber of bytes queued for sending; strictly shows how much information is currently queued.
val send_queue_count : t -> intNumber of send requests currently in the queue awaiting to be processed.
wrappers around uv_udp_init_ex. A socket of the given type will be created immediately instead of lazy (init)
val init_ipv4_exn : unit -> tval init_ipv6_exn : unit -> tval openudp : Unix.file_descr -> t uv_resultSee comment to Pipe.openpipe
val openudp_exn : Unix.file_descr -> tval bind : ?mode:mode list -> t -> addr:sockaddr -> unit -> Int_result.unitBind the UDP handle to an IP address and port.
val set_membership :
?interface:string ->
t ->
multicast:string ->
membership ->
Int_result.unitSet membership for a multicast address
val set_membership_exn :
?interface:string ->
t ->
multicast:string ->
membership ->
unitval set_multicast_loop : t -> bool -> Int_result.unitSet IP multicast loop flag. Makes multicast packets loop back to local sockets
val set_multicast_loop_exn : t -> bool -> unitval set_multicast_ttl : t -> int -> Int_result.unitSet the multicast ttl, ttl - 1 through 255.
val set_multicast_ttl_exn : t -> int -> unitval set_multicast_interface : t -> string option -> Int_result.unitSet the multicast interface to send or receive data on
val set_multicast_interface_exn : t -> string option -> unitval set_broadcast : t -> bool -> Int_result.unitSet broadcast on or off.
val set_broadcast_exn : t -> bool -> unitval set_ttl : t -> int -> Int_result.unitSet the time to live. ttl - 1 through 255.
val set_ttl_exn : t -> int -> unitSend data over the UDP socket. If the socket has not previously been bound with uv_udp_bind() it will be bound to 0.0.0.0 (the "all interfaces" IPv4 address) and a random port number.
See comment to Stream.write_raw
val try_send :
?pos:int ->
?len:int ->
buf:bytes ->
t ->
sockaddr ->
Int_result.intSame as send, but won't queue a send request if it can't be completed immediately.
val try_send_ba :
?pos:int ->
?len:int ->
buf:buf ->
t ->
sockaddr ->
Int_result.intval try_send_string :
?pos:int ->
?len:int ->
buf:string ->
t ->
sockaddr ->
Int_result.intval try_sendv : t -> Iovec_write.t list -> sockaddr -> Int_result.intval sendv_raw : t -> Iovec_write.t list -> sockaddr -> unit Lwt.tval sendv : t -> Iovec_write.t list -> sockaddr -> unit Lwt.tval recv_start : t -> cb:(recv_result -> unit) -> Int_result.unitPrepare for receiving data. If the socket has not previously been bound with uv_udp_bind() it is bound to 0.0.0.0 (the "all interfaces" IPv4 address) and a random port number.
val recv_start_exn : t -> cb:(recv_result -> unit) -> unitval recv_stop : t -> Int_result.unitStop listening for incoming datagrams.
val recv_stop_exn : t -> unitWrappers around recv_start and recv_stop for you convenience, no callback soup. ~len should be greater than zero.
See also the comments to Stream.read. Don't pass ~len:0 or an empty buf to recv. This case is captured by uwt/libuv, not your operating system :D