mirror of https://github.com/axmolengine/axmol.git
Update yasio
This commit is contained in:
parent
d8ed219bc4
commit
d628a07919
|
@ -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
|
||||
|
|
|
@ -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<int>(::sendto(this->fd, (const char*)buf, len, flags, &to.sa_, to.len()));
|
||||
return static_cast<int>(::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<int>(::recvfrom(this->fd, (char*)buf, len, flags, &from.sa_, &addrlen));
|
||||
int n = static_cast<int>(::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;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ SOFTWARE.
|
|||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#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_;
|
||||
|
|
|
@ -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<xxsocket>& 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<char>(buf, buf + len), nullptr);
|
||||
});
|
||||
|
|
|
@ -31,7 +31,6 @@ SOFTWARE.
|
|||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
|
Loading…
Reference in New Issue