uv_udp_t.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ---@meta
  2. -- luacheck: no unused args
  3. error('Cannot require a meta file')
  4. --- UDP handles encapsulate UDP communication for both clients and servers.
  5. ---
  6. ---@class uv.uv_udp_t : uv.uv_handle_t
  7. local udp = {} -- luacheck: no unused
  8. --- Bind the UDP handle to an IP address and port. Any `flags` are set with a table
  9. --- with fields `reuseaddr` or `ipv6only` equal to `true` or `false`.
  10. ---
  11. ---@param host string
  12. ---@param port integer
  13. ---@param flags? uv.udp_bind.flags
  14. ---@return 0|nil success
  15. ---@return uv.error.message|nil err
  16. ---@return uv.error.name|nil err_name
  17. function udp:bind(host, port, flags) end
  18. --- Associate the UDP handle to a remote address and port, so every message sent by
  19. --- this handle is automatically sent to that destination.
  20. --
  21. --- Calling this function with a NULL addr disconnects the handle. Trying to call `udp:connect()` on an already connected handle will result in an `EISCONN` error. Trying to disconnect a handle that is not connected will return an `ENOTCONN` error.
  22. ---
  23. ---@param host string
  24. ---@param port integer
  25. ---@return 0|nil success
  26. ---@return uv.error.message|nil err
  27. ---@return uv.error.name|nil err_name
  28. function udp:connect(host, port) end
  29. --- Returns the handle's send queue count.
  30. ---
  31. ---@return integer count
  32. function udp:get_send_queue_count() end
  33. --- Returns the handle's send queue size.
  34. ---
  35. ---@return integer size
  36. function udp:get_send_queue_size() end
  37. --- Get the remote IP and port of the UDP handle on connected UDP handles.
  38. ---
  39. ---@return uv.udp.sockname|nil peername
  40. ---@return uv.error.message|nil err
  41. ---@return uv.error.name|nil err_name
  42. function udp:getpeername() end
  43. --- Get the local IP and port of the UDP handle.
  44. ---
  45. ---@return uv.udp.sockname|nil sockname
  46. ---@return uv.error.message|nil err
  47. ---@return uv.error.name|nil err_name
  48. function udp:getsockname() end
  49. --- Opens an existing file descriptor or Windows SOCKET as a UDP handle.
  50. ---
  51. --- Unix only: The only requirement of the sock argument is that it follows the
  52. --- datagram contract (works in unconnected mode, supports sendmsg()/recvmsg(),
  53. --- etc). In other words, other datagram-type sockets like raw sockets or netlink
  54. --- sockets can also be passed to this function.
  55. ---
  56. --- The file descriptor is set to non-blocking mode.
  57. ---
  58. --- Note: The passed file descriptor or SOCKET is not checked for its type, but
  59. --- it's required that it represents a valid datagram socket.
  60. ---
  61. ---@param fd integer
  62. ---@return 0|nil success
  63. ---@return uv.error.message|nil err
  64. ---@return uv.error.name|nil err_name
  65. function udp:open(fd) end
  66. --- Prepare for receiving data.
  67. ---
  68. --- If the socket has not previously been bound with `udp:bind()` it is bound to `0.0.0.0` (the "all interfaces" IPv4 address) and a random port number.
  69. ---
  70. ---@param callback uv.udp_recv_start.callback
  71. ---@return 0|nil success
  72. ---@return uv.error.message|nil err
  73. ---@return uv.error.name|nil err_name
  74. function udp:recv_start(callback) end
  75. --- Stop listening for incoming datagrams.
  76. ---
  77. ---@return 0|nil success
  78. ---@return uv.error.message|nil err
  79. ---@return uv.error.name|nil err_name
  80. function udp:recv_stop() end
  81. --- Send data over the UDP socket.
  82. ---
  83. --- If the socket has not previously been bound with `udp:bind()` it will be bound to `0.0.0.0` (the "all interfaces" IPv4 address) and a random port number.
  84. ---
  85. ---@param data uv.buffer
  86. ---@param host string
  87. ---@param port integer
  88. ---@param callback uv.udp_send.callback
  89. ---@return uv.uv_udp_send_t|nil bytes
  90. ---@return uv.error.message|nil err
  91. ---@return uv.error.name|nil err_name
  92. function udp:send(data, host, port, callback) end
  93. --- Set broadcast on or off.
  94. ---
  95. ---@param on boolean
  96. ---@return 0|nil success
  97. ---@return uv.error.message|nil err
  98. ---@return uv.error.name|nil err_name
  99. function udp:set_broadcast(on) end
  100. --- Set membership for a multicast address.
  101. ---
  102. ---@param multicast_addr string # multicast address to set membership for
  103. ---@param interface_addr string # interface address
  104. ---@param membership "leave"|"join" # membership intent
  105. ---@return 0|nil success
  106. ---@return uv.error.message|nil err
  107. ---@return uv.error.name|nil err_name
  108. function udp:set_membership(multicast_addr, interface_addr, membership) end
  109. --- Set the multicast interface to send or receive data on.
  110. ---
  111. ---@param interface_addr string
  112. ---@return 0|nil success
  113. ---@return uv.error.message|nil err
  114. ---@return uv.error.name|nil err_name
  115. function udp:set_multicast_interface(interface_addr) end
  116. --- Set IP multicast loop flag. Makes multicast packets loop back to local
  117. --- sockets.
  118. ---
  119. ---@param on boolean
  120. ---@return 0|nil success
  121. ---@return uv.error.message|nil err
  122. ---@return uv.error.name|nil err_name
  123. function udp:set_multicast_loop(on) end
  124. --- Set the multicast ttl.
  125. ---
  126. ---@param ttl integer # an integer 1 through 255
  127. ---@return 0|nil success
  128. ---@return uv.error.message|nil err
  129. ---@return uv.error.name|nil err_name
  130. function udp:set_multicast_ttl(ttl) end
  131. --- Set membership for a source-specific multicast group.
  132. ---
  133. ---@param multicast_addr string # multicast address to set membership for
  134. ---@param interface_addr? string # interface address
  135. ---@param source_addr string # source address
  136. ---@param membership "leave"|"join" # membership intent
  137. ---@return 0|nil success
  138. ---@return uv.error.message|nil err
  139. ---@return uv.error.name|nil err_name
  140. function udp:set_source_membership(multicast_addr, interface_addr, source_addr, membership) end
  141. --- Set the time to live.
  142. ---
  143. ---@param ttl integer # integer 1 through 255
  144. ---@return 0|nil success
  145. ---@return uv.error.message|nil err
  146. ---@return uv.error.name|nil err_name
  147. function udp:set_ttl(ttl) end
  148. --- Same as `udp:send()`, but won't queue a send request if it can't be
  149. --- completed immediately.
  150. ---
  151. ---@param data uv.buffer
  152. ---@param host string
  153. ---@param port integer
  154. ---@return integer|nil success
  155. ---@return uv.error.message|nil err
  156. ---@return uv.error.name|nil err_name
  157. function udp:try_send(data, host, port) end