some fixes for previous commit
authorpk910 <philipp@zoelle1.de>
Tue, 21 Aug 2012 23:40:19 +0000 (01:40 +0200)
committerpk910 <philipp@zoelle1.de>
Tue, 21 Aug 2012 23:59:31 +0000 (01:59 +0200)
src/ClientSocket.c
src/ClientSocket.h
src/IRCQueue.c
src/QServer.c
src/main.c
src/modules/global.mod/cmd_global_reconnect.c
src/signal.c

index 5632de65e2fc07775d4ad8ab78ceb69fa257b036..13f8b6b6d55f82b9debe72288f0422f35694f197 100644 (file)
@@ -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);
index f4fc57ab49b30b8951f59da950277819017a83ab..b8db11068bee5edbafff64684bdfefcb88b89cbd 100644 (file)
@@ -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);
index 4fa520b02d6e7c7406df2fed83a4fd160727e3ef..d68f098b0bd9fd64c2a8baeea93cd1051e2c3903 100644 (file)
@@ -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;
index 1e112332bbf1bed146797caf7ccd1a90fd705543..93d2a4fb917bfc726501f16a959234ccd6556a69 100644 (file)
@@ -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;
index 22ced25ddeb0a5097a5edeb9d8485d49e73e1cc0..d585ada9e62872c3325a0f75219c8dc1554704de 100644 (file)
 #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(&current_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);
index 84eafa3c3b4d23cfeed3fa49f96f01211aa00567..1bd3aae91350ae62360b23fd34a32d8aadf9f928 100644 (file)
@@ -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");
index 37f66f38671d98cf9f9a911963e7bb96ad26e905..d427ae2e9510884b927b02f4005899d2d37ede6d 100644 (file)
@@ -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");