开发者

How to detect client-terminated connection using FCGI?

开发者 https://www.devze.com 2023-03-19 05:17 出处:网络
I have a FCGI application written in C.We have cases where a client closes an active connection--i.e. leaves the page during page load--which we\'d like to detect within the application, if possible.W

I have a FCGI application written in C. We have cases where a client closes an active connection--i.e. leaves the page during page load--which we'd like to detect within the application, if possible. We have our web server (nginx) configured to close the FCGI connection when the client connection is unexpectedly closed, so my hope is that by looking at the FCGI stream state at the end of the transaction, we might be able to detect a client-initiated closed connection.

My question is: Is it possible to detect this using FCGX_GetError() on the output stream right before calling FCGX_Finish_r() ? If not, how might I trap such a cond开发者_Python百科ition?

I tried asking on the FastCGI mailing list, but it would seem that the list is down.


If data has been transmitted over the socket and a error occurred, FCGX_GetError() will return the errno, you can also detect this using FCGX_PutStr() < 0. libfcgi internally buffers the output stream using a size of 8192 bytes, any remaining buffer is transmitted when FCGX_Finish_r() is called.


You should receive SIGPIPE when the client closes the connection. Generally, it's safe to ignore this signal. But if you need to detect this, just install handler for SIGPIPE.

0

精彩评论

暂无评论...
验证码 换一张
取 消