Commit 5e8f51a9 authored by Max Kellermann's avatar Max Kellermann

output/httpd: use the BufferedSocket class for HttpdClient

parent be3d2188
......@@ -130,7 +130,6 @@ src_mpd_SOURCES = \
src/thread/PosixCond.hxx \
src/thread/WindowsCond.hxx \
src/thread/GLibCond.hxx \
src/glib_socket.h \
src/clock.c src/clock.h \
src/notify.cxx src/notify.hxx \
src/audio_config.c src/audio_config.h \
......
......@@ -27,7 +27,6 @@ extern "C" {
#include "resolver.h"
}
#include "Permission.hxx"
#include "glib_socket.h"
#include <assert.h>
#include <sys/types.h>
......
/*
* Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_GLIB_SOCKET_H
#define MPD_GLIB_SOCKET_H
#include <glib.h>
/**
* Portable wrapper for g_io_channel_unix_new() or
* g_io_channel_win32_new_socket().
*/
G_GNUC_MALLOC
static inline GIOChannel *
g_io_channel_new_socket(int fd)
{
#ifdef G_OS_WIN32
return g_io_channel_win32_new_socket(fd);
#else
return g_io_channel_unix_new(fd);
#endif
}
#endif
......@@ -20,6 +20,7 @@
#ifndef MPD_OUTPUT_HTTPD_CLIENT_HXX
#define MPD_OUTPUT_HTTPD_CLIENT_HXX
#include "event/BufferedSocket.hxx"
#include "gcc.h"
#include <glib.h>
......@@ -31,37 +32,13 @@
struct HttpdOutput;
class Page;
class HttpdClient final {
class HttpdClient final : public BufferedSocket {
/**
* The httpd output object this client is connected to.
*/
HttpdOutput *const httpd;
/**
* The TCP socket.
*/
GIOChannel *channel;
/**
* The GLib main loop source id for reading from the socket,
* and to detect errors.
*/
guint read_source_id;
/**
* The GLib main loop source id for writing to the socket. If
* 0, then there is no event source currently (because there
* are no queued pages).
*/
guint write_source_id;
/**
* For buffered reading. This pointer is only valid while the
* HTTP request is read.
*/
struct fifo_buffer *input;
/**
* The current state of the client.
*/
enum {
......@@ -140,7 +117,8 @@ public:
* @param httpd the HTTP output device
* @param fd the socket file descriptor
*/
HttpdClient(HttpdOutput *httpd, int _fd, bool _metadata_supported);
HttpdClient(HttpdOutput *httpd, int _fd, EventLoop &_loop,
bool _metadata_supported);
/**
* Note: this does not remove the client from the
......@@ -166,21 +144,6 @@ public:
*/
void CancelQueue();
bool Read();
/**
* Data has been received from the client and it is appended
* to the input buffer.
*/
bool Received();
/**
* Check if a complete line of input is present in the input
* buffer, and duplicates it. It is removed from the input
* buffer. The return value has to be freed with g_free().
*/
char *ReadLine();
/**
* Handle a line of the HTTP request.
*/
......@@ -197,9 +160,12 @@ public:
bool SendResponse();
gcc_pure
int GetBytesTillMetaData() const;
ssize_t GetBytesTillMetaData() const;
bool Write();
ssize_t TryWritePage(const Page &page, size_t position);
ssize_t TryWritePageN(const Page &page, size_t position, ssize_t n);
bool TryWrite();
/**
* Appends a page to the client's queue.
......@@ -209,7 +175,14 @@ public:
/**
* Sends the passed metadata.
*/
void PushMetaData(Page *page);
void PushMetaData(Page *page);
protected:
virtual bool OnSocketReady(unsigned flags) override;
virtual InputResult OnSocketInput(const void *data,
size_t length) override;
virtual void OnSocketError(GError *error) override;
virtual void OnSocketClosed() override;
};
#endif
......@@ -189,7 +189,7 @@ httpd_output_finish(struct audio_output *ao)
inline void
HttpdOutput::AddClient(int fd)
{
clients.emplace_front(this, fd,
clients.emplace_front(this, fd, GetEventLoop(),
encoder->plugin->tag == NULL);
++clients_cnt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment