mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	socket-server: add tcp support for systemd socket activation
This commit is contained in:
		
							parent
							
								
									006bf0fb34
								
							
						
					
					
						commit
						72aac3ff08
					
				
					 1 changed files with 88 additions and 48 deletions
				
			
		| 
						 | 
				
			
			@ -252,12 +252,30 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
 | 
			
		|||
pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port, bool fallback, const char *tcpwrap_service) {
 | 
			
		||||
    pa_socket_server *ss;
 | 
			
		||||
    int fd = -1;
 | 
			
		||||
    bool activated = false;
 | 
			
		||||
    struct sockaddr_in sa;
 | 
			
		||||
    int on = 1;
 | 
			
		||||
 | 
			
		||||
    pa_assert(m);
 | 
			
		||||
    pa_assert(port);
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_SYSTEMD_DAEMON
 | 
			
		||||
    {
 | 
			
		||||
        int n = sd_listen_fds(0);
 | 
			
		||||
        if (n > 0) {
 | 
			
		||||
            for (int i = 0; i < n; ++i) {
 | 
			
		||||
                if (sd_is_socket_inet(SD_LISTEN_FDS_START + i, AF_INET, SOCK_STREAM, 1, port) > 0) {
 | 
			
		||||
                    fd = SD_LISTEN_FDS_START + i;
 | 
			
		||||
                    activated = true;
 | 
			
		||||
                    pa_log_info("Found socket activation socket for ipv4 in port '%d' \\o/", port);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (fd < 0) {
 | 
			
		||||
        if ((fd = pa_socket_cloexec(PF_INET, SOCK_STREAM, 0)) < 0) {
 | 
			
		||||
            pa_log("socket(PF_INET): %s", pa_cstrerror(errno));
 | 
			
		||||
            goto fail;
 | 
			
		||||
| 
						 | 
				
			
			@ -294,11 +312,13 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
 | 
			
		|||
            pa_log("listen(): %s", pa_cstrerror(errno));
 | 
			
		||||
            goto fail;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pa_assert_se(ss = socket_server_new(m, fd));
 | 
			
		||||
 | 
			
		||||
    ss->type = SOCKET_SERVER_IPV4;
 | 
			
		||||
    ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
 | 
			
		||||
    ss->activated = activated;
 | 
			
		||||
 | 
			
		||||
    return ss;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -313,12 +333,30 @@ fail:
 | 
			
		|||
pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t address[16], uint16_t port, bool fallback, const char *tcpwrap_service) {
 | 
			
		||||
    pa_socket_server *ss;
 | 
			
		||||
    int fd = -1;
 | 
			
		||||
    bool activated = false;
 | 
			
		||||
    struct sockaddr_in6 sa;
 | 
			
		||||
    int on;
 | 
			
		||||
 | 
			
		||||
    pa_assert(m);
 | 
			
		||||
    pa_assert(port > 0);
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_SYSTEMD_DAEMON
 | 
			
		||||
    {
 | 
			
		||||
        int n = sd_listen_fds(0);
 | 
			
		||||
        if (n > 0) {
 | 
			
		||||
            for (int i = 0; i < n; ++i) {
 | 
			
		||||
                if (sd_is_socket_inet(SD_LISTEN_FDS_START + i, AF_INET6, SOCK_STREAM, 1, port) > 0) {
 | 
			
		||||
                    fd = SD_LISTEN_FDS_START + i;
 | 
			
		||||
                    activated = true;
 | 
			
		||||
                    pa_log_info("Found socket activation socket for ipv6 in port '%d' \\o/", port);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (fd < 0) {
 | 
			
		||||
        if ((fd = pa_socket_cloexec(PF_INET6, SOCK_STREAM, 0)) < 0) {
 | 
			
		||||
            pa_log("socket(PF_INET6): %s", pa_cstrerror(errno));
 | 
			
		||||
            goto fail;
 | 
			
		||||
| 
						 | 
				
			
			@ -362,11 +400,13 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
 | 
			
		|||
            pa_log("listen(): %s", pa_cstrerror(errno));
 | 
			
		||||
            goto fail;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pa_assert_se(ss = socket_server_new(m, fd));
 | 
			
		||||
 | 
			
		||||
    ss->type = SOCKET_SERVER_IPV6;
 | 
			
		||||
    ss->tcpwrap_service = pa_xstrdup(tcpwrap_service);
 | 
			
		||||
    ss->activated = activated;
 | 
			
		||||
 | 
			
		||||
    return ss;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue