lib/curl: add "noexcept"

This commit is contained in:
Max Kellermann 2017-11-12 17:49:58 +01:00
parent c582a9faae
commit 9d47b220a4
14 changed files with 71 additions and 65 deletions

View File

@ -127,7 +127,7 @@ struct CurlInputStream final : public AsyncInputStream, CurlResponseHandler {
std::multimap<std::string, std::string> &&headers) override;
void OnData(ConstBuffer<void> data) override;
void OnEnd() override;
void OnError(std::exception_ptr e) override;
void OnError(std::exception_ptr e) noexcept override;
/* virtual methods from AsyncInputStream */
virtual void DoResume() override;
@ -275,7 +275,7 @@ CurlInputStream::OnEnd()
}
void
CurlInputStream::OnError(std::exception_ptr e)
CurlInputStream::OnError(std::exception_ptr e) noexcept
{
postponed_exception = std::move(e);

View File

@ -58,25 +58,26 @@ public:
/**
* Create an empty instance.
*/
CurlEasy(std::nullptr_t):handle(nullptr) {}
CurlEasy(std::nullptr_t) noexcept:handle(nullptr) {}
CurlEasy(CurlEasy &&src):handle(std::exchange(src.handle, nullptr)) {}
CurlEasy(CurlEasy &&src) noexcept
:handle(std::exchange(src.handle, nullptr)) {}
~CurlEasy() {
~CurlEasy() noexcept {
if (handle != nullptr)
curl_easy_cleanup(handle);
}
operator bool() const {
operator bool() const noexcept {
return handle != nullptr;
}
CurlEasy &operator=(CurlEasy &&src) {
CurlEasy &operator=(CurlEasy &&src) noexcept {
std::swap(handle, src.handle);
return *this;
}
CURL *Get() {
CURL *Get() noexcept {
return handle;
}

View File

@ -68,7 +68,7 @@ public:
bool OnSocketReady(unsigned flags) noexcept override;
private:
static constexpr int FlagsToCurlCSelect(unsigned flags) {
static constexpr int FlagsToCurlCSelect(unsigned flags) noexcept {
return (flags & (READ | HANGUP) ? CURL_CSELECT_IN : 0) |
(flags & WRITE ? CURL_CSELECT_OUT : 0) |
(flags & ERROR ? CURL_CSELECT_ERR : 0);
@ -175,7 +175,7 @@ CurlGlobal::Add(CURL *easy, CurlRequest &request)
}
void
CurlGlobal::Remove(CURL *easy)
CurlGlobal::Remove(CURL *easy) noexcept
{
assert(GetEventLoop().IsInside());
assert(easy != nullptr);
@ -186,7 +186,7 @@ CurlGlobal::Remove(CURL *easy)
}
static CurlRequest *
ToRequest(CURL *easy)
ToRequest(CURL *easy) noexcept
{
void *p;
CURLcode code = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &p);
@ -202,7 +202,7 @@ ToRequest(CURL *easy)
* Runs in the I/O thread. The caller must not hold locks.
*/
inline void
CurlGlobal::ReadInfo()
CurlGlobal::ReadInfo() noexcept
{
assert(GetEventLoop().IsInside());
@ -220,7 +220,7 @@ CurlGlobal::ReadInfo()
}
inline void
CurlGlobal::UpdateTimeout(long timeout_ms)
CurlGlobal::UpdateTimeout(long timeout_ms) noexcept
{
if (timeout_ms < 0) {
timeout_event.Cancel();
@ -238,7 +238,8 @@ CurlGlobal::UpdateTimeout(long timeout_ms)
}
int
CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms, void *userp)
CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms,
void *userp) noexcept
{
auto &global = *(CurlGlobal *)userp;
assert(_global == global.multi.Get());
@ -248,13 +249,13 @@ CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms, void *user
}
void
CurlGlobal::OnTimeout()
CurlGlobal::OnTimeout() noexcept
{
SocketAction(CURL_SOCKET_TIMEOUT, 0);
}
void
CurlGlobal::SocketAction(curl_socket_t fd, int ev_bitmask)
CurlGlobal::SocketAction(curl_socket_t fd, int ev_bitmask) noexcept
{
int running_handles;
CURLMcode mcode = curl_multi_socket_action(multi.Get(), fd, ev_bitmask,

View File

@ -50,25 +50,25 @@ class CurlGlobal final {
public:
explicit CurlGlobal(EventLoop &_loop);
EventLoop &GetEventLoop() {
EventLoop &GetEventLoop() noexcept {
return timeout_event.GetEventLoop();
}
void Add(CURL *easy, CurlRequest &request);
void Remove(CURL *easy);
void Remove(CURL *easy) noexcept;
/**
* Check for finished HTTP responses.
*
* Runs in the I/O thread. The caller must not hold locks.
*/
void ReadInfo();
void ReadInfo() noexcept;
void Assign(curl_socket_t fd, CurlSocket &cs) {
void Assign(curl_socket_t fd, CurlSocket &cs) noexcept {
curl_multi_assign(multi.Get(), fd, &cs);
}
void SocketAction(curl_socket_t fd, int ev_bitmask);
void SocketAction(curl_socket_t fd, int ev_bitmask) noexcept;
void InvalidateSockets() {
SocketAction(CURL_SOCKET_TIMEOUT, 0);
@ -85,11 +85,12 @@ public:
}
private:
void UpdateTimeout(long timeout_ms);
static int TimerFunction(CURLM *global, long timeout_ms, void *userp);
void UpdateTimeout(long timeout_ms) noexcept;
static int TimerFunction(CURLM *global, long timeout_ms,
void *userp) noexcept;
/* callback for #timeout_event */
void OnTimeout();
void OnTimeout() noexcept;
};
#endif

View File

@ -42,7 +42,7 @@ public:
std::multimap<std::string, std::string> &&headers) = 0;
virtual void OnData(ConstBuffer<void> data) = 0;
virtual void OnEnd() = 0;
virtual void OnError(std::exception_ptr e) = 0;
virtual void OnError(std::exception_ptr e) noexcept = 0;
};
#endif

View File

@ -57,7 +57,7 @@ CurlInit::CurlInit(EventLoop &event_loop)
instance = new CurlGlobal(event_loop);
}
CurlInit::~CurlInit()
CurlInit::~CurlInit() noexcept
{
const std::lock_guard<Mutex> protect(mutex);
if (--ref > 0)

View File

@ -47,7 +47,7 @@ class CurlInit {
public:
explicit CurlInit(EventLoop &event_loop);
~CurlInit();
~CurlInit() noexcept;
CurlInit(const CurlInit &) = delete;
CurlInit &operator=(const CurlInit &) = delete;

View File

@ -58,25 +58,26 @@ public:
/**
* Create an empty instance.
*/
CurlMulti(std::nullptr_t):handle(nullptr) {}
CurlMulti(std::nullptr_t) noexcept:handle(nullptr) {}
CurlMulti(CurlMulti &&src):handle(std::exchange(src.handle, nullptr)) {}
CurlMulti(CurlMulti &&src) noexcept
:handle(std::exchange(src.handle, nullptr)) {}
~CurlMulti() {
~CurlMulti() noexcept {
if (handle != nullptr)
curl_multi_cleanup(handle);
}
operator bool() const {
operator bool() const noexcept {
return handle != nullptr;
}
CurlMulti &operator=(CurlMulti &&src) {
CurlMulti &operator=(CurlMulti &&src) noexcept {
std::swap(handle, src.handle);
return *this;
}
CURLM *Get() {
CURLM *Get() noexcept {
return handle;
}

View File

@ -66,13 +66,13 @@ CurlRequest::CurlRequest(CurlGlobal &_global, const char *url,
easy.SetOption(CURLOPT_URL, url);
}
CurlRequest::~CurlRequest()
CurlRequest::~CurlRequest() noexcept
{
FreeEasy();
}
void
CurlRequest::Start()
CurlRequest::Start() noexcept
{
assert(!registered);
@ -81,7 +81,7 @@ CurlRequest::Start()
}
void
CurlRequest::Stop()
CurlRequest::Stop() noexcept
{
if (!registered)
return;
@ -91,7 +91,7 @@ CurlRequest::Stop()
}
void
CurlRequest::FreeEasy()
CurlRequest::FreeEasy() noexcept
{
if (!easy)
return;
@ -101,7 +101,7 @@ CurlRequest::FreeEasy()
}
void
CurlRequest::Resume()
CurlRequest::Resume() noexcept
{
assert(registered);
@ -143,7 +143,7 @@ CurlRequest::FinishBody()
}
void
CurlRequest::Done(CURLcode result)
CurlRequest::Done(CURLcode result) noexcept
{
Stop();
@ -180,7 +180,7 @@ IsResponseBoundaryHeader(StringView s) noexcept
}
inline void
CurlRequest::HeaderFunction(StringView s)
CurlRequest::HeaderFunction(StringView s) noexcept
{
if (state > State::HEADERS)
return;
@ -216,7 +216,8 @@ CurlRequest::HeaderFunction(StringView s)
}
size_t
CurlRequest::_HeaderFunction(void *ptr, size_t size, size_t nmemb, void *stream)
CurlRequest::_HeaderFunction(void *ptr, size_t size, size_t nmemb,
void *stream) noexcept
{
CurlRequest &c = *(CurlRequest *)stream;
@ -227,7 +228,7 @@ CurlRequest::_HeaderFunction(void *ptr, size_t size, size_t nmemb, void *stream)
}
inline size_t
CurlRequest::DataReceived(const void *ptr, size_t received_size)
CurlRequest::DataReceived(const void *ptr, size_t received_size) noexcept
{
assert(received_size > 0);
@ -249,7 +250,8 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size)
}
size_t
CurlRequest::WriteFunction(void *ptr, size_t size, size_t nmemb, void *stream)
CurlRequest::WriteFunction(void *ptr, size_t size, size_t nmemb,
void *stream) noexcept
{
CurlRequest &c = *(CurlRequest *)stream;
@ -261,7 +263,7 @@ CurlRequest::WriteFunction(void *ptr, size_t size, size_t nmemb, void *stream)
}
void
CurlRequest::OnPostponeError()
CurlRequest::OnPostponeError() noexcept
{
assert(postponed_error);

View File

@ -80,7 +80,7 @@ public:
*/
CurlRequest(CurlGlobal &_global, const char *url,
CurlResponseHandler &_handler);
~CurlRequest();
~CurlRequest() noexcept;
CurlRequest(const CurlRequest &) = delete;
CurlRequest &operator=(const CurlRequest &) = delete;
@ -91,16 +91,16 @@ public:
*
* This method must be called in the event loop thread.
*/
void Start();
void Start() noexcept;
/**
* Unregister this request via CurlGlobal::Remove().
*
* This method must be called in the event loop thread.
*/
void Stop();
void Stop() noexcept;
CURL *Get() {
CURL *Get() noexcept {
return easy.Get();
}
@ -115,36 +115,36 @@ public:
*/
struct Pause {};
void Resume();
void Resume() noexcept;
/**
* A HTTP request is finished. Called by #CurlGlobal.
*/
void Done(CURLcode result);
void Done(CURLcode result) noexcept;
private:
/**
* Frees the current "libcurl easy" handle, and everything
* associated with it.
*/
void FreeEasy();
void FreeEasy() noexcept;
void FinishHeaders();
void FinishBody();
size_t DataReceived(const void *ptr, size_t size);
size_t DataReceived(const void *ptr, size_t size) noexcept;
void HeaderFunction(StringView s);
void HeaderFunction(StringView s) noexcept;
void OnPostponeError();
void OnPostponeError() noexcept;
/** called by curl when new data is available */
static size_t _HeaderFunction(void *ptr, size_t size, size_t nmemb,
void *stream);
void *stream) noexcept;
/** called by curl when new data is available */
static size_t WriteFunction(void *ptr, size_t size, size_t nmemb,
void *stream);
void *stream) noexcept;
};
#endif

View File

@ -41,26 +41,26 @@ class CurlSlist {
struct curl_slist *head = nullptr;
public:
CurlSlist() = default;
CurlSlist() noexcept = default;
CurlSlist(CurlSlist &&src)
CurlSlist(CurlSlist &&src) noexcept
:head(std::exchange(src.head, nullptr)) {}
~CurlSlist() {
~CurlSlist() noexcept {
if (head != nullptr)
curl_slist_free_all(head);
}
CurlSlist &operator=(CurlSlist &&src) {
CurlSlist &operator=(CurlSlist &&src) noexcept {
std::swap(head, src.head);
return *this;
}
struct curl_slist *Get() {
struct curl_slist *Get() noexcept {
return head;
}
void Clear() {
void Clear() noexcept {
curl_slist_free_all(head);
head = nullptr;
}

View File

@ -86,7 +86,7 @@ UPnPDeviceDirectory::Downloader::OnEnd()
}
void
UPnPDeviceDirectory::Downloader::OnError(std::exception_ptr e)
UPnPDeviceDirectory::Downloader::OnError(std::exception_ptr e) noexcept
{
LogError(e);
Destroy();

View File

@ -118,7 +118,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
std::multimap<std::string, std::string> &&headers) override;
void OnData(ConstBuffer<void> data) override;
void OnEnd() override;
void OnError(std::exception_ptr e) override;
void OnError(std::exception_ptr e) noexcept override;
};
CurlInit curl;

View File

@ -144,7 +144,7 @@ private:
}
/* virtual methods from CurlResponseHandler */
void OnError(std::exception_ptr e) final {
void OnError(std::exception_ptr e) noexcept final {
const std::lock_guard<Mutex> lock(mutex);
postponed_error = std::move(e);
SetDone();