Module Udp

module Udp: Udp

type write_buffer = (Core.Std.read_write, Core.Std.Iobuf.seek) Core.Std.Iobuf.t 
val default_capacity : int
The default buffer capacity for UDP-oriented buffers is 1472, determined as the typical Ethernet MTU (1500 octets) less the typical UDP header length (28). Using buffers of this size, one avoids accidentally creating messages that will be dropped on send because they exceed the MTU, and can receive the largest corresponding UDP message.

While this number is merely typical and not guaranteed to work in all cases, defining it in one place makes it easy to share and change. For example, another MTU in common use is 9000 for Jumbo frames, so the value of default_capacity might change to 8972 in the future.

module Config: sig .. end
A typical receive loop calls before before calling its callback to prepare a packet buffer for reading and after afterwards to prepare for writing (for the next iteration).
val sendto_sync : unit ->
(Import.Fd.t ->
('a, Core.Std.Iobuf.seek) Core.Std.Iobuf.t ->
Import.Socket.Address.Inet.t -> [ `Not_ready | `Ok ])
Core.Std.Or_error.t
sendto_sync sock buf addr does not try again if sock is not ready to write. Instead, it returns `Not_ready immediately.

Short writes are distinguished by buf not being empty afterward.

sendto sock buf addr retries if sock is not ready to write.
Raises Unix_error in the case of output errors. See also Iobuf.sendto_nonblocking_no_sigpipe and Bigstring.sendto_nonblocking_no_sigpipe.

val sendto : unit ->
(Import.Fd.t ->
('a, Core.Std.Iobuf.seek) Core.Std.Iobuf.t ->
Import.Socket.Address.Inet.t -> unit Import.Deferred.t)
Core.Std.Or_error.t
val bind : ?ifname:string ->
Import.Socket.Address.Inet.t ->
([ `Bound ], Import.Socket.Address.Inet.t) Import.Socket.t Import.Deferred.t
val bind_any : unit ->
([ `Bound ], Import.Socket.Address.Inet.t) Import.Socket.t Import.Deferred.t
val recvfrom_loop : ?config:Config.t ->
Import.Fd.t ->
(write_buffer -> Import.Socket.Address.Inet.t -> unit) ->
unit Import.Deferred.t
recvfrom_loop_with_buffer_replacement callback calls callback synchronously on each message received. callback returns the packet buffer for subsequent iterations, so it can replace the initial packet buffer when necessary. This enables immediate buffer reuse in the common case and fallback to allocation if we want to save the packet buffer for asynchronous processing.
val recvfrom_loop_with_buffer_replacement : ?config:Config.t ->
Import.Fd.t ->
(write_buffer -> Import.Socket.Address.Inet.t -> write_buffer) ->
write_buffer Import.Deferred.t
val read_loop : ?config:Config.t ->
Import.Fd.t -> (write_buffer -> unit) -> unit Import.Deferred.t
val read_loop_with_buffer_replacement : ?config:Config.t ->
Import.Fd.t ->
(write_buffer -> write_buffer) -> write_buffer Import.Deferred.t
val recvmmsg_loop : (?config:Config.t ->
Import.Fd.t ->
?create_srcs:bool ->
?max_count:int ->
?bufs:write_buffer array ->
(?srcs:Core.Std.Unix.sockaddr array ->
write_buffer array -> count:int -> unit) ->
unit Import.Deferred.t)
Core.Std.Or_error.t
recvmmsg_loop ~socket callback iteratively receives up to max_count packets at a time on socket and passes them to callback. Each packet is up to capacity bytes. If create_srcs, collect from-addresses there.

callback ?srcs bufs ~count processes count packets synchronously. callback may replace packet buffers in bufs and take ownership of the corresponding originals. srcs contains the corresponding source addresses of the packets in bufs, if requested, and will similarly be reused when callback returns.

Config.init config is used as a prototype for bufs and as one of the elements.

val bind_to_interface_exn : (ifname:string -> Import.Fd.t -> unit) Core.Std.Or_error.t