Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tcp server: the tcp_server_delete() must be in sync with poll
  • Loading branch information
perexg committed Jan 4, 2016
1 parent d77186d commit 2d9ff18
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/tcp.c
Expand Up @@ -453,6 +453,7 @@ typedef struct tcp_server {
struct sockaddr_storage bound;
tcp_server_ops_t ops;
void *opaque;
LIST_ENTRY(tcp_server) link;
} tcp_server_t;

typedef struct tcp_server_launch {
Expand All @@ -471,6 +472,7 @@ typedef struct tcp_server_launch {
LIST_ENTRY(tcp_server_launch) jlink;
} tcp_server_launch_t;

static LIST_HEAD(, tcp_server) tcp_server_delete_list = { 0 };
static LIST_HEAD(, tcp_server_launch) tcp_server_launches = { 0 };
static LIST_HEAD(, tcp_server_launch) tcp_server_active = { 0 };
static LIST_HEAD(, tcp_server_launch) tcp_server_join = { 0 };
Expand Down Expand Up @@ -685,6 +687,10 @@ tcp_server_loop(void *aux)
free(tsl);
goto next;
}
while ((ts = LIST_FIRST(&tcp_server_delete_list)) != NULL) {
LIST_REMOVE(ts, link);
free(ts);
}
pthread_mutex_unlock(&global_lock);
}
continue;
Expand Down Expand Up @@ -919,6 +925,7 @@ tcp_server_delete(void *server)
{
tcp_server_t *ts = server;
tvhpoll_event_t ev;
char c = 'D';

if (server == NULL)
return;
Expand All @@ -927,8 +934,9 @@ tcp_server_delete(void *server)
ev.fd = ts->serverfd;
ev.events = TVHPOLL_IN;
ev.data.ptr = ts;
tvhpoll_rem(tcp_server_poll, &ev, 1);
free(ts);
tvhpoll_rem(tcp_server_poll, &ev, 1);
LIST_INSERT_HEAD(&tcp_server_delete_list, ts, link);
tvh_write(tcp_server_pipe.wr, &c, 1);
}

/**
Expand Down Expand Up @@ -1081,6 +1089,7 @@ tcp_server_init(void)
void
tcp_server_done(void)
{
tcp_server_t *ts;
tcp_server_launch_t *tsl;
char c = 'E';
int64_t t;
Expand Down Expand Up @@ -1117,5 +1126,9 @@ tcp_server_done(void)
free(tsl);
pthread_mutex_lock(&global_lock);
}
while ((ts = LIST_FIRST(&tcp_server_delete_list)) != NULL) {
LIST_REMOVE(ts, link);
free(ts);
}
pthread_mutex_unlock(&global_lock);
}

0 comments on commit 2d9ff18

Please sign in to comment.