From: Xiang Dai <764524258@qq.com> Date: Tue, 3 Sep 2019 05:53:54 +0000 (+0800) Subject: Avoid slow reverse-DNS requests caused by libwebsocket (#222) X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=94817b4eb37ea547893f26c9fc1b5ede2292e69b;p=ttyd.git Avoid slow reverse-DNS requests caused by libwebsocket (#222) * Avoid slow reverse-DNS requests caused by libwebsocket According to warmcat/libwebsockets#537 and following my own experience, in some circumstances lws_get_peer_addresses can take several seconds to execute a reverse DNS request on a connected peer IP. The effect is that sometimes a websocket connection takes several seconds before it is established. This PR addresses the described issue by replacing lws_get_peer_addresses with lws_get_peer_simple that completely skips the RDNS request. Signed-off-by: Xiang Dai <764524258@qq.com> --- diff --git a/src/http.c b/src/http.c index f3bd462..f0b8666 100644 --- a/src/http.c +++ b/src/http.c @@ -62,14 +62,16 @@ check_auth(struct lws *wsi, struct pss_http *pss) { } void access_log(struct lws *wsi, const char *path) { - char name[100], rip[50]; + char rip[50]; + #if LWS_LIBRARY_VERSION_MAJOR >=2 && LWS_LIBRARY_VERSION_MINOR >=4 struct lws *n_wsi = lws_get_network_wsi(wsi); #else struct lws *n_wsi = wsi; #endif - lws_get_peer_addresses(wsi, lws_get_socket_fd(n_wsi), name, sizeof(name), rip, sizeof(rip)); - lwsl_notice("HTTP %s - %s (%s)\n", path, rip, name); + + lws_get_peer_simple(wsi, rip, sizeof(rip)); + lwsl_notice("HTTP %s - %s\n", path, rip); } int