Minor changes for Windows build

This commit is contained in:
Joseph Henry
2019-06-18 11:06:05 -07:00
parent f6f79b6305
commit 17e5b8172d
3 changed files with 12 additions and 11 deletions

View File

@@ -94,9 +94,6 @@ bool _run_lwip_tcpip = false;
//bool _startupError = false; //bool _startupError = false;
pthread_t service_thread;
pthread_t callback_thread;
// Global reference to ZeroTier service // Global reference to ZeroTier service
OneService *service; OneService *service;
@@ -272,7 +269,7 @@ int __zts_can_perform_service_operation()
void _api_sleep(int interval_ms) void _api_sleep(int interval_ms)
{ {
#if defined(_WIN32) #if defined (_WIN32)
Sleep(interval_ms); Sleep(interval_ms);
#else #else
struct timespec sleepValue = {0}; struct timespec sleepValue = {0};
@@ -283,11 +280,14 @@ void _api_sleep(int interval_ms)
int _change_nice(int increment) int _change_nice(int increment)
{ {
#ifndef _WIN32
if (increment == 0) { if (increment == 0) {
return 0; return 0;
} }
int priority = getpriority(PRIO_PROCESS, 0); int priority = getpriority(PRIO_PROCESS, 0);
return setpriority(PRIO_PROCESS, 0, priority+increment); return setpriority(PRIO_PROCESS, 0, priority+increment);
#endif
return 0;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@@ -406,7 +406,10 @@ void *_zts_run_service(void *arg)
// TODO: Find a more elegant solution // TODO: Find a more elegant solution
_api_sleep(ZTS_CALLBACK_PROCESSING_INTERVAL*2); _api_sleep(ZTS_CALLBACK_PROCESSING_INTERVAL*2);
_run_callbacks = false; _run_callbacks = false;
#ifndef _WIN32
pthread_exit(0); pthread_exit(0);
#endif
return NULL;
} }
#ifdef __cplusplus #ifdef __cplusplus
@@ -566,13 +569,16 @@ int zts_start(
WSAStartup(MAKEWORD(2, 2), &wsaData); WSAStartup(MAKEWORD(2, 2), &wsaData);
HANDLE serviceThread = CreateThread(NULL, 0, _zts_run_service, (void*)params, 0, NULL); HANDLE serviceThread = CreateThread(NULL, 0, _zts_run_service, (void*)params, 0, NULL);
HANDLE callbackThread = CreateThread(NULL, 0, _zts_run_callbacks, NULL, 0, NULL); HANDLE callbackThread = CreateThread(NULL, 0, _zts_run_callbacks, NULL, 0, NULL);
#endif #else
pthread_t service_thread;
pthread_t callback_thread;
if ((err = pthread_create(&service_thread, NULL, _zts_run_service, NULL)) != 0) { if ((err = pthread_create(&service_thread, NULL, _zts_run_service, NULL)) != 0) {
retval = err; retval = err;
} }
if ((err = pthread_create(&callback_thread, NULL, _zts_run_callbacks, NULL)) != 0) { if ((err = pthread_create(&callback_thread, NULL, _zts_run_callbacks, NULL)) != 0) {
retval = err; retval = err;
} }
#endif
#if defined(__linux__) #if defined(__linux__)
pthread_setname_np(service_thread, ZTS_SERVICE_THREAD_NAME); pthread_setname_np(service_thread, ZTS_SERVICE_THREAD_NAME);
pthread_setname_np(callback_thread, ZTS_EVENT_CALLBACK_THREAD_NAME); pthread_setname_np(callback_thread, ZTS_EVENT_CALLBACK_THREAD_NAME);
@@ -674,7 +680,7 @@ int zts_restart()
_userCallbackMethodRef = _tmpUserCallbackMethodRef; _userCallbackMethodRef = _tmpUserCallbackMethodRef;
return zts_start(tmpPath.c_str(), NULL, tmpPort); return zts_start(tmpPath.c_str(), NULL, tmpPort);
#else #else
return zts_start(tmpPath.c_str(), _tmpUserEventCallbackFunc, tmpPort); return ::zts_start(tmpPath.c_str(), _tmpUserEventCallbackFunc, tmpPort);
#endif #endif
} }
#ifdef SDK_JNI #ifdef SDK_JNI

View File

@@ -27,7 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <string> #include <string>
#include <map> #include <map>

View File

@@ -165,10 +165,6 @@ public:
void (*_handler)(void *, void *, uint64_t, const MAC &, const MAC &, unsigned int, unsigned int, void (*_handler)(void *, void *, uint64_t, const MAC &, const MAC &, unsigned int, unsigned int,
const void *, unsigned int); const void *, unsigned int);
void phyOnUnixClose(PhySocket *sock, void **uptr);
void phyOnUnixData(PhySocket *sock, void **uptr, void *data, ssize_t len);
void phyOnUnixWritable(PhySocket *sock, void **uptr, bool stack_invoked);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Lower-level lwIP netif handling and traffic handling readiness // // Lower-level lwIP netif handling and traffic handling readiness //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////