scope reduction, commenting

This commit is contained in:
Christian Grothoff 2020-03-01 13:52:34 +01:00
parent 9ec23c6239
commit 9b688d7cb0
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -287,6 +287,8 @@ TALER_MHD_open_unix_path (const char *unix_path,
"set socket '%s' to mode %o\n", "set socket '%s' to mode %o\n",
unix_path, unix_path,
unix_mode); unix_mode);
/* extract and return actual socket handle from 'nh' */
{ {
int fd; int fd;
@ -315,80 +317,92 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
uint16_t *port) uint16_t *port)
{ {
char *bind_to; char *bind_to;
char *serve_unixpath;
mode_t unixpath_mode;
char port_str[6];
struct addrinfo hints;
struct addrinfo *res;
int ec;
struct GNUNET_NETWORK_Handle *nh; struct GNUNET_NETWORK_Handle *nh;
*port = 0; *port = 0;
if (GNUNET_OK != {
TALER_MHD_parse_config (cfg, char *serve_unixpath;
section, mode_t unixpath_mode;
port,
&serve_unixpath, if (GNUNET_OK !=
&unixpath_mode)) TALER_MHD_parse_config (cfg,
return -1; section,
if (NULL != serve_unixpath) port,
return TALER_MHD_open_unix_path (serve_unixpath, &serve_unixpath,
unixpath_mode); &unixpath_mode))
return -1;
if (NULL != serve_unixpath)
return TALER_MHD_open_unix_path (serve_unixpath,
unixpath_mode);
}
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, GNUNET_CONFIGURATION_get_value_string (cfg,
section, section,
"BIND_TO", "BIND_TO",
&bind_to)) &bind_to))
return -1; /* only set port */ return -1; /* only set port */
/* let's have fun binding... */
GNUNET_snprintf (port_str,
sizeof (port_str),
"%u",
(unsigned int) *port);
*port = 0; /* do NOT return port in case of errors */
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE
#ifdef AI_IDN
| AI_IDN
#endif
;
if (0 !=
(ec = getaddrinfo (bind_to,
port_str,
&hints,
&res)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to resolve BIND_TO address `%s': %s\n",
bind_to, gai_strerror (ec));
GNUNET_free (bind_to);
return -1;
}
GNUNET_free (bind_to);
if (NULL == (nh = GNUNET_NETWORK_socket_create (res->ai_family, /* let's have fun binding... */
res->ai_socktype,
res->ai_protocol)))
{ {
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, char port_str[6];
"socket"); struct addrinfo hints;
struct addrinfo *res;
int ec;
GNUNET_snprintf (port_str,
sizeof (port_str),
"%u",
(unsigned int) *port);
*port = 0; /* do NOT return port in case of errors */
memset (&hints,
0,
sizeof (hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE
#ifdef AI_IDN
| AI_IDN
#endif
;
if (0 !=
(ec = getaddrinfo (bind_to,
port_str,
&hints,
&res)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to resolve BIND_TO address `%s': %s\n",
bind_to,
gai_strerror (ec));
GNUNET_free (bind_to);
return -1;
}
GNUNET_free (bind_to);
if (NULL == (nh = GNUNET_NETWORK_socket_create (res->ai_family,
res->ai_socktype,
res->ai_protocol)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"socket");
freeaddrinfo (res);
return -1;
}
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (nh,
res->ai_addr,
res->ai_addrlen))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"bind");
freeaddrinfo (res);
return -1;
}
freeaddrinfo (res); freeaddrinfo (res);
return -1;
} }
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (nh,
res->ai_addr,
res->ai_addrlen))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"bind");
freeaddrinfo (res);
return -1;
}
freeaddrinfo (res);
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_NETWORK_socket_listen (nh, GNUNET_NETWORK_socket_listen (nh,
UNIX_BACKLOG)) UNIX_BACKLOG))
@ -398,6 +412,8 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return -1; return -1;
} }
/* extract and return actual socket handle from 'nh' */
{ {
int fh; int fh;