-/* ClientSocket.c - NeonServ v5.5
+/* ClientSocket.c - NeonServ v5.6
* Copyright (C) 2011-2012 Philipp Kreil (pk910)
*
* This program is free software: you can redistribute it and/or modify
#include "ConfigParser.h"
#include "version.h"
#include "IOHandler.h"
+#include "IRCEvents.h"
struct socket_list {
struct ClientSocket *data;
//the magic list :P
static struct socket_list *sockets = NULL;
-static char buffer[BUF_SIZ];
static IOHANDLER_CALLBACK(socket_callback);
}
struct ClientSocket* create_socket(char *host, int port, char *bindto, char *pass, char *nick, char *ident, char *realname) {
+ if(!sockets)
+ init_sockets();
struct ClientSocket *client = malloc(sizeof(*client));
if (!client) {
return NULL;
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);
} else
last_sock = sock;
}
+ event_freeclient(client);
free(client->host);
if(client->bind)
free(client->bind);
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;
+ #ifdef HAVE_THREADS
+ unsigned int tid;
+ #endif
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
+ client->traffic_in += strlen(event->data.recv_str);
parse_line(client, event->data.recv_str);
#ifdef HAVE_THREADS
clientsocket_end_of_recv(tid);