custom data pointer in struct ngx_connection_s

Pavel Balaev mail at void.so
Fri Mar 24 11:09:47 UTC 2017


Hello.

I'm trying to write module for nginx. My module needs to hold some
arbitrary data while connection is alive (keep-alive connection). The
memory for void *ctx is allocated from r->commection->pool. The problem
is that I don't know where to store this pointer. I added void *ctx to
struct ngx_connection_s and use it like this:

ctx = ngx_pcalloc(r->connection->pool, ...
r->connection->ctx = ctx;

and everything works as I needed, but I tnink that this solution may be
wrong.


More information about the nginx-devel mailing list