Udp.hx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package eval.luv;
  2. import haxe.ds.Option;
  3. import eval.luv.SockAddr;
  4. enum abstract UdpMembership(Int) {
  5. var LEAVE_GROUP = 0;
  6. var JOIN_GROUP = 1;
  7. }
  8. enum abstract RecvFlag(Int) {
  9. var PARTIAL = 0;
  10. var MMSG_CHUNK = 1;
  11. var MMSG_FREE = 2;
  12. }
  13. /**
  14. UDP sockets.
  15. @see https://aantron.github.io/luv/luv/Luv/UDP
  16. **/
  17. @:using(eval.luv.Handle)
  18. @:coreType abstract Udp to Handle to Handle.SocketHandle {
  19. /**
  20. Allocates and initializes a UDP socket.
  21. The handle should be cleaned up with `eval.luv.Handle.close` when no longer needed.
  22. **/
  23. static public function init(loop:Loop, ?domain:AddressFamily, recvmmsg:Bool = false):Result<Udp>;
  24. /**
  25. Assigns an address to the UDP socket.
  26. **/
  27. public function bind(addr:SockAddr, ipv6Only:Bool = false, reuseAddr:Bool = false):Result<Result.NoData>;
  28. /**
  29. Assigns a peer address to the socket.
  30. **/
  31. public function connect(addr:SockAddr):Result<ConnectedUdp>;
  32. /**
  33. Retrieves the address assigned to the UDP socket.
  34. **/
  35. public function getSockName():Result<SockAddr>;
  36. /**
  37. Sets multicast group membership.
  38. **/
  39. public function setMembership(group:String, interfaceName:String, membership:UdpMembership):Result<Result.NoData>;
  40. /**
  41. Sets source-specific multicast group membership.
  42. **/
  43. public function setSourceMembership(group:String, interfaceName:String, source:String, membership:UdpMembership):Result<Result.NoData>;
  44. /**
  45. Set multicast loopback.
  46. **/
  47. public function setMulticastLoop(value:Bool):Result<Result.NoData>;
  48. /**
  49. Set multicast TTL.
  50. **/
  51. public function setMulticastTtl(value:Int):Result<Result.NoData>;
  52. /**
  53. Sets the interface to be used for multicast.
  54. **/
  55. public function setMulticastInterface(value:Int):Result<Result.NoData>;
  56. /**
  57. Sets broadcast.
  58. **/
  59. public function setBroadcast(value:Bool):Result<Result.NoData>;
  60. /**
  61. Sets the TTL.
  62. **/
  63. public function setTtl(value:Int):Result<Result.NoData>;
  64. /**
  65. Sends a datagram.
  66. For connected UDP sockets, see `eval.luv.UDP.Connected.send`.
  67. **/
  68. public function send(data:Array<Buffer>, addr:SockAddr, callback:(result:Result<Result.NoData>)->Void):Void;
  69. /**
  70. Like `eval.luv.UDP.send`, but only attempts to send the datagram immediately.
  71. **/
  72. public function trySend(data:Array<Buffer>, addr:SockAddr):Result<Result.NoData>;
  73. /**
  74. Calls `callback` whenever a datagram is received on the UDP socket.
  75. @see https://aantron.github.io/luv/luv/Luv/UDP/index.html#val-recv_start
  76. **/
  77. public function recvStart(callback:(result:Result<{data:Buffer, addr:Option<SockAddr>, flags:Array<RecvFlag>}>, ?allocate:(size:Int)->Buffer)->Void):Void;
  78. /**
  79. Stops the callback provided to `eval.luv.UDP.recvStart`.
  80. **/
  81. public function recvStop():Result<Result.NoData>;
  82. /**
  83. Evaluates to true if and only if the UDP was created with `recvmmsg = true`
  84. and the platform supports recvmmsg(2).
  85. **/
  86. public function usingRecvmmsg():Bool;
  87. /**
  88. Number of bytes queued for sending. This field strictly shows how much
  89. information is currently queued.
  90. **/
  91. public function getSendQueueSize():Int;
  92. /**
  93. Number of send requests currently in the queue awaiting to be processed.
  94. **/
  95. public function getSendQueueCount():Int;
  96. }