aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-28 21:09:24 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-28 21:09:24 +0200
commit0fafc1469701dfd6e4ae81dfc27fddb905ad602f (patch)
treebcfcff476a4d140f74f774523b193cc296c8d2d0
parent65bae05af453ea0ea3ef9d8400374abb7c6bf7a2 (diff)
server: Simplify delete_conn_data
-rw-r--r--main.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/main.c b/main.c
index 497f66e..77237bf 100644
--- a/main.c
+++ b/main.c
@@ -58,29 +58,19 @@ static void delete_conn_data(int fd){
debug("Deleting conn_data for fd=%d",fd);
struct hash_item *item=conn_hash[fd%CONN_HASH_SIZE];
assert(item);
- if(item->cd.fd==fd){
- if(item->cd.userid!=-1){
- userdata_unregister(item->cd.userid,fd);
- broadcast_online_change(item->cd.userid);
- }
- conn_hash[fd%CONN_HASH_SIZE]=item->next;
- conn_data_nullify(&item->cd);
- free(item);
- return;
- }
struct hash_item *parent=NULL;
while(item&&item->cd.fd!=fd){
parent=item;
item=item->next;
}
- assert(parent);
assert(item);
if(item->cd.userid!=-1){
userdata_unregister(item->cd.userid,fd);
broadcast_online_change(item->cd.userid);
}
conn_data_nullify(&item->cd);
- parent->next=item->next;
+ if(parent)parent->next=item->next;
+ else conn_hash[fd%CONN_HASH_SIZE]=item->next;
free(item);
}