Welcome! Log In Create A New Profile

Advanced

Re: [ Module development - Socket ]

Maxim Dounin
April 11, 2017 10:12AM
Hello!

On Tue, Apr 11, 2017 at 04:28:54AM -0400, comput3rz wrote:

> Hi,
>
> I need to develop a module which make a connexion with an external server. I
> tried to use simple TCP sockets available
>
> in the "sys/socket.h" (Linux) library but it appears that it wasn't a good
> idea as nothing was working correctly.
>
> Then, I searched in the source code keywords like "connection, socket" and I
> found the "ngx_connection.h" file which I
>
> suppose, is the API to be used if I want to do an external connection.
> Looking on the web for tutorials/resources using
>
> this API I found nothing more than unanswered stackoverflow threads...
>
> I'm pretty sure that including "sys/socket.h" into nginx is not the good
> solution as it makes ugly code and broke the pipes
>
> system which makes nginx so fast, could you please help me to find a
> solution ?

Try looking into src/http/ngx_http_upstream.c for the upstream
module implementation, the base module used by proxy and other
modules which talk to backend servers. Basically, you are
expected to use the ngx_event_connect_peer() function to connect
to an external server, and then use appropriate event handling.

Additional and probably simplier examples can be found in the
mail module (src/mail/ngx_mail_auth_http_module.c,
src/mail/ngx_mail_proxy_module.c), the stream module
(src/stream/ngx_stream_proxy_module.c), as well as in OCSP
stapling code (src/event/ngx_event_openssl_stapling.c).

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

[ Module development - Socket ]

comput3rz April 11, 2017 04:28AM

Re: [ Module development - Socket ]

Maxim Dounin April 11, 2017 10:12AM

Re: [ Module development - Socket ]

comput3rz April 11, 2017 10:19AM

Re: [ Module development - Socket ]

comput3rz April 13, 2017 05:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 317
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready