Fix udp disconnect ipv6 for windows

This commit is contained in:
halx99 2021-11-04 23:10:12 +08:00
parent 7a7aa81ae2
commit 9b607c899d
3 changed files with 10 additions and 11 deletions

View File

@ -286,8 +286,6 @@ int xxsocket::getipsv(void)
void xxsocket::traverse_local_address(std::function<bool(const ip::endpoint&)> handler)
{
int family = AF_UNSPEC;
bool done = false;
/* Only windows support use getaddrinfo to get local ip address(not loopback or linklocal),
Because nullptr same as "localhost": always return loopback address and at unix/linux the
gethostname always return "localhost"
@ -596,11 +594,12 @@ int xxsocket::connect_n(socket_native_type s, const endpoint& ep)
int xxsocket::disconnect() const { return xxsocket::disconnect(this->fd); }
int xxsocket::disconnect(socket_native_type s)
{
#if defined(_WIN32)
sockaddr_storage addr_unspec{0};
return ::connect(s, (sockaddr*)&addr_unspec, sizeof(addr_unspec));
#else
sockaddr addr_unspec{0};
addr_unspec.sa_family = AF_UNSPEC;
#if defined(_WIN32)
return ::connect(s, &addr_unspec, sizeof(addr_unspec));
#else
int ret, error;
for (;;)
{
@ -615,7 +614,7 @@ int xxsocket::disconnect(socket_native_type s)
* The udp socket will be success disconnected by kernel function: `sodisconnect(upic_socket.c)`, then in the kernel, will continue try to
* connect with new sockaddr, but will failed with follow errno:
* a. EINVAL: addrlen mismatch
* b. ENOSUPPORT: family mismatch
* b. EAFNOSUPPORT: family mismatch
* So, we just simply ignore them for the disconnect behavior.
*/
return (error == EAFNOSUPPORT || error == EINVAL) ? 0 : -1;

View File

@ -266,7 +266,7 @@ public:
if (rbracket && rbracket[1] == ':')
{
auto zone_value = parse_in6_zone(ip, addr_part, sizeof(addr_part), rbracket);
as_in6(ip, atoi(rbracket + 2), zone_value);
as_in6(ip, static_cast<u_short>(atoi(rbracket + 2)), zone_value);
}
}
else
@ -277,7 +277,7 @@ public:
auto n = colon - str_ep;
memcpy(addr_part, str_ep, n);
addr_part[n] = '\0';
as_in4(addr_part, atoi(colon + 1));
as_in4(addr_part, static_cast<u_short>(atoi(colon + 1)));
}
}
return *this;
@ -373,7 +373,7 @@ public:
void zeroset() { ::memset(this, 0x0, sizeof(*this)); }
void af(int v) { sa_.sa_family = v; }
void af(int v) { sa_.sa_family = static_cast<u_short>(v); }
int af() const { return sa_.sa_family; }
void ip(const char* addr)

View File

@ -1477,7 +1477,7 @@ void io_service::do_ssl_handshake(io_channel* ctx)
}
#endif
#if defined(YASIO_HAVE_CARES)
void io_service::ares_getaddrinfo_cb(void* arg, int status, int timeouts, ares_addrinfo* answerlist)
void io_service::ares_getaddrinfo_cb(void* arg, int status, int /*timeouts*/, ares_addrinfo* answerlist)
{
auto ctx = (io_channel*)arg;
auto& current_service = ctx->get_service();
@ -1565,7 +1565,6 @@ void io_service::config_ares_name_servers()
int status = ::ares_get_servers_ports(ares_, &name_servers);
if (status == ARES_SUCCESS)
{
int count = 0;
for (auto ns = name_servers; ns != nullptr; ns = ns->next)
if (endpoint{ns->family, &ns->addr, static_cast<u_short>(ns->udp_port)}.format_to(nscsv, endpoint::fmt_default | endpoint::fmt_no_local))
nscsv.push_back(',');
@ -1792,6 +1791,7 @@ void io_service::notify_connect_succeed(transport_handle_t t)
auto ctx = t->ctx_;
auto& s = t->socket_;
this->transports_.push_back(t);
YASIO__UNUSED_PARAM(s);
YASIO_KLOGV("[index: %d] sndbuf=%d, rcvbuf=%d", ctx->index_, s->get_optval<int>(SOL_SOCKET, SO_SNDBUF), s->get_optval<int>(SOL_SOCKET, SO_RCVBUF));
YASIO_KLOGD("[index: %d] the connection #%u(%p) <%s> --> <%s> is established.", ctx->index_, t->id_, t, t->local_endpoint().to_string().c_str(),
t->remote_endpoint().to_string().c_str());