mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-21 18:26:06 -05:00
[evhtr] Consolidate pool threading in evthr.c
Also reinstate check for server already running
This commit is contained in:
21
src/misc.c
21
src/misc.c
@@ -278,8 +278,8 @@ net_connect(const char *addr, unsigned short port, int type, const char *log_ser
|
||||
|
||||
// If *port is 0 then a random port will be assigned, and *port will be updated
|
||||
// with the port number
|
||||
int
|
||||
net_bind(short unsigned *port, int type, const char *log_service_name)
|
||||
static int
|
||||
net_bind_impl(short unsigned *port, int type, const char *log_service_name, bool reuseport)
|
||||
{
|
||||
struct addrinfo hints = { 0 };
|
||||
struct addrinfo *servinfo;
|
||||
@@ -318,7 +318,10 @@ net_bind(short unsigned *port, int type, const char *log_service_name)
|
||||
continue;
|
||||
|
||||
// Makes us able to attach multiple threads to the same port
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes));
|
||||
if (reuseport)
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes));
|
||||
else
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &no, sizeof(no));
|
||||
if (ret < 0)
|
||||
continue;
|
||||
|
||||
@@ -381,6 +384,18 @@ net_bind(short unsigned *port, int type, const char *log_service_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
net_bind(short unsigned *port, int type, const char *log_service_name)
|
||||
{
|
||||
return net_bind_impl(port, type, log_service_name, false);
|
||||
}
|
||||
|
||||
int
|
||||
net_bind_with_reuseport(short unsigned *port, int type, const char *log_service_name)
|
||||
{
|
||||
return net_bind_impl(port, type, log_service_name, true);
|
||||
}
|
||||
|
||||
int
|
||||
net_evhttp_bind(struct evhttp *evhttp, unsigned short port, const char *log_service_name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user