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,15 +317,13 @@ 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;
{
char *serve_unixpath;
mode_t unixpath_mode;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_MHD_parse_config (cfg, TALER_MHD_parse_config (cfg,
section, section,
@ -334,19 +334,29 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (NULL != serve_unixpath) if (NULL != serve_unixpath)
return TALER_MHD_open_unix_path (serve_unixpath, return TALER_MHD_open_unix_path (serve_unixpath,
unixpath_mode); 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... */ /* let's have fun binding... */
{
char port_str[6];
struct addrinfo hints;
struct addrinfo *res;
int ec;
GNUNET_snprintf (port_str, GNUNET_snprintf (port_str,
sizeof (port_str), sizeof (port_str),
"%u", "%u",
(unsigned int) *port); (unsigned int) *port);
*port = 0; /* do NOT return port in case of errors */ *port = 0; /* do NOT return port in case of errors */
memset (&hints, 0, sizeof (hints)); memset (&hints,
0,
sizeof (hints));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP; hints.ai_protocol = IPPROTO_TCP;
@ -355,6 +365,7 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
| AI_IDN | AI_IDN
#endif #endif
; ;
if (0 != if (0 !=
(ec = getaddrinfo (bind_to, (ec = getaddrinfo (bind_to,
port_str, port_str,
@ -363,7 +374,8 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to resolve BIND_TO address `%s': %s\n", "Failed to resolve BIND_TO address `%s': %s\n",
bind_to, gai_strerror (ec)); bind_to,
gai_strerror (ec));
GNUNET_free (bind_to); GNUNET_free (bind_to);
return -1; return -1;
} }
@ -389,6 +401,8 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
return -1; return -1;
} }
freeaddrinfo (res); 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;