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>
This commit is contained in:
Xiang Dai
2019-09-03 13:53:54 +08:00
committed by Shuanglei Tao
parent 43c5aedd35
commit 94817b4eb3

View File

@@ -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