(thanks to the people reading git and excessively exploiting this bug... It was undet...
[NeonServV5.git] / src / ClientSocket.c
index eb11d88fc131558ff1bb698f883c37bd91144188..a624a305498337f8f2ff690144e78df2005a51c1 100644 (file)
@@ -25,6 +25,7 @@
 #include "version.h"
 #include "IOHandler.h"
 #include "IRCEvents.h"
+#include "log.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -54,7 +55,7 @@ void init_sockets() {
     sockets = malloc(sizeof(*sockets));
     if (!sockets)
     {
-        perror("malloc() failed");
+        printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     sockets->data = NULL;
@@ -99,9 +100,10 @@ struct ClientSocket* create_socket(char *host, int port, char *bindto, char *pas
 void connect_socket(struct ClientSocket *client) {
     client->iofd = iohandler_connect(client->host, client->port, ((client->flags & SOCKET_FLAG_SSL) ? 1 : 0), client->bind, socket_callback);
     client->iofd->data = client;
+    client->flags |= SOCKET_FLAG_RECONNECT;
 }
 
-int close_socket(struct ClientSocket *client) {
+static int _close_socket(struct ClientSocket *client) {
     if(client == NULL) return 0;
     if((client->flags & SOCKET_FLAG_CONNECTED)) {
         iohandler_printf(client->iofd, "QUIT :[NeonServ %s.%d] disconnect requested.\n", NEONSERV_VERSION, patchlevel);
@@ -121,6 +123,12 @@ int close_socket(struct ClientSocket *client) {
     return 1;
 }
 
+int close_socket(struct ClientSocket *client) { //external call (don't reconnect)
+    if(client == NULL) return 0;
+    client->flags &= ~SOCKET_FLAG_RECONNECT;
+    return _close_socket(client);
+}
+
 int destroy_socket(struct ClientSocket *client) {
     if(client == NULL) return 0;
     close_socket(client);
@@ -156,9 +164,9 @@ 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
-    putlog(LOGLEVEL_RAW, "[%d send %d] %s", getCurrentThreadID(), len, msg);
+    printf_log("main", LOG_IRCRAW, "[%d send %d] %s", getCurrentThreadID(), len, msg);
     #else
-    putlog(LOGLEVEL_RAW, "[send %d] %s", len, msg);
+    printf_log("main", LOG_IRCRAW, "[send %d] %s", len, msg);
     #endif
        iohandler_send(client->iofd, msg, len);
     client->traffic_out += len;
@@ -234,7 +242,7 @@ static IOHANDLER_CALLBACK(socket_callback) {
         break;
     case IOEVENT_NOTCONNECTED:
     case IOEVENT_CLOSED:
-        close_socket(client);
+        _close_socket(client);
         if(client->flags & SOCKET_FLAG_RECONNECT) {
             struct timeval timeout;
             gettimeofday(&timeout, NULL);