mirror of https://github.com/axmolengine/axmol.git
Improve some platform features implementation
This commit is contained in:
parent
bf68e35b08
commit
072aaf4117
|
@ -104,21 +104,21 @@ SOFTWARE.
|
||||||
# define YASIO__UDP_KROUTE 1
|
# define YASIO__UDP_KROUTE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tests whether current OS is BSD-like system
|
// Tests whether current OS is BSD-like system for process common BSD socket behaviors
|
||||||
#if !defined(_WIN32) && !defined(__linux__)
|
#if !defined(_WIN32) && !defined(__linux__)
|
||||||
# include <sys/param.h>
|
# include <sys/param.h>
|
||||||
# if defined(BSD) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
|
# if defined(BSD) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
|
||||||
# define YASIO__OS_BSD 1
|
# define YASIO__OS_BSD_LIKE 1
|
||||||
# else
|
# else
|
||||||
# define YASIO__OS_BSD 0
|
# define YASIO__OS_BSD_LIKE 0
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define YASIO__OS_BSD 0
|
# define YASIO__OS_BSD_LIKE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test whether sockaddr has member 'sa_len'
|
// Test whether sockaddr has member 'sa_len'
|
||||||
// see also: https://github.com/freebsd/freebsd-src/blob/main/sys/sys/socket.h#L329
|
// see also: https://github.com/freebsd/freebsd-src/blob/main/sys/sys/socket.h#L329
|
||||||
#if YASIO__OS_BSD
|
#if YASIO__OS_BSD_LIKE
|
||||||
# define YASIO__HAS_SA_LEN 1
|
# define YASIO__HAS_SA_LEN 1
|
||||||
#else
|
#else
|
||||||
# define YASIO__HAS_SA_LEN 0
|
# define YASIO__HAS_SA_LEN 0
|
||||||
|
|
|
@ -34,6 +34,9 @@ SOFTWARE.
|
||||||
# include <Windows.h>
|
# include <Windows.h>
|
||||||
#else
|
#else
|
||||||
# include <thread>
|
# include <thread>
|
||||||
|
# if defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||||
|
# include <pthread_np.h> // For pthread_getthreadid_np() / pthread_set_name_np()
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
@ -62,12 +65,18 @@ static void yasio__set_thread_name(const char* threadName)
|
||||||
{}
|
{}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
#elif defined(__linux__)
|
||||||
|
# if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
|
||||||
|
# define yasio__set_thread_name(name) pthread_setname_np(pthread_self(), name)
|
||||||
|
# else
|
||||||
|
# define yasio__set_thread_name(name)
|
||||||
|
# endif
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
# define yasio__set_thread_name(name) pthread_setname_np(name)
|
# define yasio__set_thread_name(name) pthread_setname_np(name)
|
||||||
#elif defined(__linux__) && (defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12))))
|
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||||
// These functions first appeared in glibc in version 2.12.
|
# define yasio__set_thread_name(name) pthread_set_name_np(pthread_self(), name)
|
||||||
// see: http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html
|
#elif defined(__NetBSD__)
|
||||||
# define yasio__set_thread_name(name) pthread_setname_np(pthread_self(), name)
|
# define yasio__set_thread_name(name) pthread_setname_np(pthread_self(), "%s", (void*)name);
|
||||||
#else
|
#else
|
||||||
# define yasio__set_thread_name(name)
|
# define yasio__set_thread_name(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -325,7 +325,7 @@ void xxsocket::traverse_local_address(std::function<bool(const ip::endpoint&)> h
|
||||||
{
|
{
|
||||||
errmsg = xxsocket::gai_strerror(iret);
|
errmsg = xxsocket::gai_strerror(iret);
|
||||||
}
|
}
|
||||||
#else // __APPLE__ or linux with <ifaddrs.h>
|
#else // unix like systems with <ifaddrs.h>
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
/*
|
/*
|
||||||
The value of ifa->ifa_name:
|
The value of ifa->ifa_name:
|
||||||
|
@ -608,7 +608,7 @@ int xxsocket::disconnect(socket_native_type s)
|
||||||
return 0;
|
return 0;
|
||||||
if ((error = xxsocket::get_last_errno()) == EINTR)
|
if ((error = xxsocket::get_last_errno()) == EINTR)
|
||||||
continue;
|
continue;
|
||||||
# if YASIO__OS_BSD
|
# if YASIO__OS_BSD_LIKE
|
||||||
/*
|
/*
|
||||||
* From kernel source code of FreeBSD,NetBSD,OpenBSD,etc.
|
* From kernel source code of FreeBSD,NetBSD,OpenBSD,etc.
|
||||||
* The udp socket will be success disconnected by kernel function: `sodisconnect(upic_socket.c)`, then in the kernel, will continue try to
|
* The udp socket will be success disconnected by kernel function: `sodisconnect(upic_socket.c)`, then in the kernel, will continue try to
|
||||||
|
@ -894,14 +894,12 @@ unsigned int xxsocket::tcp_rtt(socket_native_type s)
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
return info.RttUs;
|
return info.RttUs;
|
||||||
# endif
|
# endif
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
||||||
struct tcp_info info;
|
struct tcp_info info;
|
||||||
int length = sizeof(struct tcp_info);
|
|
||||||
if (0 == xxsocket::get_optval(s, IPPROTO_TCP, TCP_INFO, info))
|
if (0 == xxsocket::get_optval(s, IPPROTO_TCP, TCP_INFO, info))
|
||||||
return info.tcpi_rtt;
|
return info.tcpi_rtt;
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
struct tcp_connection_info info;
|
struct tcp_connection_info info;
|
||||||
int length = sizeof(struct tcp_connection_info);
|
|
||||||
/*
|
/*
|
||||||
info.tcpi_srtt: average RTT in ms
|
info.tcpi_srtt: average RTT in ms
|
||||||
info.tcpi_rttcur: most recent RTT in ms
|
info.tcpi_rttcur: most recent RTT in ms
|
||||||
|
|
|
@ -1003,7 +1003,7 @@ public:
|
||||||
** @params:
|
** @params:
|
||||||
** non
|
** non
|
||||||
**
|
**
|
||||||
** @returns: [0] succeed, otherwise, a value of SOCKET_ERROR is returned.
|
** @returns: > 0 succeed, 0 failed.
|
||||||
*/
|
*/
|
||||||
YASIO__DECL unsigned int tcp_rtt() const;
|
YASIO__DECL unsigned int tcp_rtt() const;
|
||||||
YASIO__DECL static unsigned int tcp_rtt(socket_native_type s);
|
YASIO__DECL static unsigned int tcp_rtt(socket_native_type s);
|
||||||
|
|
|
@ -1776,7 +1776,7 @@ void io_service::handle_connect_succeed(transport_handle_t transport)
|
||||||
register_descriptor(connection->native_handle(), YEM_POLLIN);
|
register_descriptor(connection->native_handle(), YEM_POLLIN);
|
||||||
if (yasio__testbits(ctx->properties_, YCM_TCP))
|
if (yasio__testbits(ctx->properties_, YCM_TCP))
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__) || defined(__linux__)
|
#if defined(SO_NOSIGPIPE)
|
||||||
connection->set_optval(SOL_SOCKET, SO_NOSIGPIPE, (int)1);
|
connection->set_optval(SOL_SOCKET, SO_NOSIGPIPE, (int)1);
|
||||||
#endif
|
#endif
|
||||||
// apply tcp keepalive options
|
// apply tcp keepalive options
|
||||||
|
|
Loading…
Reference in New Issue