listen: no CamelCase
Renamed functions.
This commit is contained in:
parent
d89ba3bcce
commit
9bb3f2d060
47
src/listen.c
47
src/listen.c
@ -64,16 +64,16 @@ struct listen_socket {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct listen_socket *listen_sockets;
|
static struct listen_socket *listen_sockets;
|
||||||
int boundPort;
|
int listen_port;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
listen_in_event(GIOChannel *source, GIOCondition condition, gpointer data);
|
listen_in_event(GIOChannel *source, GIOCondition condition, gpointer data);
|
||||||
|
|
||||||
static int establishListen(int pf, const struct sockaddr *addrp,
|
static int
|
||||||
socklen_t addrlen)
|
listen_add_address(int pf, const struct sockaddr *addrp, socklen_t addrlen)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
int allowReuse = ALLOW_REUSE;
|
const int reuse = ALLOW_REUSE;
|
||||||
#ifdef HAVE_STRUCT_UCRED
|
#ifdef HAVE_STRUCT_UCRED
|
||||||
int passcred = 1;
|
int passcred = 1;
|
||||||
#endif
|
#endif
|
||||||
@ -83,8 +83,8 @@ static int establishListen(int pf, const struct sockaddr *addrp,
|
|||||||
if ((sock = socket(pf, SOCK_STREAM, 0)) < 0)
|
if ((sock = socket(pf, SOCK_STREAM, 0)) < 0)
|
||||||
g_error("socket < 0");
|
g_error("socket < 0");
|
||||||
|
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&allowReuse,
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||||
sizeof(allowReuse)) < 0) {
|
&reuse, sizeof(reuse)) < 0) {
|
||||||
g_error("problems setsockopt'ing: %s", strerror(errno));
|
g_error("problems setsockopt'ing: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,8 @@ static int establishListen(int pf, const struct sockaddr *addrp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
static bool ipv6Supported(void)
|
static bool
|
||||||
|
is_ipv6_enabled(void)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
s = socket(AF_INET6, SOCK_STREAM, 0);
|
s = socket(AF_INET6, SOCK_STREAM, 0);
|
||||||
@ -127,8 +128,8 @@ static bool ipv6Supported(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
listen_add_config_param(G_GNUC_UNUSED unsigned int port,
|
||||||
const struct config_param *param)
|
const struct config_param *param)
|
||||||
{
|
{
|
||||||
const struct sockaddr *addrp;
|
const struct sockaddr *addrp;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
@ -136,7 +137,7 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
struct sockaddr_in sin4;
|
struct sockaddr_in sin4;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
struct sockaddr_in6 sin6;
|
struct sockaddr_in6 sin6;
|
||||||
int useIpv6 = ipv6Supported();
|
int ipv6_enabled = is_ipv6_enabled();
|
||||||
|
|
||||||
memset(&sin6, 0, sizeof(struct sockaddr_in6));
|
memset(&sin6, 0, sizeof(struct sockaddr_in6));
|
||||||
sin6.sin6_port = htons(port);
|
sin6.sin6_port = htons(port);
|
||||||
@ -151,11 +152,11 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
#ifdef HAVE_TCP
|
#ifdef HAVE_TCP
|
||||||
g_debug("binding to any address");
|
g_debug("binding to any address");
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if (useIpv6) {
|
if (ipv6_enabled) {
|
||||||
sin6.sin6_addr = in6addr_any;
|
sin6.sin6_addr = in6addr_any;
|
||||||
addrp = (const struct sockaddr *)&sin6;
|
addrp = (const struct sockaddr *)&sin6;
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
if (establishListen(PF_INET6, addrp, addrlen) < 0)
|
if (listen_add_address(PF_INET6, addrp, addrlen) < 0)
|
||||||
BINDERROR();
|
BINDERROR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -163,9 +164,9 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
addrp = (const struct sockaddr *)&sin4;
|
addrp = (const struct sockaddr *)&sin4;
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
if ((establishListen(PF_INET, addrp, addrlen) < 0) && !useIpv6) {
|
if ((listen_add_address(PF_INET, addrp, addrlen) < 0) && !ipv6_enabled) {
|
||||||
#else
|
#else
|
||||||
if (establishListen(PF_INET, addrp, addrlen) < 0) {
|
if (listen_add_address(PF_INET, addrp, addrlen) < 0) {
|
||||||
#endif
|
#endif
|
||||||
BINDERROR();
|
BINDERROR();
|
||||||
}
|
}
|
||||||
@ -189,7 +190,7 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
addrp = (const struct sockaddr *)&s_un;
|
addrp = (const struct sockaddr *)&s_un;
|
||||||
addrlen = sizeof(s_un);
|
addrlen = sizeof(s_un);
|
||||||
|
|
||||||
if (establishListen(PF_UNIX, addrp, addrlen) < 0)
|
if (listen_add_address(PF_UNIX, addrp, addrlen) < 0)
|
||||||
g_error("unable to bind to %s: %s",
|
g_error("unable to bind to %s: %s",
|
||||||
param->value, strerror(errno));
|
param->value, strerror(errno));
|
||||||
|
|
||||||
@ -223,8 +224,8 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
param->value, param->line, gai_strerror(ret));
|
param->value, param->line, gai_strerror(ret));
|
||||||
|
|
||||||
for (i = ai; i != NULL; i = i->ai_next)
|
for (i = ai; i != NULL; i = i->ai_next)
|
||||||
if (establishListen(i->ai_family, i->ai_addr,
|
if (listen_add_address(i->ai_family, i->ai_addr,
|
||||||
i->ai_addrlen) < 0)
|
i->ai_addrlen) < 0)
|
||||||
BINDERROR();
|
BINDERROR();
|
||||||
|
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
@ -242,7 +243,7 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
g_error("IPv4 address expected for host \"%s\" at line %i",
|
g_error("IPv4 address expected for host \"%s\" at line %i",
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
|
|
||||||
if (establishListen(AF_INET, he->h_addr, he->h_length) < 0)
|
if (listen_add_address(AF_INET, he->h_addr, he->h_length) < 0)
|
||||||
BINDERROR();
|
BINDERROR();
|
||||||
#endif /* !WIN32 */
|
#endif /* !WIN32 */
|
||||||
#else /* HAVE_TCP */
|
#else /* HAVE_TCP */
|
||||||
@ -251,21 +252,21 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void listenOnPort(void)
|
void listen_global_init(void)
|
||||||
{
|
{
|
||||||
int port = config_get_positive(CONF_PORT, DEFAULT_PORT);
|
int port = config_get_positive(CONF_PORT, DEFAULT_PORT);
|
||||||
const struct config_param *param =
|
const struct config_param *param =
|
||||||
config_get_next_param(CONF_BIND_TO_ADDRESS, NULL);
|
config_get_next_param(CONF_BIND_TO_ADDRESS, NULL);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
parseListenConfigParam(port, param);
|
listen_add_config_param(port, param);
|
||||||
} while ((param = config_get_next_param(CONF_BIND_TO_ADDRESS, param)));
|
} while ((param = config_get_next_param(CONF_BIND_TO_ADDRESS, param)));
|
||||||
boundPort = port;
|
listen_port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeAllListenSockets(void)
|
void listen_global_finish(void)
|
||||||
{
|
{
|
||||||
g_debug("closeAllListenSockets called");
|
g_debug("listen_global_finish called");
|
||||||
|
|
||||||
while (listen_sockets != NULL) {
|
while (listen_sockets != NULL) {
|
||||||
struct listen_socket *ls = listen_sockets;
|
struct listen_socket *ls = listen_sockets;
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
#ifndef MPD_LISTEN_H
|
#ifndef MPD_LISTEN_H
|
||||||
#define MPD_LISTEN_H
|
#define MPD_LISTEN_H
|
||||||
|
|
||||||
extern int boundPort;
|
extern int listen_port;
|
||||||
|
|
||||||
void listenOnPort(void);
|
void listen_global_init(void);
|
||||||
|
|
||||||
void closeAllListenSockets(void);
|
void listen_global_finish(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -226,7 +226,7 @@ int main(int argc, char *argv[])
|
|||||||
tag_lib_init();
|
tag_lib_init();
|
||||||
log_init(options.verbose, options.stdOutput);
|
log_init(options.verbose, options.stdOutput);
|
||||||
|
|
||||||
listenOnPort();
|
listen_global_init();
|
||||||
|
|
||||||
daemonize_set_user();
|
daemonize_set_user();
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ int main(int argc, char *argv[])
|
|||||||
playerKill();
|
playerKill();
|
||||||
finishZeroconf();
|
finishZeroconf();
|
||||||
client_manager_deinit();
|
client_manager_deinit();
|
||||||
closeAllListenSockets();
|
listen_global_finish();
|
||||||
finishPlaylist();
|
finishPlaylist();
|
||||||
|
|
||||||
start = clock();
|
start = clock();
|
||||||
|
@ -114,7 +114,7 @@ static void avahiRegisterService(AvahiClient * c)
|
|||||||
ret = avahi_entry_group_add_service(avahiGroup,
|
ret = avahi_entry_group_add_service(avahiGroup,
|
||||||
AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
|
AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
|
||||||
0, avahiName, SERVICE_TYPE, NULL,
|
0, avahiName, SERVICE_TYPE, NULL,
|
||||||
NULL, boundPort, NULL);
|
NULL, listen_port, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
g_warning("Failed to add service %s: %s", SERVICE_TYPE,
|
g_warning("Failed to add service %s: %s", SERVICE_TYPE,
|
||||||
avahi_strerror(ret));
|
avahi_strerror(ret));
|
||||||
|
@ -61,7 +61,7 @@ void init_zeroconf_osx(const char *serviceName)
|
|||||||
DNSServiceErrorType error = DNSServiceRegister(&dnsReference,
|
DNSServiceErrorType error = DNSServiceRegister(&dnsReference,
|
||||||
0, 0, serviceName,
|
0, 0, serviceName,
|
||||||
SERVICE_TYPE, NULL, NULL,
|
SERVICE_TYPE, NULL, NULL,
|
||||||
htons(boundPort), 0,
|
htons(listen_port), 0,
|
||||||
NULL,
|
NULL,
|
||||||
dnsRegisterCallback,
|
dnsRegisterCallback,
|
||||||
NULL);
|
NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user