X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmain.c;h=22ced25ddeb0a5097a5edeb9d8485d49e73e1cc0;hb=c99b8d5951fe6429844c8cb5ff94213bb625ad95;hp=f3afaaf8a18c97a9bfd50a452eac5c2bd2a9feb5;hpb=923d68b1cf61c22ac4bd61cd55f4ac305def1ea3;p=NeonServV5.git diff --git a/src/main.c b/src/main.c index f3afaaf..22ced25 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* main.c - NeonServ v5.4 +/* main.c - NeonServ v5.5 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -40,6 +40,7 @@ #include "version.h" #include "modules.h" #include "module_commands.h" +#include "ModuleFunctions.h" time_t start_time; static int running, hard_restart; @@ -107,30 +108,24 @@ static int load_mysql_config() { return 1; } -#ifdef HAVE_THREADS -pthread_t *current_threads = NULL; +static TIMEQ_CALLBACK(clear_cache) { + timeq_add(CLEAR_CACHE_INTERVAL, 0, clear_cache, NULL); + clearTempUsers(); + destroyEvents(); + mysql_free(); +} -void * thread_main(void *arg) { +void *thread_main(void *arg) { time_t socket_wait; while(running) { - socket_wait = time(0) + SOCKET_SELECT_TIME; - do { - if(!socket_loop(SOCKET_SELECT_TIME)) { - if(!running) break; - putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.\n"); - cleanup(); - exit(0); - } - } while(time(0) < socket_wait); - if(!running) break; - clearTempUsers(); - destroyEvents(); - mysql_free(); + iohandler_poll(); } - running_threads--; return NULL; } +#ifdef HAVE_THREADS +pthread_t *current_threads = NULL; + int getCurrentThreadID() { if(!current_threads) return 0; int i; @@ -261,18 +256,6 @@ main: start_time = time(0); - #ifdef WIN32 - int res; - WSADATA wsadata; - // Start Windows Sockets. - res = WSAStartup(MAKEWORD(2, 0), &wsadata); - if (res) - { - perror("Unable to start Windows Sockets"); - return 0; - } - #endif - statistics_enabled = get_int_field("statistics.enable"); #ifdef HAVE_THREADS @@ -281,11 +264,7 @@ main: THREAD_MUTEX_INIT(whohandler_mass_sync); #endif - queue_init(); - init_sockets(); - init_timeq(); init_lang(); - ssl_init(); init_parser(); init_UserNode(); init_ChanNode(); @@ -295,6 +274,7 @@ main: register_module_commands(); init_handleinfohandler(); init_tools(); + init_modulefunctions(); loadModules(); init_bots(); init_DBHelper(); @@ -307,6 +287,8 @@ main: timeq_add(90, 0, main_checkauths, NULL); + timeq_add(CLEAR_CACHE_INTERVAL, 0, clear_cache, NULL); + int worker_threads = get_int_field("General.worker_threads"); if(!worker_threads) worker_threads = 1; running = 1; @@ -317,38 +299,13 @@ main: running_threads++; pthread_create(¤t_threads[tid_id], NULL, thread_main, NULL); } - int usleep_delay = 1000000 / TICKS_PER_SECOND; - while(running) { - timeq_tick(); - loop_modules(); - qserver_loop(); - queue_loop(); - mysql_free(); - usleep(usleep_delay); - } + #endif + thread_main(); + #ifdef HAVE_THREADS for(tid_id = 0; tid_id < worker_threads; tid_id++) { pthread_join(current_threads[tid_id], NULL); } running_threads = 0; - #else - time_t socket_wait; - while(running) { - socket_wait = time(0) + SOCKET_SELECT_TIME; - do { - if(!socket_loop(SOCKET_SELECT_TIME)) { - putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.\n"); - cleanup(); - exit(0); - } - } while(time(0) < socket_wait); - timeq_tick(); - loop_modules(); - clearTempUsers(); - destroyEvents(); - qserver_loop(); - queue_loop(); - mysql_free(); - } #endif cleanup(); if(hard_restart) {