[Libwebsockets] 回复: 回复: 答复: A question about libwebsockets dns resolve

Andy Green andy at warmcat.com
Mon May 11 10:53:00 CEST 2020

On 5/11/20 7:56 AM, o_O凌雲 wrote:
> Hi,
>       I have made some changes to lws to limit wait time , and I make 
> mychanges.diff as your said. please help to review my code. thanks. I 
> add "PENDING_TIMEOUT_DNS_RESOLVER_TRY" to limit wait time. and using 
> "onevalid.bogus.warmcat.com" to test.see more in attachments.
>       huangkaicheng.

Thanks.  I could look at it and quickly see what's changed... basically 
what you're trying to do in there is not unreasonable.  But there's a 
lot of added / cut-and-pasted code introduced, the client connection 
path has already become overcomplicated and needs refactoring and 
cleaning rather than more code piled on.

I made a different patch that repurposes the timeout sul in the wsi to 
protect the connect similar to the lws_set_timeout() approach.  But 
instead of using the normal timeout flow, since it's pre connect() it 
sets a different callback that can directly call into connect3 and go to 
the next DNS result.  I checked this with blackhole.bogus.warmcat.com 
( blackhole twice and one correct IP) and 
onevalid.bogus.warmcat.com (some 127.0.0.x and one correct IP) and he 
seems to act well.  For he waits for 20s (the default timeout in 
the context info) and then tries the next.

$ ./bin/lws-minimal-http-client --server onevalid.bogus.warmcat.com -d 
1039 -m
$ ./bin/lws-minimal-http-client --server blackhole.bogus.warmcat.com -d 
1039 -m


Please give it a try.


More information about the Libwebsockets mailing list