Mochiweb Long Survey - How to determine if a client is canceling a request?

I have a basic mochiweb poll loop that looks like this, except that it does other things instead of printing to the console and ultimately returns:

blah() -> io:format("Blah") blah() loop(Req) -> PathParts = string:tokens(Req:get(path), "/") case PathParts of ["poll"] -> blah() 

This works fine until the client aborts their request. For example, if the client window is closed, this process continues to run indefinitely.

I would like to know if there is an option in mochiweb start () or perhaps something else that I forgot that mochiweb will automatically terminate this process or at least send a client abort message. Any ideas?

+4
source share
1 answer

It looks like one solution sets up another process to call gen_tcp:recv(Req:get(socket), 0, 1) and looks for the result {error, closed} , and then kills the polling process if it is received ... Not sure that it is optimal.

0
source

Source: https://habr.com/ru/post/1313576/


All Articles