3 ms·
Can someone say what method Nginx uses to pass file descriptors from the listening or master socket to the worker? Does the Nginx master proc process accept()
by bogomipz 6y ago
Can someone say what method Nginx uses to pass file descriptors from the listening or master socket to the worker? Does the Nginx master proc process accept() new connection and use sendmsg() with SCM_RIGHTS to send those new connections to worker processes?
- thamer 6y agoSee `ngx_write_channel` in `ngx_channel.c`[1]: cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int)); cmsg.cm.cmsg_level = SOL_SOCKET; cmsg.cm.cmsg_type = SCM_RIGHTS; [...] ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int)); [...] n = sendmsg(s, &msg, 0); edit: This article[2] also explains the way the master process sends commands to its workers. [1] https://github.com/nginx/nginx/blob/2a81e0556611188a1b9b3e1240a06928dcebc1a2/src/os/unix/ngx_channel.c#L41 https://github.com/nginx/nginx/blob/2a81e0556611188a1b9b3e12... [2] https://titanwolf.org/Network/Articles/Article?AID=6fb184f9-e06b-4b9a-bcf3-a62ce22cdd53#gsc.tab=0 https://titanwolf.org/Network/Articles/Article?AID=6fb184f9-...
- bogomipz 6y agoAh thanks, this second link is really great analysis of that part of the code base. Cheers!