output/httpd: add noexcept

This commit is contained in:
Max Kellermann 2018-12-28 17:02:39 +01:00
parent 53a4de35c4
commit ab30695bd1
4 changed files with 40 additions and 38 deletions

View File

@ -31,27 +31,27 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
HttpdClient::~HttpdClient() HttpdClient::~HttpdClient() noexcept
{ {
if (IsDefined()) if (IsDefined())
BufferedSocket::Close(); BufferedSocket::Close();
} }
void void
HttpdClient::Close() HttpdClient::Close() noexcept
{ {
httpd.RemoveClient(*this); httpd.RemoveClient(*this);
} }
void void
HttpdClient::LockClose() HttpdClient::LockClose() noexcept
{ {
const std::lock_guard<Mutex> protect(httpd.mutex); const std::lock_guard<Mutex> protect(httpd.mutex);
Close(); Close();
} }
void void
HttpdClient::BeginResponse() HttpdClient::BeginResponse() noexcept
{ {
assert(state != State::RESPONSE); assert(state != State::RESPONSE);
@ -66,7 +66,7 @@ HttpdClient::BeginResponse()
* Handle a line of the HTTP request. * Handle a line of the HTTP request.
*/ */
bool bool
HttpdClient::HandleLine(const char *line) HttpdClient::HandleLine(const char *line) noexcept
{ {
assert(state != State::RESPONSE); assert(state != State::RESPONSE);
@ -121,7 +121,7 @@ HttpdClient::HandleLine(const char *line)
* Sends the status line and response headers to the client. * Sends the status line and response headers to the client.
*/ */
bool bool
HttpdClient::SendResponse() HttpdClient::SendResponse() noexcept
{ {
char buffer[1024]; char buffer[1024];
AllocatedString<> allocated = nullptr; AllocatedString<> allocated = nullptr;
@ -171,7 +171,7 @@ HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor _fd,
} }
void void
HttpdClient::ClearQueue() HttpdClient::ClearQueue() noexcept
{ {
assert(state == State::RESPONSE); assert(state == State::RESPONSE);
@ -189,7 +189,7 @@ HttpdClient::ClearQueue()
} }
void void
HttpdClient::CancelQueue() HttpdClient::CancelQueue() noexcept
{ {
if (state != State::RESPONSE) if (state != State::RESPONSE)
return; return;
@ -201,7 +201,7 @@ HttpdClient::CancelQueue()
} }
ssize_t ssize_t
HttpdClient::TryWritePage(const Page &page, size_t position) HttpdClient::TryWritePage(const Page &page, size_t position) noexcept
{ {
assert(position < page.GetSize()); assert(position < page.GetSize());
@ -210,7 +210,8 @@ HttpdClient::TryWritePage(const Page &page, size_t position)
} }
ssize_t ssize_t
HttpdClient::TryWritePageN(const Page &page, size_t position, ssize_t n) HttpdClient::TryWritePageN(const Page &page,
size_t position, ssize_t n) noexcept
{ {
return n >= 0 return n >= 0
? GetSocket().Write(page.GetData() + position, n) ? GetSocket().Write(page.GetData() + position, n)
@ -228,7 +229,7 @@ HttpdClient::GetBytesTillMetaData() const noexcept
} }
inline bool inline bool
HttpdClient::TryWrite() HttpdClient::TryWrite() noexcept
{ {
const std::lock_guard<Mutex> protect(httpd.mutex); const std::lock_guard<Mutex> protect(httpd.mutex);
@ -342,7 +343,7 @@ HttpdClient::TryWrite()
} }
void void
HttpdClient::PushPage(PagePtr page) HttpdClient::PushPage(PagePtr page) noexcept
{ {
if (state != State::RESPONSE) if (state != State::RESPONSE)
/* the client is still writing the HTTP request */ /* the client is still writing the HTTP request */
@ -361,7 +362,7 @@ HttpdClient::PushPage(PagePtr page)
} }
void void
HttpdClient::PushMetaData(PagePtr page) HttpdClient::PushMetaData(PagePtr page) noexcept
{ {
assert(page != nullptr); assert(page != nullptr);

View File

@ -138,55 +138,56 @@ public:
* Note: this does not remove the client from the * Note: this does not remove the client from the
* #HttpdOutput object. * #HttpdOutput object.
*/ */
~HttpdClient(); ~HttpdClient() noexcept;
/** /**
* Frees the client and removes it from the server's client list. * Frees the client and removes it from the server's client list.
*/ */
void Close(); void Close() noexcept;
void LockClose(); void LockClose() noexcept;
/** /**
* Clears the page queue. * Clears the page queue.
*/ */
void CancelQueue(); void CancelQueue() noexcept;
/** /**
* Handle a line of the HTTP request. * Handle a line of the HTTP request.
*/ */
bool HandleLine(const char *line); bool HandleLine(const char *line) noexcept;
/** /**
* Switch the client to #State::RESPONSE. * Switch the client to #State::RESPONSE.
*/ */
void BeginResponse(); void BeginResponse() noexcept;
/** /**
* Sends the status line and response headers to the client. * Sends the status line and response headers to the client.
*/ */
bool SendResponse(); bool SendResponse() noexcept;
gcc_pure gcc_pure
ssize_t GetBytesTillMetaData() const noexcept; ssize_t GetBytesTillMetaData() const noexcept;
ssize_t TryWritePage(const Page &page, size_t position); ssize_t TryWritePage(const Page &page, size_t position) noexcept;
ssize_t TryWritePageN(const Page &page, size_t position, ssize_t n); ssize_t TryWritePageN(const Page &page,
size_t position, ssize_t n) noexcept;
bool TryWrite(); bool TryWrite() noexcept;
/** /**
* Appends a page to the client's queue. * Appends a page to the client's queue.
*/ */
void PushPage(PagePtr page); void PushPage(PagePtr page) noexcept;
/** /**
* Sends the passed metadata. * Sends the passed metadata.
*/ */
void PushMetaData(PagePtr page); void PushMetaData(PagePtr page) noexcept;
private: private:
void ClearQueue(); void ClearQueue() noexcept;
protected: protected:
/* virtual methods from class SocketMonitor */ /* virtual methods from class SocketMonitor */

View File

@ -162,7 +162,7 @@ public:
using ServerSocket::GetEventLoop; using ServerSocket::GetEventLoop;
void Bind(); void Bind();
void Unbind(); void Unbind() noexcept;
void Enable() override { void Enable() override {
Bind(); Bind();
@ -208,18 +208,18 @@ public:
return HasClients(); return HasClients();
} }
void AddClient(UniqueSocketDescriptor fd); void AddClient(UniqueSocketDescriptor fd) noexcept;
/** /**
* Removes a client from the httpd_output.clients linked list. * Removes a client from the httpd_output.clients linked list.
*/ */
void RemoveClient(HttpdClient &client); void RemoveClient(HttpdClient &client) noexcept;
/** /**
* Sends the encoder header to the client. This is called * Sends the encoder header to the client. This is called
* right after the response headers have been sent. * right after the response headers have been sent.
*/ */
void SendHeader(HttpdClient &client) const; void SendHeader(HttpdClient &client) const noexcept;
gcc_pure gcc_pure
std::chrono::steady_clock::duration Delay() const noexcept override; std::chrono::steady_clock::duration Delay() const noexcept override;
@ -235,7 +235,7 @@ public:
* *
* Mutext must not be locked. * Mutext must not be locked.
*/ */
void BroadcastPage(PagePtr page); void BroadcastPage(PagePtr page) noexcept;
/** /**
* Broadcasts data from the encoder to all clients. * Broadcasts data from the encoder to all clients.
@ -251,7 +251,7 @@ public:
size_t Play(const void *chunk, size_t size) override; size_t Play(const void *chunk, size_t size) override;
void CancelAllClients(); void CancelAllClients() noexcept;
void Cancel() noexcept override; void Cancel() noexcept override;
bool Pause() override; bool Pause() override;

View File

@ -77,7 +77,7 @@ HttpdOutput::Bind()
} }
inline void inline void
HttpdOutput::Unbind() HttpdOutput::Unbind() noexcept
{ {
assert(!open); assert(!open);
@ -91,7 +91,7 @@ HttpdOutput::Unbind()
* HttpdOutput.clients linked list. * HttpdOutput.clients linked list.
*/ */
inline void inline void
HttpdOutput::AddClient(UniqueSocketDescriptor fd) HttpdOutput::AddClient(UniqueSocketDescriptor fd) noexcept
{ {
auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(), auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(),
!encoder->ImplementsTag()); !encoder->ImplementsTag());
@ -223,7 +223,7 @@ HttpdOutput::Close() noexcept
} }
void void
HttpdOutput::RemoveClient(HttpdClient &client) HttpdOutput::RemoveClient(HttpdClient &client) noexcept
{ {
assert(!clients.empty()); assert(!clients.empty());
@ -232,7 +232,7 @@ HttpdOutput::RemoveClient(HttpdClient &client)
} }
void void
HttpdOutput::SendHeader(HttpdClient &client) const HttpdOutput::SendHeader(HttpdClient &client) const noexcept
{ {
if (header != nullptr) if (header != nullptr)
client.PushPage(header); client.PushPage(header);
@ -260,7 +260,7 @@ HttpdOutput::Delay() const noexcept
} }
void void
HttpdOutput::BroadcastPage(PagePtr page) HttpdOutput::BroadcastPage(PagePtr page) noexcept
{ {
assert(page != nullptr); assert(page != nullptr);
@ -386,7 +386,7 @@ HttpdOutput::SendTag(const Tag &tag)
} }
inline void inline void
HttpdOutput::CancelAllClients() HttpdOutput::CancelAllClients() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);