Hi Romaboy,
It is tricky getting into both the nginx code and the open-resty code.
I did not have enough time to do the full tcpsock:accept/listen() solution :(
I came up with a solution for my exact use-case: a unique port per worker.
This is accomplished by a new lua function called unique_socket_per_worker(path) which replaces the unix-socket specified by 'path' with a unique socket per worker (i.e. path_$(PID)).
This is only avaialble in my fork: https://github.com/JakSprats/lua-nginx-module
The function is called unique_socket_per_worker(path) and is defined in this file: https://github.com/JakSprats/lua-nginx-module/blob/master/src/ngx_http_lua_unique_socket_per_worker.c
This code is experimental so use with caution. I will be adding tests to it and will discuss w/ agentzh if I should make a PR.
Read thru the C file, the same approach could be used to implement sock:accept/listen, but there is still a lot of server/stream initialization code needed, as well as openresty tcpsock code needed.
Hope this helps
- Russ