[ Module development - Socket ]

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[ Module development - Socket ]

S.A.N
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 ?

Regards,

XXX

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273525,273525#msg-273525

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ Module development - Socket ]

Maxim Dounin
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
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ Module development - Socket ]

S.A.N
Thanks Maxim ! =)

I found what I was looking for.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273525,273532#msg-273532

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ Module development - Socket ]

S.A.N
In reply to this post by Maxim Dounin
After reading the source code available  in "ngx_mail_auth_http_module.c"

 trying to figure out how to make a "basic TCP connection" to

a backend server, nothing seems clear. I didn't find any simple pattern

to read/write on a TCP socket, even if there are simple call like

ngx_event_connect_peer() or ngx_close_connection() for connection phase

 and ngx_send|recv / ngx_unix_send|recv / send|recv for reading and writing
on a socket.

How can I setup a basic TCP socket into my handler which will connect / send
/ recv and then

close the connection ?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273525,273598#msg-273598

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...