diff --git a/thirdparty/yasio/compiler/feature_test.hpp b/thirdparty/yasio/compiler/feature_test.hpp index 0d0ece2bc2..d1c00b9e63 100644 --- a/thirdparty/yasio/compiler/feature_test.hpp +++ b/thirdparty/yasio/compiler/feature_test.hpp @@ -98,6 +98,7 @@ SOFTWARE. #endif // Test whether sockaddr has member 'sa_len' +// see also: https://github.com/freebsd/freebsd-src/blob/main/sys/sys/socket.h#L329 #if defined(__linux__) || defined(_WIN32) # define YASIO__HAS_SA_LEN 0 #else diff --git a/thirdparty/yasio/xxsocket.cpp b/thirdparty/yasio/xxsocket.cpp index b63030c6b7..e57a5454fc 100644 --- a/thirdparty/yasio/xxsocket.cpp +++ b/thirdparty/yasio/xxsocket.cpp @@ -521,7 +521,7 @@ int xxsocket::test_nonblocking(socket_native_type s) } int xxsocket::bind(const char* addr, unsigned short port) const { return this->bind(endpoint(addr, port)); } -int xxsocket::bind(const endpoint& ep) const { return ::bind(this->fd, &ep.sa_, ep.len()); } +int xxsocket::bind(const endpoint& ep) const { return ::bind(this->fd, &ep, ep.len()); } int xxsocket::bind_any(bool ipv6) const { return this->bind(endpoint(!ipv6 ? "0.0.0.0" : "::", 0)); } int xxsocket::listen(int backlog) const { return ::listen(this->fd, backlog); } @@ -562,7 +562,7 @@ int xxsocket::connect(socket_native_type s, const char* addr, u_short port) return xxsocket::connect(s, peer); } -int xxsocket::connect(socket_native_type s, const endpoint& ep) { return ::connect(s, &ep.sa_, ep.len()); } +int xxsocket::connect(socket_native_type s, const endpoint& ep) { return ::connect(s, &ep, ep.len()); } int xxsocket::connect_n(const char* addr, u_short port, const std::chrono::microseconds& wtimeout) { return connect_n(ip::endpoint(addr, port), wtimeout); } int xxsocket::connect_n(const endpoint& ep, const std::chrono::microseconds& wtimeout) { return this->connect_n(this->fd, ep, wtimeout); } @@ -730,13 +730,13 @@ int xxsocket::recv(socket_native_type s, void* buf, int len, int flags) { return int xxsocket::sendto(const void* buf, int len, const endpoint& to, int flags) const { - return static_cast(::sendto(this->fd, (const char*)buf, len, flags, &to.sa_, to.len())); + return static_cast(::sendto(this->fd, (const char*)buf, len, flags, &to, to.len())); } int xxsocket::recvfrom(void* buf, int len, endpoint& from, int flags) const { socklen_t addrlen{sizeof(from)}; - int n = static_cast(::recvfrom(this->fd, (char*)buf, len, flags, &from.sa_, &addrlen)); + int n = static_cast(::recvfrom(this->fd, (char*)buf, len, flags, &from, &addrlen)); from.len(addrlen); return n; } @@ -800,7 +800,7 @@ endpoint xxsocket::local_endpoint(socket_native_type fd) { endpoint ep; socklen_t socklen = sizeof(ep); - getsockname(fd, &ep.sa_, &socklen); + getsockname(fd, &ep, &socklen); ep.len(socklen); return ep; } @@ -810,7 +810,7 @@ endpoint xxsocket::peer_endpoint(socket_native_type fd) { endpoint ep; socklen_t socklen = sizeof(ep); - getpeername(fd, &ep.sa_, &socklen); + getpeername(fd, &ep, &socklen); ep.len(socklen); return ep; } diff --git a/thirdparty/yasio/xxsocket.hpp b/thirdparty/yasio/xxsocket.hpp index ce61f3e159..208ca34801 100644 --- a/thirdparty/yasio/xxsocket.hpp +++ b/thirdparty/yasio/xxsocket.hpp @@ -38,6 +38,7 @@ SOFTWARE. #include #include #include +#include #include "yasio/detail/socket.hpp" #include "yasio/detail/logging.hpp" @@ -301,10 +302,8 @@ public: { this->zeroset(); - this->af(AF_INET); this->addr_v4(addr); this->port(port); - this->len(sizeof(sockaddr_in)); return *this; } @@ -368,8 +367,13 @@ public: unsigned short port() const { return ntohs(in4_.sin_port); } void port(unsigned short value) { in4_.sin_port = htons(value); } - void addr_v4(uint32_t addr) { in4_.sin_addr.s_addr = htonl(addr); } - uint32_t addr_v4() const { return ntohl(in4_.sin_addr.s_addr); } + void addr_v4(uint32_t addr) + { + this->af(AF_INET); + in4_.sin_addr.s_addr = htonl(addr); + this->len(sizeof(sockaddr_in)); + } + uint32_t addr_v4() const { return af() == AF_INET ? ntohl(in4_.sin_addr.s_addr) : 0u; } // check does endpoint is global address, not linklocal or loopback bool is_global() const @@ -499,6 +503,9 @@ public: return s; } + sockaddr* operator&() { return &sa_; } + const sockaddr* operator&() const { return &sa_; } + union { sockaddr sa_; sockaddr_in in4_; diff --git a/thirdparty/yasio/yasio.cpp b/thirdparty/yasio/yasio.cpp index 2e60212c98..6477c34e1c 100644 --- a/thirdparty/yasio/yasio.cpp +++ b/thirdparty/yasio/yasio.cpp @@ -211,7 +211,7 @@ void highp_timer::cancel(io_service& service) int io_send_op::perform(io_transport* transport, const void* buf, int n) { return transport->write_cb_(buf, n, nullptr); } /// io_sendto_op -int io_sendto_op::perform(io_transport* transport, const void* buf, int n) { return transport->write_cb_(buf, n, &destination_); } +int io_sendto_op::perform(io_transport* transport, const void* buf, int n) { return transport->write_cb_(buf, n, std::addressof(destination_)); } #if defined(YASIO_SSL_BACKEND) void ssl_auto_handle::destroy() @@ -680,7 +680,7 @@ io_transport_kcp::io_transport_kcp(io_channel* ctx, std::shared_ptr& s ::ikcp_setoutput(this->kcp_, [](const char* buf, int len, ::ikcpcb* /*kcp*/, void* user) { auto t = (io_transport_kcp*)user; if (yasio__min_wait_duration == 0) - return t->write_cb_(buf, len, &t->ensure_destination()); + return t->write_cb_(buf, len, std::addressof(t->ensure_destination())); // Enqueue to transport queue return t->io_transport_udp::write(std::vector(buf, buf + len), nullptr); }); diff --git a/thirdparty/yasio/yasio.hpp b/thirdparty/yasio/yasio.hpp index 8ec83fca65..3404eb24d0 100644 --- a/thirdparty/yasio/yasio.hpp +++ b/thirdparty/yasio/yasio.hpp @@ -31,7 +31,6 @@ SOFTWARE. #include #include #include -#include #include #include #include