aboutsummaryrefslogtreecommitdiff
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 13:20:27 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 14:16:04 +0100
commitfa51db449fdb9558a4cb4542a86437ac9dd3ddbd (patch)
tree7ecc27850e582fc6b4233bd316dcb079d0702341 /src/output
parentcb9a05ac77034fdcefc0d574e768afe0a1b86327 (diff)
ServerSocket: replace callback with virtual method
Diffstat (limited to 'src/output')
-rw-r--r--src/output/HttpdInternal.hxx12
-rw-r--r--src/output/HttpdOutputPlugin.cxx48
2 files changed, 29 insertions, 31 deletions
diff --git a/src/output/HttpdInternal.hxx b/src/output/HttpdInternal.hxx
index 4e6eb4f5..f1ee513e 100644
--- a/src/output/HttpdInternal.hxx
+++ b/src/output/HttpdInternal.hxx
@@ -28,6 +28,7 @@
#include "output_internal.h"
#include "timer.h"
#include "thread/Mutex.hxx"
+#include "event/ServerSocket.hxx"
#include <glib.h>
@@ -39,7 +40,7 @@ class ServerSocket;
class HttpdClient;
class Page;
-struct HttpdOutput {
+struct HttpdOutput final : private ServerSocket {
struct audio_output base;
/**
@@ -79,11 +80,6 @@ struct HttpdOutput {
struct timer *timer;
/**
- * The listener socket.
- */
- ServerSocket *server_socket;
-
- /**
* The header page, which is sent to every client on connect.
*/
Page *header;
@@ -201,6 +197,10 @@ struct HttpdOutput {
bool EncodeAndPlay(const void *chunk, size_t size, GError **error_r);
void SendTag(const struct tag *tag);
+
+private:
+ virtual void OnAccept(int fd, const sockaddr &address,
+ size_t address_length, int uid) override;
};
#endif
diff --git a/src/output/HttpdOutputPlugin.cxx b/src/output/HttpdOutputPlugin.cxx
index a4714637..6c67030c 100644
--- a/src/output/HttpdOutputPlugin.cxx
+++ b/src/output/HttpdOutputPlugin.cxx
@@ -28,7 +28,6 @@
#include "Page.hxx"
#include "IcyMetaDataServer.hxx"
#include "fd_util.h"
-#include "event/ServerSocket.hxx"
#include "Main.hxx"
#include <assert.h>
@@ -54,14 +53,10 @@ httpd_output_quark(void)
return g_quark_from_static_string("httpd_output");
}
-static void
-httpd_listen_in_event(int fd, const struct sockaddr *address,
- size_t address_length, int uid, void *ctx);
-
inline
HttpdOutput::HttpdOutput(EventLoop &_loop)
- :encoder(nullptr), unflushed_input(0),
- server_socket(new ServerSocket(_loop, httpd_listen_in_event, this)),
+ :ServerSocket(_loop),
+ encoder(nullptr), unflushed_input(0),
metadata(nullptr)
{
}
@@ -74,8 +69,6 @@ HttpdOutput::~HttpdOutput()
if (encoder != nullptr)
encoder_finish(encoder);
- delete server_socket;
-
}
inline bool
@@ -84,7 +77,7 @@ HttpdOutput::Bind(GError **error_r)
open = false;
const ScopeLock protect(mutex);
- return server_socket->Open(error_r);
+ return ServerSocket::Open(error_r);
}
inline void
@@ -93,7 +86,7 @@ HttpdOutput::Unbind()
assert(!open);
const ScopeLock protect(mutex);
- server_socket->Close();
+ ServerSocket::Close();
}
inline bool
@@ -125,8 +118,8 @@ HttpdOutput::Configure(const config_param *param, GError **error_r)
config_get_block_string(param, "bind_to_address", NULL);
bool success = bind_to_address != NULL &&
strcmp(bind_to_address, "any") != 0
- ? server_socket->AddHost(bind_to_address, port, error_r)
- : server_socket->AddPort(port, error_r);
+ ? AddHost(bind_to_address, port, error_r)
+ : AddPort(port, error_r);
if (!success)
return false;
@@ -165,12 +158,21 @@ httpd_output_init(const struct config_param *param,
return &httpd->base;
}
+#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winvalid-offsetof"
+#endif
+
static inline constexpr HttpdOutput *
Cast(audio_output *ao)
{
return (HttpdOutput *)((char *)ao - offsetof(HttpdOutput, base));
}
+#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
static void
httpd_output_finish(struct audio_output *ao)
{
@@ -196,18 +198,16 @@ HttpdOutput::AddClient(int fd)
clients.front().PushMetaData(metadata);
}
-static void
-httpd_listen_in_event(int fd, const struct sockaddr *address,
- size_t address_length, G_GNUC_UNUSED int uid, void *ctx)
+void
+HttpdOutput::OnAccept(int fd, const sockaddr &address,
+ size_t address_length, gcc_unused int uid)
{
- HttpdOutput *httpd = (HttpdOutput *)ctx;
-
/* the listener socket has become readable - a client has
connected */
#ifdef HAVE_LIBWRAP
- if (address->sa_family != AF_UNIX) {
- char *hostaddr = sockaddr_to_string(address, address_length, NULL);
+ if (address.sa_family != AF_UNIX) {
+ char *hostaddr = sockaddr_to_string(&address, address_length, NULL);
const char *progname = g_get_prgname();
struct request_info req;
@@ -231,14 +231,12 @@ httpd_listen_in_event(int fd, const struct sockaddr *address,
(void)address_length;
#endif /* HAVE_WRAP */
- const ScopeLock protect(httpd->mutex);
+ const ScopeLock protect(mutex);
if (fd >= 0) {
/* can we allow additional client */
- if (httpd->open &&
- (httpd->clients_max == 0 ||
- httpd->clients_cnt < httpd->clients_max))
- httpd->AddClient(fd);
+ if (open && (clients_max == 0 || clients_cnt < clients_max))
+ AddClient(fd);
else
close_socket(fd);
} else if (fd < 0 && errno != EINTR) {