//the magic list :P
static struct socket_list *sockets = NULL;
-static char buffer[BUF_SIZ];
static IOHANDLER_CALLBACK(socket_callback);
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;
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);
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
#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) {
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;
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);
/* 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);
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);
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;
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);
}
}
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);
client->iofd = NULL;
break;
case IOEVENT_ACCEPT:
-
+ qserver_accept(event->data.accept_fd);
break;
default:
break;
#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;
}
void *thread_main(void *arg) {
- time_t socket_wait;
while(running) {
iohandler_poll();
}
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);
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");
#include "bots.h"
#include "ChanNode.h"
#include "ClientSocket.h"
+#include "IOHandler.h"
#include "ConfigParser.h"
static void sigcrash();
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");