Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

doc: add documentation to to uv_udp_start_recv #1350

Merged
merged 1 commit into from
Jul 2, 2014
Merged

doc: add documentation to to uv_udp_start_recv #1350

merged 1 commit into from
Jul 2, 2014

Conversation

txdv
Copy link
Contributor

@txdv txdv commented Jul 2, 2014

This clarifies the behaviour of uv_udp_recv_start.

@saghul
Copy link
Contributor

saghul commented Jul 2, 2014

Thanks! This is not entirely correct, here is when nread==0 and addr==NULL can happen: https://github.com/joyent/libuv/blob/master/src/unix/udp.c#L219 As you can see, it's not related to closing the handle. In UDP, since we read datagrams, when the fd is readable we read until we get EAGAIN, but because alloc_cb was called to allocate the buffer for a datagram, we need to return it back, so the recv callback is called with nread==0 and addr==NULL.

@txdv
Copy link
Contributor Author

txdv commented Jul 2, 2014

Why does it call alloc_cb if there is nothing to read?

@saghul
Copy link
Contributor

saghul commented Jul 2, 2014

Because we don't know what there is nothing to read. Once the socket is readable we read until we get EAGAIN, but each time re call recvmsg we need to allocate a buffer first. So, when we get EAGAIN we already called alloc_cb and thus we need to give it back to the user in order for him to free the memory.

@txdv
Copy link
Contributor Author

txdv commented Jul 2, 2014

Makes sense.

@saghul
Copy link
Contributor

saghul commented Jul 2, 2014

LGTM now. Can you update the patch title? (to to).

@saghul saghul merged commit d17bfc6 into joyent:master Jul 2, 2014
@saghul
Copy link
Contributor

saghul commented Jul 2, 2014

Thanks a lot Andrius! Landed! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants