Browse Source

- Improve stomp_free_client()

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)
203 203
 		logwarn("Client %d socket error, disconnecting.", client->fd);
204 204
 	}
205 205
 
206
+	client->response_cmd = STOMP_CMD_DISCONNECT;
206 207
 	stomp_free_client(client);
207
-
208
-	bufferevent_free(client->bev);
209
-	close(client->fd);
210
-	free(client);
211 208
 }
212 209
 
213 210
 /**

+ 12
- 16
stomputil.c View File

@@ -84,29 +84,25 @@ struct queue* stomp_find_queue(const char *queuename)
84 84
 
85 85
 void stomp_free_queue(struct queue *queue)
86 86
 {
87
-   /* TODO: implement stomp_free_queue */
88
-   ;
87
+   /* TODO: Remove subscriptions */
88
+
89
+   TAILQ_REMOVE(&queues, queue, entries);
90
+   free(queue);
89 91
 }
90 92
 
91 93
 void stomp_free_client(struct client *client)
92 94
 {        
93
-   /* TODO: remove all subscriptions */
94
-   /* TODO: free all allocated memory */
95
-
96
-   struct client *entry, *tmp_entry;
97
-         
98
-   for (entry = TAILQ_FIRST(&clients); entry != NULL; entry = tmp_entry) {
99
-      tmp_entry = TAILQ_NEXT(entry, entries);
100
-      if ((void *)tmp_entry != NULL && client->fd == tmp_entry->fd) {
101
-         TAILQ_REMOVE(&clients, entry, entries);
102
-         free(entry);
103
-      }
104
-   }
95
+   /* Error/Logout */
96
+   logwarn("Logout Client %d", client->fd);
105 97
 
106 98
    client->authenticated = 0;
107
-   logwarn("Free client %d", client->fd);
108
-
99
+   /* TODO: remove all subscriptions */
100
+         
101
+   /* Disconnect/Free */
109 102
    if(client->response_cmd == STOMP_CMD_DISCONNECT){
103
+      /* TODO: free all allocated memory */
104
+      TAILQ_REMOVE(&clients, client, entries);
105
+
110 106
       bufferevent_free(client->bev);
111 107
       close(client->fd);
112 108
       free(client);

Loading…
Cancel
Save