alibaba/tengine — pull request #296 by chobits (2013-08-07 09:53:11+00:00)
Title: test (kqueue)connection completely in ngx_http_upstream_test_connect()

With NGX_HAVE_KQUEUE option, ngx_http_upstream_test_connect() may return
NGX_OK although the connection isnt established.

Reproduce the problem in os x 10.8.4, let backend server down, then
tengine upstream try to connect and send request to it:

ngx_http_upstream_init_request()
'-> ngx_http_upstream_connect()
'-> ngx_event_connect_peer() returns NGX_AGAIN <<< cannot connect
'-> ..
'-> ngx_http_upstream_send_request()
'-> ngx_http_upstream_test_connect() returns NGX_OK <<< wrong value
'-> ngx_output_chain() returns NGX_AGAIN

With this patch, ngx_http_upstream_test_connect() will call getsockopt
to test connection still after it thinks kqueue connection is ok.

Without this patch, tengine can work well because c->recv() will return
NGX_ERROR when read event timedout expires.

Note that nginx has the same problem.

简单说来就是 让 ngx_http_upstream_test_connect()在认为kqueue连接是正常时，再跑一遍常规测试(getsockopt)