Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
jobs: Fix callsync hanging
[src/app-framework-binder.git]
/
src
/
afb-socket.c
diff --git
a/src/afb-socket.c
b/src/afb-socket.c
index
ebbc58e
..
cf788de
100644
(file)
--- a/
src/afb-socket.c
+++ b/
src/afb-socket.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2015-201
8
"IoT.bzh"
+ * Copyright (C) 2015-201
9
"IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@
-31,7
+31,8
@@
#include "afb-fdev.h"
#include "afb-socket.h"
#include "afb-fdev.h"
#include "afb-socket.h"
-#include "afb-systemd.h"
+
+#include "systemd.h"
#include "fdev.h"
#include "verbose.h"
#include "fdev.h"
#include "verbose.h"
@@
-158,14
+159,14
@@
static int open_unix(const char *spec, int server)
*
* @return the file descriptor number of the socket or -1 in case of error
*/
*
* @return the file descriptor number of the socket or -1 in case of error
*/
-static int open_tcp(const char *spec, int server)
+static int open_tcp(const char *spec, int server
, int reuseaddr
)
{
int rc, fd;
const char *service, *host, *tail;
struct addrinfo hint, *rai, *iai;
/* scan the uri */
{
int rc, fd;
const char *service, *host, *tail;
struct addrinfo hint, *rai, *iai;
/* scan the uri */
- tail = strchr(spec, '/');
+ tail = strchr
nul
(spec, '/');
service = strchr(spec, ':');
if (tail == NULL || service == NULL || tail < service) {
errno = EINVAL;
service = strchr(spec, ':');
if (tail == NULL || service == NULL || tail < service) {
errno = EINVAL;
@@
-178,6
+179,11
@@
static int open_tcp(const char *spec, int server)
memset(&hint, 0, sizeof hint);
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_STREAM;
memset(&hint, 0, sizeof hint);
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_STREAM;
+ if (server) {
+ hint.ai_flags = AI_PASSIVE;
+ if (host[0] == 0 || (host[0] == '*' && host[1] == 0))
+ host = NULL;
+ }
rc = getaddrinfo(host, service, &hint, &rai);
if (rc != 0) {
errno = EINVAL;
rc = getaddrinfo(host, service, &hint, &rai);
if (rc != 0) {
errno = EINVAL;
@@
-190,6
+196,10
@@
static int open_tcp(const char *spec, int server)
fd = socket(iai->ai_family, iai->ai_socktype, iai->ai_protocol);
if (fd >= 0) {
if (server) {
fd = socket(iai->ai_family, iai->ai_socktype, iai->ai_protocol);
if (fd >= 0) {
if (server) {
+ if (reuseaddr) {
+ rc = 1;
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc);
+ }
rc = bind(fd, iai->ai_addr, iai->ai_addrlen);
} else {
rc = connect(fd, iai->ai_addr, iai->ai_addrlen);
rc = bind(fd, iai->ai_addr, iai->ai_addrlen);
} else {
rc = connect(fd, iai->ai_addr, iai->ai_addrlen);
@@
-217,9
+227,9
@@
static int open_systemd(const char *spec)
{
#if defined(NO_SYSTEMD_ACTIVATION)
errno = EAFNOSUPPORT;
{
#if defined(NO_SYSTEMD_ACTIVATION)
errno = EAFNOSUPPORT;
-
fd =
-1;
+
return
-1;
#else
#else
- return
afb_
systemd_fds_for(spec);
+ return systemd_fds_for(spec);
#endif
}
#endif
}
@@
-262,7
+272,7
@@
static struct entry *get_entry(const char *uri, int *offset)
*/
static int open_uri(const char *uri, int server)
{
*/
static int open_uri(const char *uri, int server)
{
- int fd,
rc,
offset;
+ int fd, offset;
struct entry *e;
const char *api;
struct entry *e;
const char *api;
@@
-281,7
+291,7
@@
static int open_uri(const char *uri, int server)
fd = open_unix(uri, server);
break;
case Type_Inet:
fd = open_unix(uri, server);
break;
case Type_Inet:
- fd = open_tcp(uri, server);
+ fd = open_tcp(uri, server
, !e->noreuseaddr
);
break;
case Type_Systemd:
if (server)
break;
case Type_Systemd:
if (server)
@@
-303,10
+313,6
@@
static int open_uri(const char *uri, int server)
fcntl(fd, F_SETFD, FD_CLOEXEC);
fcntl(fd, F_SETFL, O_NONBLOCK);
if (server) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
fcntl(fd, F_SETFL, O_NONBLOCK);
if (server) {
- if (!e->noreuseaddr) {
- rc = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc);
- }
if (!e->nolisten)
listen(fd, BACKLOG);
}
if (!e->nolisten)
listen(fd, BACKLOG);
}
@@
-366,9
+372,11
@@
const char *afb_socket_api(const char *uri)
{
int offset;
const char *api;
{
int offset;
const char *api;
+ struct entry *entry;
- get_entry(uri, &offset);
+
entry =
get_entry(uri, &offset);
uri += offset;
uri += offset;
+ uri += (entry->type == Type_Unix && *uri == '@');
api = strstr(uri, as_api);
if (api)
api += sizeof as_api - 1;
api = strstr(uri, as_api);
if (api)
api += sizeof as_api - 1;