Browse Source

- Improve stomp_free_client()

master
decke 7 years ago
parent
commit
7b20b8d187
2 changed files with 13 additions and 20 deletions
  1. 1
    4
      server.c
  2. 12
    16
      stomputil.c

+ 1
- 4
server.c View File

@@ -203,11 +203,8 @@ void buffered_on_error(struct bufferevent *bev, short what, void *arg)
logwarn("Client %d socket error, disconnecting.", client->fd);
}

client->response_cmd = STOMP_CMD_DISCONNECT;
stomp_free_client(client);

bufferevent_free(client->bev);
close(client->fd);
free(client);
}

/**

+ 12
- 16
stomputil.c View File

@@ -84,29 +84,25 @@ struct queue* stomp_find_queue(const char *queuename)

void stomp_free_queue(struct queue *queue)
{
/* TODO: implement stomp_free_queue */
;
/* TODO: Remove subscriptions */

TAILQ_REMOVE(&queues, queue, entries);
free(queue);
}

void stomp_free_client(struct client *client)
{
/* TODO: remove all subscriptions */
/* TODO: free all allocated memory */

struct client *entry, *tmp_entry;
for (entry = TAILQ_FIRST(&clients); entry != NULL; entry = tmp_entry) {
tmp_entry = TAILQ_NEXT(entry, entries);
if ((void *)tmp_entry != NULL && client->fd == tmp_entry->fd) {
TAILQ_REMOVE(&clients, entry, entries);
free(entry);
}
}
/* Error/Logout */
logwarn("Logout Client %d", client->fd);

client->authenticated = 0;
logwarn("Free client %d", client->fd);

/* TODO: remove all subscriptions */
/* Disconnect/Free */
if(client->response_cmd == STOMP_CMD_DISCONNECT){
/* TODO: free all allocated memory */
TAILQ_REMOVE(&clients, client, entries);

bufferevent_free(client->bev);
close(client->fd);
free(client);

Loading…
Cancel
Save