mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-12-25 09:39:52 +03:00
Several Tunings for OS X
This commit is contained in:
parent
14e8693421
commit
4c48388b12
@ -105,6 +105,9 @@
|
||||
#include <errno.h>
|
||||
#include <Mayaqua/Mayaqua.h>
|
||||
#include <Cedar/Cedar.h>
|
||||
#ifdef UNIX_MACOS
|
||||
#include <net/ethernet.h>
|
||||
#endif
|
||||
|
||||
#ifdef OS_UNIX
|
||||
|
||||
@ -524,10 +527,11 @@ int UnixCreateTapDeviceEx(char *name, char *prefix, UCHAR *mac_address)
|
||||
|
||||
if (mac_address != NULL)
|
||||
{
|
||||
uint8_t macos_mac_address[19];
|
||||
Zero(&ifr, sizeof(ifr));
|
||||
StrCpy(ifr.ifr_name, sizeof(ifr.ifr_name), macos_eth_name);
|
||||
Copy(&ifr.ifr_addr.sa_data, mac_address, 6);
|
||||
ifr.ifr_addr.sa_len = ETHER_ADDR_LEN;
|
||||
ifr.ifr_addr.sa_family = AF_LINK;
|
||||
Copy(&ifr.ifr_addr.sa_data, mac_address, ETHER_ADDR_LEN);
|
||||
ioctl(s, SIOCSIFLLADDR, &ifr);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ UINT g_zero = 0;
|
||||
// Get the real-time system timer
|
||||
UINT TickRealtime()
|
||||
{
|
||||
#if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES)
|
||||
#if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES) || defined(UNIX_MACOS)
|
||||
return Tick() + 1;
|
||||
#else
|
||||
return TickRealtimeManual() + 1;
|
||||
|
@ -129,6 +129,9 @@
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <Mayaqua/Mayaqua.h>
|
||||
#ifdef UNIX_MACOS
|
||||
#include <sys/event.h>
|
||||
#endif // UNIX_MACOS
|
||||
|
||||
#ifdef OS_WIN32
|
||||
NETWORK_WIN32_FUNCTIONS *w32net;
|
||||
@ -141,7 +144,7 @@ struct ROUTE_CHANGE_DATA
|
||||
#endif // OS_WIN32
|
||||
|
||||
// Whether the blocking occurs in SSL
|
||||
#if defined(UNIX_BSD)
|
||||
#if defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||
#define FIX_SSL_BLOCKING
|
||||
#endif
|
||||
|
||||
@ -8791,7 +8794,12 @@ void UnixSetSockEvent(SOCK_EVENT *event)
|
||||
// Execute 'select' for the socket
|
||||
void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout)
|
||||
{
|
||||
#ifdef UNIX_MACOS
|
||||
int kq;
|
||||
struct kevent *kevents;
|
||||
#else // UNIX_MACOS
|
||||
struct pollfd *p;
|
||||
#endif // UNIX_MACOS
|
||||
UINT num;
|
||||
UINT i;
|
||||
UINT n;
|
||||
@ -8828,7 +8836,12 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
||||
}
|
||||
|
||||
num = num_read_total + num_write_total;
|
||||
#ifdef UNIX_MACOS
|
||||
kq = kqueue();
|
||||
kevents = ZeroMallocFast(sizeof(struct kevent) * (num + num_write_total));
|
||||
#else // UNIX_MACOS
|
||||
p = ZeroMallocFast(sizeof(struct pollfd) * num);
|
||||
#endif // UNIX_MACOS
|
||||
|
||||
n = 0;
|
||||
|
||||
@ -8836,9 +8849,13 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
||||
{
|
||||
if (reads[i] != INVALID_SOCKET)
|
||||
{
|
||||
#ifdef UNIX_MACOS
|
||||
EV_SET(&kevents[n++], reads[i], EVFILT_READ, EV_ADD, 0, 0, NULL);
|
||||
#else // UNIX_MACOS
|
||||
struct pollfd *pfd = &p[n++];
|
||||
pfd->fd = reads[i];
|
||||
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP;
|
||||
#endif // UNIX_MACOS
|
||||
}
|
||||
}
|
||||
|
||||
@ -8846,22 +8863,44 @@ void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, U
|
||||
{
|
||||
if (writes[i] != INVALID_SOCKET)
|
||||
{
|
||||
#ifdef UNIX_MACOS
|
||||
EV_SET(&kevents[n++], reads[i], EVFILT_READ, EV_ADD, 0, 0, NULL);
|
||||
EV_SET(&kevents[n++], reads[i], EVFILT_WRITE, EV_ADD, 0, 0, NULL);
|
||||
#else // UNIX_MACOS
|
||||
struct pollfd *pfd = &p[n++];
|
||||
pfd->fd = writes[i];
|
||||
pfd->events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLOUT;
|
||||
#endif // UNIX_MACOS
|
||||
}
|
||||
}
|
||||
|
||||
if (num != 0)
|
||||
{
|
||||
#ifdef UNIX_MACOS
|
||||
struct timespec kevent_timeout, *p_kevent_timeout;
|
||||
if (timeout == INFINITE) {
|
||||
p_kevent_timeout = NULL;
|
||||
} else {
|
||||
kevent_timeout.tv_sec = timeout / 1000;
|
||||
kevent_timeout.tv_nsec = (timeout % 1000) * 1000000l;
|
||||
p_kevent_timeout = &kevent_timeout;
|
||||
}
|
||||
kevent(kq, kevents, n, kevents, n, p_kevent_timeout);
|
||||
#else // UNIX_MACOS
|
||||
poll(p, num, timeout == INFINITE ? -1 : (int)timeout);
|
||||
#endif // UNIX_MACOS
|
||||
}
|
||||
else
|
||||
{
|
||||
SleepThread(timeout);
|
||||
}
|
||||
|
||||
#ifdef UNIX_MACOS
|
||||
Free(kevents);
|
||||
close(kq);
|
||||
#else // UNIX_MACOS
|
||||
Free(p);
|
||||
#endif // UNIX_MACOS
|
||||
}
|
||||
|
||||
// Clean-up of the socket event
|
||||
@ -13198,9 +13237,9 @@ SOCK *Accept(SOCK *sock)
|
||||
size = sizeof(addr);
|
||||
|
||||
#ifdef OS_UNIX
|
||||
#ifdef UNIX_LINUX
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
UnixIgnoreSignalForThread(SIGUSR1);
|
||||
#endif // UNIX_LINUX
|
||||
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
sock->CallingThread = pthread_self();
|
||||
#endif // OS_UNIX
|
||||
|
||||
@ -13309,9 +13348,9 @@ SOCK *Accept6(SOCK *sock)
|
||||
size = sizeof(addr);
|
||||
|
||||
#ifdef OS_UNIX
|
||||
#ifdef UNIX_LINUX
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
UnixIgnoreSignalForThread(SIGUSR1);
|
||||
#endif // UNIX_LINUX
|
||||
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
sock->CallingThread = pthread_self();
|
||||
#endif // OS_UNIX
|
||||
|
||||
@ -13625,7 +13664,7 @@ void Disconnect(SOCK *sock)
|
||||
// Connect to localhost if the socket is in listening
|
||||
sock->CancelAccept = true;
|
||||
|
||||
#ifdef UNIX_LINUX
|
||||
#if defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
{
|
||||
pthread_t t = sock->CallingThread;
|
||||
|
||||
@ -13637,7 +13676,7 @@ void Disconnect(SOCK *sock)
|
||||
SleepThread(200);
|
||||
}
|
||||
}
|
||||
#endif // UNIX_LINUX
|
||||
#endif // defined(UNIX_LINUX) || defined(UNIX_MACOS)
|
||||
|
||||
#ifdef OS_WIN32
|
||||
if (sock->hAcceptEvent != NULL)
|
||||
|
@ -106,9 +106,11 @@
|
||||
#include <errno.h>
|
||||
#include <Mayaqua/Mayaqua.h>
|
||||
|
||||
// Struct statfs for MacOS X
|
||||
#ifdef UNIX_MACOS
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
#ifdef NO_VLAN
|
||||
// Struct statfs for MacOS X
|
||||
typedef struct fsid { int32_t val[2]; } fsid_t;
|
||||
struct statfs {
|
||||
short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
|
||||
@ -2057,8 +2059,19 @@ UINT64 UnixGetTick64()
|
||||
return ret;
|
||||
|
||||
#else
|
||||
|
||||
#ifdef UNIX_MACOS
|
||||
static clock_serv_t clock_serv = 0;
|
||||
mach_timespec_t t;
|
||||
UINT64 ret;
|
||||
if (clock_serv == 0) {
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_serv);
|
||||
}
|
||||
clock_get_time(clock_serv, &t);
|
||||
ret = (UINT64)t.tv_sec * 1000LL + (UINT64)t.tv_nsec / 1000000LL;
|
||||
return ret;
|
||||
#else
|
||||
return TickRealtimeManual();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -2553,16 +2566,16 @@ void UnixExecService(char *name, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop
|
||||
signal(SIGTERM, &UnixSigTermHandler);
|
||||
while (unix_svc_terminate == false)
|
||||
{
|
||||
#ifndef UNIX_BSD
|
||||
#if !(defined(UNIX_BSD) || defined(UNIX_MACOS))
|
||||
pause();
|
||||
#else // UNIX_BSD
|
||||
#else // defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||
if (UnixReadCtlFile() != saved_ctl)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
SleepThread(1394);
|
||||
#endif // UNIX_BSD
|
||||
#endif // defined(UNIX_BSD) || defined(UNIX_MACOS)
|
||||
}
|
||||
|
||||
// Stop
|
||||
|
Loading…
Reference in New Issue
Block a user