static struct socket_list *sockets = NULL;
static char buffer[BUF_SIZ];
-static void init() {
+static void init_sockets() {
sockets = malloc(sizeof(*sockets));
if (!sockets)
{
}
struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user) {
- if(sockets == NULL) init();
+ if(sockets == NULL) init_sockets();
struct ClientSocket *client = malloc(sizeof(*client));
if (!client)
{
client->flags = 0;
client->bufferpos = 0;
client->botid = 0;
- client->trigger = NULL;
+ client->clientid = 0;
client->next = sockets->data;
sockets->data = client;
return client;
}
return NULL;
}
+
+void free_sockets() {
+ if(!sockets) return;
+ struct ClientSocket *client, *next;
+ for (client = sockets->data; client; client = next) {
+ next = client->next;
+ if((client->flags & SOCKET_FLAG_CONNECTED))
+ close(client->sock);
+ free(client->host);
+ free(client->pass);
+ free(client);
+ }
+ free(sockets);
+ sockets = NULL;
+}