skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.84k stars 209 forks source link

UDP send after connect not possible #262

Open tlbtlbtlb opened 2 years ago

tlbtlbtlb commented 2 years ago

Once a UDP socket is connected in libuv, you have to call send with a null address or else you get UV_EISCONN and nothing is sent. There seems to be no way to do this through the uvw API, since the addr parameter is passed by reference. In udp.cc the wrappers are like:

UVW_INLINE void UDPHandle::send(const sockaddr &addr, std::unique_ptr<char[]> data, unsigned int len) {
...
    req->send(get(), &addr);
}

Empirically it works to call it like

   sock->send(*(sockaddr *)nullptr, txbuf, txbuf_size);

But this is undefined behavior in C++, and the compiler (at least Clang++-10) warns accordingly.

I think the right answer is to have versions of UDPHandle::send that don't take an address parameter.

References: http://docs.libuv.org/en/v1.x/udp.html in the uv_udp_send section

skypjack commented 2 years ago

Sounds reasonable. We're working on a v3 branch that flips the project on its head. We'll add this function there probably. 👍