Skip to content

Commit

Permalink
add unix_sockets_posix module to build system and fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ahedberg committed Mar 18, 2016
1 parent 80d6b12 commit 43df295
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 31 deletions.
9 changes: 9 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ cc_library(
"src/core/iomgr/timer.h",
"src/core/iomgr/timer_heap.h",
"src/core/iomgr/udp_server.h",
"src/core/iomgr/unix_sockets_posix.h",
"src/core/iomgr/wakeup_fd_pipe.h",
"src/core/iomgr/wakeup_fd_posix.h",
"src/core/iomgr/workqueue.h",
Expand Down Expand Up @@ -361,6 +362,8 @@ cc_library(
"src/core/iomgr/timer.c",
"src/core/iomgr/timer_heap.c",
"src/core/iomgr/udp_server.c",
"src/core/iomgr/unix_sockets_posix.c",
"src/core/iomgr/unix_sockets_posix_noop.c",
"src/core/iomgr/wakeup_fd_eventfd.c",
"src/core/iomgr/wakeup_fd_nospecial.c",
"src/core/iomgr/wakeup_fd_pipe.c",
Expand Down Expand Up @@ -551,6 +554,7 @@ cc_library(
"src/core/iomgr/timer.h",
"src/core/iomgr/timer_heap.h",
"src/core/iomgr/udp_server.h",
"src/core/iomgr/unix_sockets_posix.h",
"src/core/iomgr/wakeup_fd_pipe.h",
"src/core/iomgr/wakeup_fd_posix.h",
"src/core/iomgr/workqueue.h",
Expand Down Expand Up @@ -678,6 +682,8 @@ cc_library(
"src/core/iomgr/timer.c",
"src/core/iomgr/timer_heap.c",
"src/core/iomgr/udp_server.c",
"src/core/iomgr/unix_sockets_posix.c",
"src/core/iomgr/unix_sockets_posix_noop.c",
"src/core/iomgr/wakeup_fd_eventfd.c",
"src/core/iomgr/wakeup_fd_nospecial.c",
"src/core/iomgr/wakeup_fd_pipe.c",
Expand Down Expand Up @@ -1339,6 +1345,8 @@ objc_library(
"src/core/iomgr/timer.c",
"src/core/iomgr/timer_heap.c",
"src/core/iomgr/udp_server.c",
"src/core/iomgr/unix_sockets_posix.c",
"src/core/iomgr/unix_sockets_posix_noop.c",
"src/core/iomgr/wakeup_fd_eventfd.c",
"src/core/iomgr/wakeup_fd_nospecial.c",
"src/core/iomgr/wakeup_fd_pipe.c",
Expand Down Expand Up @@ -1510,6 +1518,7 @@ objc_library(
"src/core/iomgr/timer.h",
"src/core/iomgr/timer_heap.h",
"src/core/iomgr/udp_server.h",
"src/core/iomgr/unix_sockets_posix.h",
"src/core/iomgr/wakeup_fd_pipe.h",
"src/core/iomgr/wakeup_fd_posix.h",
"src/core/iomgr/workqueue.h",
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,8 @@ LIBGRPC_SRC = \
src/core/iomgr/timer.c \
src/core/iomgr/timer_heap.c \
src/core/iomgr/udp_server.c \
src/core/iomgr/unix_sockets_posix.c \
src/core/iomgr/unix_sockets_posix_noop.c \
src/core/iomgr/wakeup_fd_eventfd.c \
src/core/iomgr/wakeup_fd_nospecial.c \
src/core/iomgr/wakeup_fd_pipe.c \
Expand Down Expand Up @@ -2744,6 +2746,8 @@ LIBGRPC_UNSECURE_SRC = \
src/core/iomgr/timer.c \
src/core/iomgr/timer_heap.c \
src/core/iomgr/udp_server.c \
src/core/iomgr/unix_sockets_posix.c \
src/core/iomgr/unix_sockets_posix_noop.c \
src/core/iomgr/wakeup_fd_eventfd.c \
src/core/iomgr/wakeup_fd_nospecial.c \
src/core/iomgr/wakeup_fd_pipe.c \
Expand Down
2 changes: 2 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@
'src/core/iomgr/timer.c',
'src/core/iomgr/timer_heap.c',
'src/core/iomgr/udp_server.c',
'src/core/iomgr/unix_sockets_posix.c',
'src/core/iomgr/unix_sockets_posix_noop.c',
'src/core/iomgr/wakeup_fd_eventfd.c',
'src/core/iomgr/wakeup_fd_nospecial.c',
'src/core/iomgr/wakeup_fd_pipe.c',
Expand Down
3 changes: 3 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ filegroups:
- src/core/iomgr/timer.h
- src/core/iomgr/timer_heap.h
- src/core/iomgr/udp_server.h
- src/core/iomgr/unix_sockets_posix.h
- src/core/iomgr/wakeup_fd_pipe.h
- src/core/iomgr/wakeup_fd_posix.h
- src/core/iomgr/workqueue.h
Expand Down Expand Up @@ -430,6 +431,8 @@ filegroups:
- src/core/iomgr/timer.c
- src/core/iomgr/timer_heap.c
- src/core/iomgr/udp_server.c
- src/core/iomgr/unix_sockets_posix.c
- src/core/iomgr/unix_sockets_posix_noop.c
- src/core/iomgr/wakeup_fd_eventfd.c
- src/core/iomgr/wakeup_fd_nospecial.c
- src/core/iomgr/wakeup_fd_pipe.c
Expand Down
2 changes: 2 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ if test "$PHP_GRPC" != "no"; then
src/core/iomgr/timer.c \
src/core/iomgr/timer_heap.c \
src/core/iomgr/udp_server.c \
src/core/iomgr/unix_sockets_posix.c \
src/core/iomgr/unix_sockets_posix_noop.c \
src/core/iomgr/wakeup_fd_eventfd.c \
src/core/iomgr/wakeup_fd_nospecial.c \
src/core/iomgr/wakeup_fd_pipe.c \
Expand Down
4 changes: 4 additions & 0 deletions gRPC.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Pod::Spec.new do |s|
'src/core/iomgr/timer.h',
'src/core/iomgr/timer_heap.h',
'src/core/iomgr/udp_server.h',
'src/core/iomgr/unix_sockets_posix.h',
'src/core/iomgr/wakeup_fd_pipe.h',
'src/core/iomgr/wakeup_fd_posix.h',
'src/core/iomgr/workqueue.h',
Expand Down Expand Up @@ -378,6 +379,8 @@ Pod::Spec.new do |s|
'src/core/iomgr/timer.c',
'src/core/iomgr/timer_heap.c',
'src/core/iomgr/udp_server.c',
'src/core/iomgr/unix_sockets_posix.c',
'src/core/iomgr/unix_sockets_posix_noop.c',
'src/core/iomgr/wakeup_fd_eventfd.c',
'src/core/iomgr/wakeup_fd_nospecial.c',
'src/core/iomgr/wakeup_fd_pipe.c',
Expand Down Expand Up @@ -546,6 +549,7 @@ Pod::Spec.new do |s|
'src/core/iomgr/timer.h',
'src/core/iomgr/timer_heap.h',
'src/core/iomgr/udp_server.h',
'src/core/iomgr/unix_sockets_posix.h',
'src/core/iomgr/wakeup_fd_pipe.h',
'src/core/iomgr/wakeup_fd_posix.h',
'src/core/iomgr/workqueue.h',
Expand Down
3 changes: 3 additions & 0 deletions grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/iomgr/timer.h )
s.files += %w( src/core/iomgr/timer_heap.h )
s.files += %w( src/core/iomgr/udp_server.h )
s.files += %w( src/core/iomgr/unix_sockets_posix.h )
s.files += %w( src/core/iomgr/wakeup_fd_pipe.h )
s.files += %w( src/core/iomgr/wakeup_fd_posix.h )
s.files += %w( src/core/iomgr/workqueue.h )
Expand Down Expand Up @@ -361,6 +362,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/iomgr/timer.c )
s.files += %w( src/core/iomgr/timer_heap.c )
s.files += %w( src/core/iomgr/udp_server.c )
s.files += %w( src/core/iomgr/unix_sockets_posix.c )
s.files += %w( src/core/iomgr/unix_sockets_posix_noop.c )
s.files += %w( src/core/iomgr/wakeup_fd_eventfd.c )
s.files += %w( src/core/iomgr/wakeup_fd_nospecial.c )
s.files += %w( src/core/iomgr/wakeup_fd_pipe.c )
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"src/core/iomgr/timer.h",
"src/core/iomgr/timer_heap.h",
"src/core/iomgr/udp_server.h",
"src/core/iomgr/unix_sockets_posix.h",
"src/core/iomgr/wakeup_fd_pipe.h",
"src/core/iomgr/wakeup_fd_posix.h",
"src/core/iomgr/workqueue.h",
Expand Down Expand Up @@ -305,6 +306,8 @@
"src/core/iomgr/timer.c",
"src/core/iomgr/timer_heap.c",
"src/core/iomgr/udp_server.c",
"src/core/iomgr/unix_sockets_posix.c",
"src/core/iomgr/unix_sockets_posix_noop.c",
"src/core/iomgr/wakeup_fd_eventfd.c",
"src/core/iomgr/wakeup_fd_nospecial.c",
"src/core/iomgr/wakeup_fd_pipe.c",
Expand Down
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
<file baseinstalldir="/" name="src/core/iomgr/timer.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/timer_heap.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/udp_server.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/unix_sockets_posix.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/wakeup_fd_pipe.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/wakeup_fd_posix.h" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/workqueue.h" role="src" />
Expand Down Expand Up @@ -365,6 +366,8 @@
<file baseinstalldir="/" name="src/core/iomgr/timer.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/timer_heap.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/udp_server.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/unix_sockets_posix.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/unix_sockets_posix_noop.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/wakeup_fd_eventfd.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/wakeup_fd_nospecial.c" role="src" />
<file baseinstalldir="/" name="src/core/iomgr/wakeup_fd_pipe.c" role="src" />
Expand Down
2 changes: 1 addition & 1 deletion src/core/iomgr/resolve_address_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "src/core/iomgr/executor.h"
#include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/iomgr/unix_posix_sockets.h"
#include "src/core/iomgr/unix_sockets_posix.h"
#include "src/core/support/block_annotate.h"
#include "src/core/support/string.h"

Expand Down
2 changes: 1 addition & 1 deletion src/core/iomgr/sockaddr_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int grpc_sockaddr_get_port(const struct sockaddr *addr) {
case AF_INET6:
return ntohs(((struct sockaddr_in6 *)addr)->sin6_port);
default:
if (grpc_is_unix_socket(addr->sa_family)) {
if (grpc_is_unix_socket(addr)) {
return 1;
}
gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_get_port",
Expand Down
4 changes: 2 additions & 2 deletions src/core/iomgr/tcp_client_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "src/core/iomgr/socket_utils_posix.h"
#include "src/core/iomgr/tcp_posix.h"
#include "src/core/iomgr/timer.h"
#include "src/core/iomgr/unix_sockets_posix.h"
#include "src/core/support/string.h"

extern int grpc_tcp_trace;
Expand All @@ -77,8 +78,7 @@ static int prepare_socket(const struct sockaddr *addr, int fd) {
}

if (!grpc_set_socket_nonblocking(fd, 1) || !grpc_set_socket_cloexec(fd, 1) ||
(!grpc_is_unix_socket(addr->sa_family) &&
!grpc_set_socket_low_latency(fd, 1)) ||
(!grpc_is_unix_socket(addr) && !grpc_set_socket_low_latency(fd, 1)) ||
!grpc_set_socket_no_sigpipe_if_possible(fd)) {
gpr_log(GPR_ERROR, "Unable to configure socket %d: %s", fd,
strerror(errno));
Expand Down
18 changes: 9 additions & 9 deletions src/core/iomgr/unix_sockets_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#ifdef GPR_HAVE_UNIX_SOCKET

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/un.h>

#include <grpc/support/alloc.h>
Expand All @@ -47,7 +48,7 @@ void grpc_create_socketpair_if_unix(int sv[2]) {
grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char* name) {
struct sockaddr_un *un;

addrs = gpr_malloc(sizeof(grpc_resolved_addresses));
grpc_resolved_addresses *addrs = gpr_malloc(sizeof(grpc_resolved_addresses));
addrs->naddrs = 1;
addrs->addrs = gpr_malloc(sizeof(grpc_resolved_address));
un = (struct sockaddr_un *)addrs->addrs->addr;
Expand All @@ -57,11 +58,11 @@ grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char* name) {
return addrs;
}

int grpc_is_unix_socket(sa_family_t addr_family) {
return addr_family == AF_UNIX;
int grpc_is_unix_socket(const struct sockaddr *addr) {
return addr->sa_family == AF_UNIX;
}

static void unlink_if_unix_domain_socket(const struct sockaddr *addr) {
void unlink_if_unix_domain_socket(const struct sockaddr *addr) {
if (addr->sa_family != AF_UNIX) {
return;
}
Expand All @@ -73,8 +74,7 @@ static void unlink_if_unix_domain_socket(const struct sockaddr *addr) {
}
}

static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr,
size_t *len) {
int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) {
struct sockaddr_un *un = (struct sockaddr_un *)addr;

un->sun_family = AF_UNIX;
Expand All @@ -84,12 +84,12 @@ static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr,
return 1;
}

static char *unix_get_default_authority(grpc_resolver_factory *factory,
grpc_uri *uri) {
char *unix_get_default_authority(grpc_resolver_factory *factory,
grpc_uri *uri) {
return gpr_strdup("localhost");
}

char *grpc_sockaddr_to_uri_unix_if_possible(struct sockaddr *addr) {
char *grpc_sockaddr_to_uri_unix_if_possible(const struct sockaddr *addr) {
if (addr->sa_family != AF_UNIX) {
return NULL;
}
Expand Down
15 changes: 6 additions & 9 deletions src/core/iomgr/unix_sockets_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,22 @@
#include <grpc/support/string_util.h>

#include "src/core/client_config/resolver_factory.h"
#include "src/core/client_config/uri_parser.h";
#include "src/core/client_config/uri_parser.h"
#include "src/core/iomgr/resolve_address.h"

void grpc_create_socketpair_if_unix(int sv[2]);

grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char* name);

int grpc_is_unix_socket(sa_family_t addr_family);
int grpc_is_unix_socket(const struct sockaddr *addr);

static void unlink_if_unix_domain_socket(const struct sockaddr *addr);
void unlink_if_unix_domain_socket(const struct sockaddr *addr);

static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr,
size_t *len);
int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len);

static char *unix_get_default_authority(grpc_resolver_factory *factory,
grpc_uri *uri);
char *unix_get_default_authority(grpc_resolver_factory *factory, grpc_uri *uri);

char *grpc_sockaddr_to_uri_unix_if_possible(char **strp,
const char *format, ...);
char *grpc_sockaddr_to_uri_unix_if_possible(const struct sockaddr *addr);

#endif
#endif /* GRPC_INTERNAL_CORE_IOMGR_UNIX_SOCKETS_POSIX_H */
23 changes: 14 additions & 9 deletions src/core/iomgr/unix_sockets_posix_noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,31 @@

#include "src/core/iomgr/unix_sockets_posix.h"

#ifdef GPR_POSIX_SOCKET

void grpc_create_socketpair_if_unix(int sv[2]) {}

void grpc_resolve_unix_domain_address(const char* name) {
grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char* name) {
return NULL;
}

int grpc_is_unix_socket(sa_family_t addr_family) {
int grpc_is_unix_socket(const struct sockaddr *addr) {
return false;
}

static void unlink_if_unix_domain_socket(const struct sockaddr *addr) {}
void unlink_if_unix_domain_socket(const struct sockaddr *addr) {}

static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr,
size_t *len) {}
int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) {
return 0;
}

static char *unix_get_default_authority(grpc_resolver_factory *factory,
grpc_uri *uri) {}
char *unix_get_default_authority(grpc_resolver_factory *factory,
grpc_uri *uri) {
return NULL;
}

char *grpc_sockaddr_to_uri_unix_if_possible(struct sockaddr *addr) {
return NULL;
char *grpc_sockaddr_to_uri_unix_if_possible(const struct sockaddr *addr) {
return NULL;
}

#endif
2 changes: 2 additions & 0 deletions src/python/grpcio/grpc_core_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
'src/core/iomgr/timer.c',
'src/core/iomgr/timer_heap.c',
'src/core/iomgr/udp_server.c',
'src/core/iomgr/unix_sockets_posix.c',
'src/core/iomgr/unix_sockets_posix_noop.c',
'src/core/iomgr/wakeup_fd_eventfd.c',
'src/core/iomgr/wakeup_fd_nospecial.c',
'src/core/iomgr/wakeup_fd_pipe.c',
Expand Down
3 changes: 3 additions & 0 deletions tools/doxygen/Doxyfile.core.internal
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ src/core/iomgr/time_averaged_stats.h \
src/core/iomgr/timer.h \
src/core/iomgr/timer_heap.h \
src/core/iomgr/udp_server.h \
src/core/iomgr/unix_sockets_posix.h \
src/core/iomgr/wakeup_fd_pipe.h \
src/core/iomgr/wakeup_fd_posix.h \
src/core/iomgr/workqueue.h \
Expand Down Expand Up @@ -979,6 +980,8 @@ src/core/iomgr/time_averaged_stats.c \
src/core/iomgr/timer.c \
src/core/iomgr/timer_heap.c \
src/core/iomgr/udp_server.c \
src/core/iomgr/unix_sockets_posix.c \
src/core/iomgr/unix_sockets_posix_noop.c \
src/core/iomgr/wakeup_fd_eventfd.c \
src/core/iomgr/wakeup_fd_nospecial.c \
src/core/iomgr/wakeup_fd_pipe.c \
Expand Down
Loading

0 comments on commit 43df295

Please sign in to comment.