fixed WIN32 support
authorpk910 <philipp@zoelle1.de>
Mon, 23 Jan 2012 15:45:59 +0000 (16:45 +0100)
committerpk910 <philipp@zoelle1.de>
Mon, 23 Jan 2012 15:51:24 +0000 (16:51 +0100)
.gitignore
src/ClientSocket.c
src/ClientSocket.h
src/HandleInfoHandler.c
src/IRCParser.c
src/QServer.c
src/WHOHandler.c
src/cmd_global_netinfo.c
src/main.c
src/main.h
src/mysqlConn.c

index a3d7d92901277383e84eec2572c2592febbe5856..34025fe26af63b7e0bcc3b359c982e1de5db3905 100644 (file)
@@ -27,6 +27,7 @@ Makefile
 missing
 stamp-h1
 neonserv
-neonserv.exe
+neonserv*.exe
 libmysql.dll
+pthreadGC2.dll
 motd.txt
\ No newline at end of file
index c49577724393e3de6b1443841072ff8e1ed46105..6d2c34e5d20efe744237d1d6b3fab270a15c7607 100644 (file)
@@ -35,7 +35,7 @@ static pthread_mutex_t synchronized;
 static pthread_mutex_t synchronized_recv;
 
 struct ParseOrder {
-    unsigned long tid;
+    unsigned int tid;
     struct ParseOrder *next;
 };
 struct ParseOrder *parse_order = NULL;
@@ -230,7 +230,7 @@ static int _connect_socket(struct ClientSocket *client) {
     return 1;
 }
 #else
-static int connect_socket(struct ClientSocket *client) {
+static int _connect_socket(struct ClientSocket *client) {
     if((client->flags & SOCKET_FLAG_CONNECTED)) return 1;
     struct hostent *host;
     struct sockaddr_in addr;
@@ -376,7 +376,7 @@ int write_socket(struct ClientSocket *client, char* msg, int len) {
 }
 
 #if HAVE_THREADS
-static void clientsocket_start_of_recv(unsigned long tid) {
+static void clientsocket_start_of_recv(unsigned int tid) {
     SYNCHRONIZE(whohandler_sync);
     struct ParseOrder *entry, *last;
     for(last = parse_order; last; last = last->next) {
@@ -393,7 +393,7 @@ static void clientsocket_start_of_recv(unsigned long tid) {
     DESYNCHRONIZE(whohandler_sync);
 }
 
-static void clientsocket_end_of_recv(unsigned long tid) {
+static void clientsocket_end_of_recv(unsigned int tid) {
     SYNCHRONIZE(whohandler_sync);
     struct ParseOrder *entry, *last = NULL;
     for(entry = parse_order; entry; entry = entry->next) {
@@ -410,7 +410,7 @@ static void clientsocket_end_of_recv(unsigned long tid) {
     DESYNCHRONIZE(whohandler_sync);
 }
 
-int clientsocket_parseorder_top(unsigned long tid) {
+int clientsocket_parseorder_top(unsigned int tid) {
     if(parse_order && parse_order->tid == tid)
         return 1;
     else
@@ -494,7 +494,7 @@ void socket_loop(int timeout_seconds) {
                     sock->bufferpos -= used;
                 }
                 is_synchronized = 0;
-                unsigned long tid = syscall(SYS_gettid);
+                unsigned int tid = (unsigned int) pthread_self_tid();
                 clientsocket_start_of_recv(tid);
                 DESYNCHRONIZE(synchronized_recv);
                 parse_lines(sock, linesbuf, used);
index 1ab71397d2ec182564a619c63004cdb1f59fc578..37543998855b2e63d7690698dcfc029e7a79e048 100644 (file)
@@ -84,7 +84,7 @@ int disconnect_socket(struct ClientSocket *client);
 int write_socket_force(struct ClientSocket *client, char* msg, int len);
 int write_socket(struct ClientSocket *client, char* msg, int len);
 #ifdef HAVE_THREADS
-int clientsocket_parseorder_top(unsigned long tid);
+int clientsocket_parseorder_top(unsigned int tid);
 #endif
 void socket_loop(int timeout_seconds);
 void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
index 0508e07413448c82c7dc22f2661b364d333db646..6e5415ffe40381af7b894b72cc37f97d512a156a 100644 (file)
@@ -207,7 +207,7 @@ static void recv_notice(struct UserNode *user, struct UserNode *target, char *me
     
     if(do_match) {
         #ifdef HAVE_THREADS
-        unsigned long tid = syscall(SYS_gettid);
+        unsigned int tid = (unsigned int) pthread_self_tid();
         while(!clientsocket_parseorder_top(tid)) {
             usleep(1000); //1ms
         }
index 97e851aa2eb63b8b4ed0ff7bb2212f5ee99e6244..eed9380f8e0dddb242bee17782200f36ab36d987 100644 (file)
@@ -58,7 +58,7 @@ static void parse_line(struct ClientSocket *client, char *line) {
     int argc = 0;
     char *argv[MAXNUMPARAMS];
     #ifdef HAVE_THREADS
-    printf("[%lu recv %lu] %s\n", syscall(SYS_gettid), (unsigned long) strlen(line), line);
+    printf("[%d recv %lu] %s\n", getCurrentThreadID(), (unsigned long) strlen(line), line);
     #else
     printf("[recv %lu] %s\n", (unsigned long) strlen(line), line);
     #endif
index fd10beb46cd3965fab8a651b50d70160b8b99a8a..fd0e8e6676a1486bc5ab12059dbf265a279ddfe2 100644 (file)
 #include "ConfigParser.h"
 #include "bots.h"
 
+#ifdef WIN32
+typedef uint32_t socklen_t;
+#endif
+
 #define QSERVER_TIMEOUT 30
 #define QSERVER_MAXCLIENTS 100
 
@@ -52,7 +56,7 @@ void qserver_init() {
         if (server_sockfd < 0) 
             return;
         struct sockaddr_in serv_addr;
-        bzero((char *) &serv_addr, sizeof(serv_addr));
+        memset(&serv_addr, 0, sizeof(serv_addr));
         int portno = get_int_field("QServer.port");
         if(!portno)
             portno = 7499;
index f8769decabbce38aa79444156a7b1006b3450e83..28547188eb3f0e0f2e22213a98af3a344ccdf5c5 100644 (file)
@@ -242,7 +242,7 @@ static void _recv_whohandler_354(struct ClientSocket *client, char **argv, unsig
     struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, type, 0);
     if(entry == NULL) return;
     #ifdef HAVE_THREADS
-    unsigned long tid = syscall(SYS_gettid);
+    unsigned int tid = (unsigned int) pthread_self_tid();
     while(!clientsocket_parseorder_top(tid)) {
         usleep(1000); //1ms
     }
@@ -338,7 +338,7 @@ static void _recv_whohandler_315(struct ClientSocket *client, char **argv, unsig
     struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, type, 0);
     if(entry == NULL) return;
     #ifdef HAVE_THREADS
-    unsigned long tid = syscall(SYS_gettid);
+    unsigned int tid = (unsigned int) pthread_self_tid();
     while(!clientsocket_parseorder_top(tid)) {
         usleep(1000); //1ms
     }
index 1e68aaaff48e5fd6dccb87440af54ebb0cb6daed..3d01c989f0da3089f78e614233636fc63f9f7170 100644 (file)
@@ -146,7 +146,7 @@ CMD_BIND(global_cmd_netinfo) {
     
     #ifdef HAVE_THREADS
     content[0] = get_language_string(user, "NS_NETINFO_THREADS");
-    sprintf(tmp, "%d (current tid: %lu)", running_threads, syscall(SYS_gettid));
+    sprintf(tmp, "%d (current thread: %i)", running_threads, getCurrentThreadID());
     content[1] = tmp;
     table_add(table, content);
     #endif
index 17980b445762e5b2b9634d94bc2c4f2d93e98c98..b86633e7e01536e4df08fa7fb657f429dca994fc 100644 (file)
@@ -101,6 +101,8 @@ static int load_mysql_config() {
 }
 
 #ifdef HAVE_THREADS
+pthread_t *current_threads = NULL;
+
 void * thread_main(void *arg) {
     time_t socket_wait;
     while(running) {
@@ -114,6 +116,22 @@ void * thread_main(void *arg) {
     running_threads--;
     return NULL;
 }
+
+int getCurrentThreadID() {
+    if(!current_threads) return 0;
+    int i;
+    unsigned int my_tid = (unsigned int) pthread_self_tid();
+    for(i = 0; i < running_threads; i++) {
+        #ifdef WIN32
+        if((unsigned int) current_threads[i].p == my_tid)
+        #else
+        if((unsigned int) current_threads[i] == my_tid)
+        #endif
+            return i+1;
+    }
+    return 0;
+}
+
 #endif
 
 int main(int argc, char *argv[]) {
@@ -170,14 +188,13 @@ main:
     
     int worker_threads = get_int_field("General.worker_threads");
     if(!worker_threads) worker_threads = 1;
-    
     running = 1;
     #ifdef HAVE_THREADS
-    pthread_t tid[worker_threads];
     int tid_id = 0;
+    current_threads = calloc(worker_threads, sizeof(*current_threads));
     for(tid_id = 0; tid_id < worker_threads; tid_id++) {
         running_threads++;
-        pthread_create(&tid[tid_id], NULL, thread_main, NULL);
+        pthread_create(&current_threads[tid_id], NULL, thread_main, NULL);
     }
     int usleep_delay = 1000000 / TICKS_PER_SECOND;
     while(running) {
@@ -188,7 +205,7 @@ main:
         usleep(usleep_delay);
     }
     for(tid_id = 0; tid_id < worker_threads; tid_id++) {
-        pthread_join(tid[tid_id], NULL);
+        pthread_join(current_threads[tid_id], NULL);
     }
     running_threads = 0;
     #else
index 6a2a99f575a38f666adb593a2a1b4d9f38b45684..d14869e11564df1426fe6b2a56967b18659f8bd3 100644 (file)
@@ -21,7 +21,6 @@
 #define NEONSERV_VERSION "5.3"
 #define VERSION_PATCHLEVEL 543
 
-#include <features.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +30,7 @@
 #include <winsock2.h>
 #include <malloc.h>
 #else
+#include <features.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <time.h>
 #ifdef HAVE_THREADS
 #include <pthread.h>
-#include <sys/syscall.h>
+#ifdef WIN32
+#define pthread_self_tid() pthread_self().p
+#else
+#define pthread_self_tid() pthread_self()
+#endif
 #define THREAD_MUTEX_INIT(var) { \
     pthread_mutexattr_t mutex_attr; \
     pthread_mutexattr_init(&mutex_attr);\
@@ -136,6 +140,8 @@ extern int statistics_enabled;
 extern int running_threads;
 extern pthread_mutex_t cache_sync;
 extern pthread_mutex_t whohandler_sync, whohandler_mass_sync;
+
+int getCurrentThreadID();
 #endif
 
 int stricmp (const char *s1, const char *s2);
index 12ab76d6ff709ab7bf986e08384a62beaaef80bd..3e5dd19dfac03a156ede2bb49a30bfb26f83b5a7 100644 (file)
@@ -19,7 +19,7 @@
 #define DATABASE_VERSION "15"
 
 struct mysql_conn_struct {
-    unsigned long tid;
+    unsigned int tid;
     MYSQL *mysql_conn;
     struct used_result *used_results;
     struct escaped_string *escaped_strings;
@@ -264,9 +264,9 @@ char* escape_string(const char *str) {
 struct mysql_conn_struct *get_mysql_conn_struct() {
     SYNCHRONIZE(synchronized);
     struct mysql_conn_struct *mysql_conn;
-    unsigned long tid;
+    unsigned int tid;
     #ifdef HAVE_THREADS
-    tid = syscall(SYS_gettid);
+    tid = (unsigned int) pthread_self_tid();
     #else
     tid = 1;
     #endif