@@ -34,16 +34,36 @@ namespace node {
3434
3535class UDPWrapBase ;
3636
37+ // A listener that can be attached to an `UDPWrapBase` object and generally
38+ // manages its I/O activity. This is similar to `StreamListener`.
3739class UDPListener {
3840 public:
3941 virtual ~UDPListener ();
42+
43+ // Called right before data is received from the socket. Must return a
44+ // buffer suitable for reading data into, that is then passed to OnRecv.
4045 virtual uv_buf_t OnAlloc (size_t suggested_size) = 0;
46+
47+ // Called right after data is received from the socket, and includes
48+ // information about the source address. If `nread` is negative, an error
49+ // has occurred, and it represents a libuv error code.
4150 virtual void OnRecv (ssize_t nread,
4251 const uv_buf_t & buf,
4352 const sockaddr* addr,
4453 unsigned int flags) = 0;
54+
55+ // Called when an asynchronous request for writing data is created.
56+ // The `msg_size` value contains the total size of the data to be sent,
57+ // but may be ignored by the implementation of this Method.
58+ // The return value is later passed to OnSendDone.
4559 virtual ReqWrap<uv_udp_send_t >* CreateSendWrap (size_t msg_size) = 0;
60+
61+ // Called when an asynchronous request for writing data has finished.
62+ // If status is negative, an error has occurred, and it represents a libuv
63+ // error code.
4664 virtual void OnSendDone (ReqWrap<uv_udp_send_t >* wrap, int status) = 0;
65+
66+ // Optional callback that is called after the socket has been bound.
4767 virtual void OnAfterBind () {}
4868
4969 inline UDPWrapBase* udp () const { return wrap_; }
@@ -59,13 +79,26 @@ class UDPWrapBase {
5979 static constexpr int kUDPWrapBaseField = 1 ;
6080
6181 virtual ~UDPWrapBase ();
82+
83+ // Start emitting OnAlloc() + OnRecv() events on the listener.
6284 virtual int RecvStart () = 0;
85+
86+ // Stop emitting OnAlloc() + OnRecv() events on the listener.
6387 virtual int RecvStop () = 0;
88+
89+ // Send a chunk of data over this socket. This may call CreateSendWrap()
90+ // on the listener if an async transmission is necessary.
6491 virtual ssize_t Send (uv_buf_t * bufs,
6592 size_t nbufs,
6693 const sockaddr* addr) = 0;
94+
95+ // Stores the sockaddr for the peer in `name`.
6796 virtual int GetPeerName (sockaddr* name, int * namelen) = 0;
97+
98+ // Stores the sockaddr for the local socket in `name`.
6899 virtual int GetSockName (sockaddr* name, int * namelen) = 0;
100+
101+ // Returns an AsyncWrap object with the same lifetime as this object.
69102 virtual AsyncWrap* GetAsyncWrap () = 0;
70103
71104 void set_listener (UDPListener* listener);
0 commit comments