From: pk910 Date: Tue, 21 Aug 2012 23:40:19 +0000 (+0200) Subject: some fixes for previous commit X-Git-Tag: v5.5~9^2~13 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=9eb6179eb4d2c394c7913eda496c922cb8c5d1a8 some fixes for previous commit --- diff --git a/src/ClientSocket.c b/src/ClientSocket.c index 5632de6..13f8b6b 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -43,7 +43,6 @@ struct ParseOrder *parse_order = NULL; //the magic list :P static struct socket_list *sockets = NULL; -static char buffer[BUF_SIZ]; static IOHANDLER_CALLBACK(socket_callback); @@ -77,7 +76,6 @@ struct ClientSocket* create_socket(char *host, int port, char *bindto, char *pas client->user = NULL; client->network_name = NULL; client->flags = 0; - client->bufferpos = 0; client->traffic_in = 0; client->traffic_out = 0; client->connection_time = 0; @@ -103,9 +101,7 @@ void connect_socket(struct ClientSocket *client) { int close_socket(struct ClientSocket *client) { if(client == NULL) return 0; if((client->flags & SOCKET_FLAG_CONNECTED)) { - char quitbuf[MAXLEN]; - int quitlen = sprintf(quitbuf, "QUIT :[NeonServ %s.%d] disconnect requested.\n", NEONSERV_VERSION, patchlevel); - iohandler_send(client, quitbuf, quitlen); + iohandler_printf(client->iofd, "QUIT :[NeonServ %s.%d] disconnect requested.\n", NEONSERV_VERSION, patchlevel); bot_disconnect(client); @@ -152,7 +148,7 @@ int destroy_socket(struct ClientSocket *client) { return 1; } -static int write_socket_force(struct ClientSocket *client, char* msg, int len) { +int write_socket_force(struct ClientSocket *client, char* msg, int len) { if(!(client && (client->flags & SOCKET_FLAG_CONNECTED))) return 0; SYNCHRONIZE(synchronized); #ifdef HAVE_THREADS @@ -160,10 +156,10 @@ static int write_socket_force(struct ClientSocket *client, char* msg, int len) { #else putlog(LOGLEVEL_RAW, "[send %d] %s", len, msg); #endif - iohandler_send(client->iofd, msg, len) + iohandler_send(client->iofd, msg, len); client->traffic_out += len; DESYNCHRONIZE(synchronized); - return ret; + return 1; } int write_socket(struct ClientSocket *client, char* msg, int len) { @@ -219,6 +215,7 @@ int clientsocket_parseorder_top(unsigned int tid) { static IOHANDLER_CALLBACK(socket_callback) { struct ClientSocket *client = event->iofd->data; + unsigned int tid; switch(event->type) { case IOEVENT_CONNECTED: client->flags |= SOCKET_FLAG_CONNECTED; @@ -243,6 +240,7 @@ static IOHANDLER_CALLBACK(socket_callback) { break; case IOEVENT_RECV: #ifdef HAVE_THREADS + tid = (unsigned int) pthread_self_tid(); clientsocket_start_of_recv(tid); #endif parse_line(client, event->data.recv_str); diff --git a/src/ClientSocket.h b/src/ClientSocket.h index f4fc57a..b8db110 100644 --- a/src/ClientSocket.h +++ b/src/ClientSocket.h @@ -84,6 +84,7 @@ struct ClientSocket { /* MODULAR ACCESSIBLE */ void connect_socket(struct ClientSocket *client); /* MODULAR ACCESSIBLE */ int close_socket(struct ClientSocket *client); /* MODULAR ACCESSIBLE */ int destroy_socket(struct ClientSocket *client); +int write_socket_force(struct ClientSocket *client, char* msg, int len); /* MODULAR ACCESSIBLE */ int write_socket(struct ClientSocket *client, char* msg, int len); #ifdef HAVE_THREADS int clientsocket_parseorder_top(unsigned int tid); diff --git a/src/IRCQueue.c b/src/IRCQueue.c index 4fa520b..d68f098 100644 --- a/src/IRCQueue.c +++ b/src/IRCQueue.c @@ -55,6 +55,12 @@ static struct BotQueue *initialize_queue(struct ClientSocket *client) { return queue; } +static int calculate_penalty(char *message) { + int msglen = strlen(message); + int penalty = (2 + msglen / 100); + return penalty; +} + int queue_add(struct ClientSocket *client, char* msg, int len) { if(!client->queue) client->queue = initialize_queue(client); @@ -153,12 +159,6 @@ int queue_add(struct ClientSocket *client, char* msg, int len) { return 1; } -static int calculate_penalty(char *message) { - int msglen = strlen(message); - int penalty = (2 + msglen / 100); - return penalty; -} - static void dequeue_bot(struct ClientSocket *client) { if(client->queue->penalty >= MAXPENALTY) return; int penalty; diff --git a/src/QServer.c b/src/QServer.c index 1e11233..93d2a4f 100644 --- a/src/QServer.c +++ b/src/QServer.c @@ -54,9 +54,9 @@ void qserver_init() { char *host = get_string_field("QServer.host"); if(!host) host = "0.0.0.0"; - int portno = get_int_field("QServer.port"); - if(!portno) - portno = 7499; + int port = get_int_field("QServer.port"); + if(!port) + port = 7499; server_iofd = iohandler_listen(host, port, qserver_callback); } } @@ -87,7 +87,7 @@ static void qserver_put(struct QServerClient *client, const char *text, ...) { va_list arg_list; char sendBuf[MAXLEN]; int pos; - if (!(client && !(client->flags & QSERVER_FLAG_DISCONNECT))) return; + if (!client || !client->iofd) return; sendBuf[0] = '\0'; va_start(arg_list, text); pos = vsnprintf(sendBuf, MAXLEN - 2, text, arg_list); @@ -218,7 +218,7 @@ static IOHANDLER_CALLBACK(qserver_callback) { client->iofd = NULL; break; case IOEVENT_ACCEPT: - + qserver_accept(event->data.accept_fd); break; default: break; diff --git a/src/main.c b/src/main.c index 22ced25..d585ada 100644 --- a/src/main.c +++ b/src/main.c @@ -35,12 +35,12 @@ #include "IRCQueue.h" #include "DBHelper.h" #include "ConfigParser.h" -#include "ssl.h" #include "QServer.h" #include "version.h" #include "modules.h" #include "module_commands.h" #include "ModuleFunctions.h" +#include "IOHandler.h" time_t start_time; static int running, hard_restart; @@ -116,7 +116,6 @@ static TIMEQ_CALLBACK(clear_cache) { } void *thread_main(void *arg) { - time_t socket_wait; while(running) { iohandler_poll(); } @@ -300,7 +299,7 @@ main: pthread_create(¤t_threads[tid_id], NULL, thread_main, NULL); } #endif - thread_main(); + thread_main(NULL); #ifdef HAVE_THREADS for(tid_id = 0; tid_id < worker_threads; tid_id++) { pthread_join(current_threads[tid_id], NULL); diff --git a/src/modules/global.mod/cmd_global_reconnect.c b/src/modules/global.mod/cmd_global_reconnect.c index 84eafa3..1bd3aae 100644 --- a/src/modules/global.mod/cmd_global_reconnect.c +++ b/src/modules/global.mod/cmd_global_reconnect.c @@ -35,13 +35,13 @@ CMD_BIND(global_cmd_reconnect) { botid = atoi(row[0]); for(client = getBots(0, NULL); client; client = getBots(0, client)) { if(client->clientid == botid) { - disconnect_socket(client); - client->flags |= SOCKET_FLAG_FAST_JUMP; + close_socket(client); + connect_socket(client); break; } } } else { - disconnect_socket(client); + close_socket(client); connect_socket(client); } reply(textclient, user, "NS_RECONNECT_DONE"); diff --git a/src/signal.c b/src/signal.c index 37f66f3..d427ae2 100644 --- a/src/signal.c +++ b/src/signal.c @@ -18,6 +18,7 @@ #include "bots.h" #include "ChanNode.h" #include "ClientSocket.h" +#include "IOHandler.h" #include "ConfigParser.h" static void sigcrash(); @@ -85,8 +86,9 @@ static void sigcrash(int signum) { struct ClientSocket *bot; for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { if((bot->flags & SOCKET_FLAG_CONNECTED)) { - close(bot->sock); + iohandler_close(bot->iofd); bot->flags &= SOCKET_FLAG_CONNECTED; + bot->iofd = NULL; } } putlog(LOGLEVEL_INFO, "hard shutdown...\n");