Module Uwt.Udp

module Udp: sig .. end

UDP handles encapsulate UDP communication for both clients and servers.

type t 
include Uwt.Handle
include Uwt.Handle_ext
include Uwt.Handle_fileno
val to_handle : t -> Uwt.Handle.t
val send_queue_size : t -> int

Number of bytes queued for sending; strictly shows how much information is currently queued.

val send_queue_count : t -> int

Number of send requests currently in the queue awaiting to be processed.

val init : unit -> t

See comment to Uwt.Pipe.init

val init_ipv4 : unit -> t uv_result

wrappers around uv_udp_init_ex. A socket of the given type will be created immediately instead of lazy (Uwt.Udp.init)

val init_ipv4_exn : unit -> t
val init_ipv6 : unit -> t uv_result
val init_ipv6_exn : unit -> t
val openudp : Unix.file_descr -> t uv_result

See comment to Uwt.Pipe.openpipe

val openudp_exn : Unix.file_descr -> t
type mode = 
| Ipv6_only
| Reuse_addr
val bind : ?mode:mode list ->
t -> addr:sockaddr -> unit -> Int_result.unit

Bind the UDP handle to an IP address and port.

mode : default mode is the empty list
val bind_exn : ?mode:mode list -> t -> addr:sockaddr -> unit -> unit
val getsockname : t -> sockaddr uv_result

Get the local IP and port of the UDP handle.

val getsockname_exn : t -> sockaddr
type membership = 
| Leave_group
| Join_group
val set_membership : ?interface:string ->
t -> multicast:string -> membership -> Int_result.unit

Set membership for a multicast address

val set_membership_exn : ?interface:string ->
t -> multicast:string -> membership -> unit
val set_multicast_loop : t -> bool -> Int_result.unit

Set IP multicast loop flag. Makes multicast packets loop back to local sockets

val set_multicast_loop_exn : t -> bool -> unit
val set_multicast_ttl : t -> int -> Int_result.unit

Set the multicast ttl, ttl - 1 through 255.

val set_multicast_ttl_exn : t -> int -> unit
val set_multicast_interface : t -> string option -> Int_result.unit

Set the multicast interface to send or receive data on

val set_multicast_interface_exn : t -> string option -> unit
val set_broadcast : t -> bool -> Int_result.unit

Set broadcast on or off.

val set_broadcast_exn : t -> bool -> unit
val set_ttl : t -> int -> Int_result.unit

Set the time to live. ttl - 1 through 255.

val set_ttl_exn : t -> int -> unit
val send : ?pos:int -> ?len:int -> buf:bytes -> t -> sockaddr -> unit Lwt.t

Send 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.

val send_ba : ?pos:int -> ?len:int -> buf:buf -> t -> sockaddr -> unit Lwt.t
val send_string : ?pos:int -> ?len:int -> buf:string -> t -> sockaddr -> unit Lwt.t
val send_raw : ?pos:int -> ?len:int -> buf:bytes -> t -> sockaddr -> unit Lwt.t

See comment to Uwt.Stream.write_raw

val send_raw_ba : ?pos:int -> ?len:int -> buf:buf -> t -> sockaddr -> unit Lwt.t
val send_raw_string : ?pos:int -> ?len:int -> buf:string -> t -> sockaddr -> unit Lwt.t
val try_send : ?pos:int -> ?len:int -> buf:bytes -> t -> sockaddr -> Int_result.int

Same as Uwt.Udp.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.int
val try_send_string : ?pos:int -> ?len:int -> buf:string -> t -> sockaddr -> Int_result.int
val try_sendv : t -> Iovec_write.t list -> sockaddr -> Int_result.int
val sendv_raw : t -> Iovec_write.t list -> sockaddr -> unit Lwt.t
val sendv : t -> Iovec_write.t list -> sockaddr -> unit Lwt.t
type recv_result = 
| Data of Bytes.t * sockaddr option
| Partial_data of Bytes.t * sockaddr option
| Empty_from of sockaddr
| Transmission_error of error (*

The type definition will likely be changed. Don't use fragile pattern matching for it

*)
val recv_start : t -> cb:(recv_result -> unit) -> Int_result.unit

Prepare 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) -> unit
val recv_stop : t -> Int_result.unit

Stop listening for incoming datagrams.

val recv_stop_exn : t -> unit
type recv = {
   recv_len : int;
   is_partial : bool;
   sockaddr : sockaddr option;
}
val recv : ?pos:int -> ?len:int -> buf:bytes -> t -> recv Lwt.t

Wrappers around Uwt.Udp.recv_start and Uwt.Udp.recv_stop for you convenience, no callback soup. ~len should be greater than zero.

See also the comments to Uwt.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

val recv_ba : ?pos:int -> ?len:int -> buf:buf -> t -> recv Lwt.t