Skip to content

Commit

Permalink
client: free udp when exit
Browse files Browse the repository at this point in the history
  • Loading branch information
liudongmiao committed Apr 13, 2024
1 parent f07a033 commit ea731a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ static void close_wss(struct bufferevent *raw, enum close_reason close_reason, s
struct bufferevent *tev = evhttp_connection_get_bufferevent(wss);
bufferevent_setcb(tev, close_wss_data_cb, NULL, close_wss_event_cb, wss);
} else {
LOGD("close wss %p as close was send", wss);
LOGD("close wss %p as close was sent", wss);
evhttp_connection_free(wss);
}
}
Expand Down
10 changes: 10 additions & 0 deletions wss-proxy-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ static void udp_read_cb_server(evutil_socket_t sock, short event, void *ctx) {
}
}

static void free_udp(bufferevent_udp *udp) {
struct bufferevent *raw = (struct bufferevent *) udp;
LOGD("free udp for peer %d", get_peer_port(raw));
if (raw->errorcb != raw_event_cb) {
send_close(raw, CLOSE_GOING_AWAY);
}
raw->errorcb(raw, BEV_EVENT_EOF, get_wss(raw));
}

static void server_context_free(const struct server_context *server_context) {
if (server_context->listener) {
evconnlistener_free(server_context->listener);
Expand All @@ -494,6 +503,7 @@ static void server_context_free(const struct server_context *server_context) {
evutil_closesocket(server_context->udp_sock);
}
if (server_context->udp_context.hash) {
lh_bufferevent_udp_doall(server_context->udp_context.hash, free_udp);
lh_bufferevent_udp_free(server_context->udp_context.hash);
}
if (server_context->udp_event) {
Expand Down

0 comments on commit ea731a7

Please sign in to comment.