Hello!
On Tue, Nov 25, 2014 at 1:36 PM, Nathan Eloe wrote:
>
> How should I handle r->main->count? Should I be decrementing that at the
> end of my zmq functionality?
Check out all those nginx upstream modules like ngx_proxy,
ngx_drizzle, and ngx_postgres on how to handle it.
The ngx_echo module can be a good example as well due to its
simplicity. ngx_lua is the best example because it has way more
advanced usage of the nginx core.
The rule of thumb is as follows:
1. increment r->main->count yourself when you do not want to complete
the whole request but the request would be completed otherwise.
2. use ngx_http_finalize_request to decrement r->main->count
automatically and destroy the current request if the counter reaches
zero (the last time you should call ngx_http_finalize_request with
NGX_OK or some error codes).
> I have not seen that in any example plugins I
> was examining.
Maybe it's just that you're looking at the wrong ones.
> Also, what is the correct/accepted way of cleaning up the
> upstream connection?
It is complicated due to various cases you need to consider. Generally
ngx_http_upstream is a good example. ngx_lua module's cosocket
implementation can also be an excellent example.
> I have been unable to find any documentation or
> suggestions on how to do this.
>
My personal suggestion is to avoid writing nginx C modules wherever
you can. Try sticking with existing mature nginx C modules, especially
ngx_lua, to fit your use cases. It's hard to get nontrivial nginx C
modules right and that was also why we have been working so hard on
ngx_lua to save our own troubles (and also many others').
Regards,
-agentzh