Commit 5edfe797 authored by Sergey Lyubka's avatar Sergey Lyubka

Using _beginthread() for starting threads on Windows

parent 6d70e5c6
...@@ -221,6 +221,12 @@ typedef int SOCKET; ...@@ -221,6 +221,12 @@ typedef int SOCKET;
#define MAX_CGI_ENVIR_VARS 64 #define MAX_CGI_ENVIR_VARS 64
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#ifdef _WIN32
static pthread_t pthread_self(void) {
return GetCurrentThreadId();
}
#endif // _WIN32
#if defined(DEBUG) #if defined(DEBUG)
#define DEBUG_TRACE(x) do { \ #define DEBUG_TRACE(x) do { \
flockfile(stdout); \ flockfile(stdout); \
...@@ -863,10 +869,6 @@ static int pthread_cond_destroy(pthread_cond_t *cv) { ...@@ -863,10 +869,6 @@ static int pthread_cond_destroy(pthread_cond_t *cv) {
return CloseHandle(cv->signal) && CloseHandle(cv->broadcast) ? 0 : -1; return CloseHandle(cv->signal) && CloseHandle(cv->broadcast) ? 0 : -1;
} }
static pthread_t pthread_self(void) {
return GetCurrentThreadId();
}
// For Windows, change all slashes to backslashes in path names. // For Windows, change all slashes to backslashes in path names.
static void change_slashes_to_backslashes(char *path) { static void change_slashes_to_backslashes(char *path) {
int i; int i;
...@@ -1104,18 +1106,8 @@ struct dirent * readdir(DIR *dir) { ...@@ -1104,18 +1106,8 @@ struct dirent * readdir(DIR *dir) {
#define set_close_on_exec(fd) // No FD_CLOEXEC on Windows #define set_close_on_exec(fd) // No FD_CLOEXEC on Windows
static int start_thread(struct mg_context *ctx, mg_thread_func_t func, static int start_thread(struct mg_context *ctx, mg_thread_func_t f, void *p) {
void *param) { return _beginthread((void (__cdecl *)(void *)) f, 0, p) == -1L ? -1 : 0;
HANDLE hThread;
ctx = NULL; // Unused
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, param, 0,
NULL);
if (hThread != NULL) {
(void) CloseHandle(hThread);
}
return hThread == NULL ? -1 : 0;
} }
static HANDLE dlopen(const char *dll_name, int flags) { static HANDLE dlopen(const char *dll_name, int flags) {
...@@ -3454,7 +3446,7 @@ static int set_ports_option(struct mg_context *ctx) { ...@@ -3454,7 +3446,7 @@ static int set_ports_option(struct mg_context *ctx) {
// handshake will figure out that the client is down and // handshake will figure out that the client is down and
// will close the server end. // will close the server end.
// Thanks to Igor Klopov who suggested the patch. // Thanks to Igor Klopov who suggested the patch.
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &on,
sizeof(on)) != 0 || sizeof(on)) != 0 ||
bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 || bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 ||
listen(sock, 100) != 0) { listen(sock, 100) != 0) {
...@@ -3783,7 +3775,7 @@ static void close_socket_gracefully(SOCKET sock) { ...@@ -3783,7 +3775,7 @@ static void close_socket_gracefully(SOCKET sock) {
// ephemeral port exhaust problem under high QPS. // ephemeral port exhaust problem under high QPS.
linger.l_onoff = 1; linger.l_onoff = 1;
linger.l_linger = 1; linger.l_linger = 1;
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)); setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
// Send FIN to the client // Send FIN to the client
(void) shutdown(sock, SHUT_WR); (void) shutdown(sock, SHUT_WR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment