|  | @@ -52,9 +52,6 @@
 | 
	
		
			
				|  |  |  #include <sys/socket.h>
 | 
	
		
			
				|  |  |  #include <sys/stat.h>
 | 
	
		
			
				|  |  |  #include <sys/types.h>
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  | -#include <sys/un.h>
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  |  #include <unistd.h>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #include "src/core/iomgr/pollset_posix.h"
 | 
	
	
		
			
				|  | @@ -62,6 +59,7 @@
 | 
	
		
			
				|  |  |  #include "src/core/iomgr/sockaddr_utils.h"
 | 
	
		
			
				|  |  |  #include "src/core/iomgr/socket_utils_posix.h"
 | 
	
		
			
				|  |  |  #include "src/core/iomgr/tcp_posix.h"
 | 
	
		
			
				|  |  | +#include "src/core/iomgr/unix_sockets_posix.h"
 | 
	
		
			
				|  |  |  #include "src/core/support/string.h"
 | 
	
		
			
				|  |  |  #include <grpc/support/alloc.h>
 | 
	
		
			
				|  |  |  #include <grpc/support/log.h>
 | 
	
	
		
			
				|  | @@ -83,9 +81,6 @@ struct grpc_tcp_listener {
 | 
	
		
			
				|  |  |    union {
 | 
	
		
			
				|  |  |      uint8_t untyped[GRPC_MAX_SOCKADDR_SIZE];
 | 
	
		
			
				|  |  |      struct sockaddr sockaddr;
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  | -    struct sockaddr_un un;
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  |    } addr;
 | 
	
		
			
				|  |  |    size_t addr_len;
 | 
	
		
			
				|  |  |    int port;
 | 
	
	
		
			
				|  | @@ -102,16 +97,6 @@ struct grpc_tcp_listener {
 | 
	
		
			
				|  |  |    int is_sibling;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  | -static void unlink_if_unix_domain_socket(const struct sockaddr_un *un) {
 | 
	
		
			
				|  |  | -  struct stat st;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) {
 | 
	
		
			
				|  |  | -    unlink(un->sun_path);
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  /* the overall server */
 | 
	
		
			
				|  |  |  struct grpc_tcp_server {
 | 
	
		
			
				|  |  |    gpr_refcount refs;
 | 
	
	
		
			
				|  | @@ -209,11 +194,7 @@ static void deactivated_all_ports(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
 | 
	
		
			
				|  |  |    if (s->head) {
 | 
	
		
			
				|  |  |      grpc_tcp_listener *sp;
 | 
	
		
			
				|  |  |      for (sp = s->head; sp; sp = sp->next) {
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  | -      if (sp->addr.sockaddr.sa_family == AF_UNIX) {
 | 
	
		
			
				|  |  | -        unlink_if_unix_domain_socket(&sp->addr.un);
 | 
	
		
			
				|  |  | -      }
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  | +      unlink_if_unix_domain_socket(&sp->addr.sockaddr);
 | 
	
		
			
				|  |  |        sp->destroyed_closure.cb = destroyed_port;
 | 
	
		
			
				|  |  |        sp->destroyed_closure.cb_arg = s;
 | 
	
		
			
				|  |  |        grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL,
 | 
	
	
		
			
				|  | @@ -288,25 +269,15 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
 | 
	
		
			
				|  |  |      goto error;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  |    if (!grpc_set_socket_nonblocking(fd, 1) || !grpc_set_socket_cloexec(fd, 1) ||
 | 
	
		
			
				|  |  | -      (addr->sa_family != AF_UNIX && (!grpc_set_socket_low_latency(fd, 1) ||
 | 
	
		
			
				|  |  | -                                      !grpc_set_socket_reuse_addr(fd, 1))) ||
 | 
	
		
			
				|  |  | +      (!grpc_is_unix_socket(addr) &&
 | 
	
		
			
				|  |  | +       (!grpc_set_socket_low_latency(fd, 1) ||
 | 
	
		
			
				|  |  | +        !grpc_set_socket_reuse_addr(fd, 1))) ||
 | 
	
		
			
				|  |  |        !grpc_set_socket_no_sigpipe_if_possible(fd)) {
 | 
	
		
			
				|  |  |      gpr_log(GPR_ERROR, "Unable to configure socket %d: %s", fd,
 | 
	
		
			
				|  |  |              strerror(errno));
 | 
	
		
			
				|  |  |      goto error;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -#else
 | 
	
		
			
				|  |  | -  if (!grpc_set_socket_nonblocking(fd, 1) || !grpc_set_socket_cloexec(fd, 1) ||
 | 
	
		
			
				|  |  | -      !grpc_set_socket_low_latency(fd, 1) ||
 | 
	
		
			
				|  |  | -      !grpc_set_socket_reuse_addr(fd, 1) ||
 | 
	
		
			
				|  |  | -      !grpc_set_socket_no_sigpipe_if_possible(fd)) {
 | 
	
		
			
				|  |  | -    gpr_log(GPR_ERROR, "Unable to configure socket %d: %s", fd,
 | 
	
		
			
				|  |  | -            strerror(errno));
 | 
	
		
			
				|  |  | -    goto error;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    GPR_ASSERT(addr_len < ~(socklen_t)0);
 | 
	
		
			
				|  |  |    if (bind(fd, addr, (socklen_t)addr_len) < 0) {
 | 
	
	
		
			
				|  | @@ -470,11 +441,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
 | 
	
		
			
				|  |  |    if (s->tail != NULL) {
 | 
	
		
			
				|  |  |      port_index = s->tail->port_index + 1;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -#ifdef GPR_HAVE_UNIX_SOCKET
 | 
	
		
			
				|  |  | -  if (((struct sockaddr *)addr)->sa_family == AF_UNIX) {
 | 
	
		
			
				|  |  | -    unlink_if_unix_domain_socket(addr);
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -#endif
 | 
	
		
			
				|  |  | +  unlink_if_unix_domain_socket((struct sockaddr *)addr);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    /* Check if this is a wildcard port, and if so, try to keep the port the same
 | 
	
		
			
				|  |  |       as some previously created listener. */
 |