Open L-Sun opened 3 years ago
Had the exact same issue.
My current workaround is to manually create an endpoint with a fixed port:
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
// ...
auto endpoint = cppcoro::net::ipv4_endpoint::from_string("127.0.0.1:7001");
endpoint = cppcoro::net::ipv4_endpoint{endpoint.address(), htons(endpoint.port())};
The actual bound port is accessible from socket.local_endpoint()
after the call to socket.bind(..)
.
https://github.com/lewissbaker/cppcoro/blob/a87e97fe5b6091ca9f6de4637736b8e0d8b109cf/lib/socket.cpp#L291
is the correct code following?