Commit 9d47b220 authored by Max Kellermann's avatar Max Kellermann

lib/curl: add "noexcept"

parent c582a9fa
...@@ -127,7 +127,7 @@ struct CurlInputStream final : public AsyncInputStream, CurlResponseHandler { ...@@ -127,7 +127,7 @@ struct CurlInputStream final : public AsyncInputStream, CurlResponseHandler {
std::multimap<std::string, std::string> &&headers) override; std::multimap<std::string, std::string> &&headers) override;
void OnData(ConstBuffer<void> data) override; void OnData(ConstBuffer<void> data) override;
void OnEnd() override; void OnEnd() override;
void OnError(std::exception_ptr e) override; void OnError(std::exception_ptr e) noexcept override;
/* virtual methods from AsyncInputStream */ /* virtual methods from AsyncInputStream */
virtual void DoResume() override; virtual void DoResume() override;
...@@ -275,7 +275,7 @@ CurlInputStream::OnEnd() ...@@ -275,7 +275,7 @@ CurlInputStream::OnEnd()
} }
void void
CurlInputStream::OnError(std::exception_ptr e) CurlInputStream::OnError(std::exception_ptr e) noexcept
{ {
postponed_exception = std::move(e); postponed_exception = std::move(e);
......
...@@ -58,25 +58,26 @@ public: ...@@ -58,25 +58,26 @@ public:
/** /**
* Create an empty instance. * 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) if (handle != nullptr)
curl_easy_cleanup(handle); curl_easy_cleanup(handle);
} }
operator bool() const { operator bool() const noexcept {
return handle != nullptr; return handle != nullptr;
} }
CurlEasy &operator=(CurlEasy &&src) { CurlEasy &operator=(CurlEasy &&src) noexcept {
std::swap(handle, src.handle); std::swap(handle, src.handle);
return *this; return *this;
} }
CURL *Get() { CURL *Get() noexcept {
return handle; return handle;
} }
......
...@@ -68,7 +68,7 @@ public: ...@@ -68,7 +68,7 @@ public:
bool OnSocketReady(unsigned flags) noexcept override; bool OnSocketReady(unsigned flags) noexcept override;
private: private:
static constexpr int FlagsToCurlCSelect(unsigned flags) { static constexpr int FlagsToCurlCSelect(unsigned flags) noexcept {
return (flags & (READ | HANGUP) ? CURL_CSELECT_IN : 0) | return (flags & (READ | HANGUP) ? CURL_CSELECT_IN : 0) |
(flags & WRITE ? CURL_CSELECT_OUT : 0) | (flags & WRITE ? CURL_CSELECT_OUT : 0) |
(flags & ERROR ? CURL_CSELECT_ERR : 0); (flags & ERROR ? CURL_CSELECT_ERR : 0);
...@@ -175,7 +175,7 @@ CurlGlobal::Add(CURL *easy, CurlRequest &request) ...@@ -175,7 +175,7 @@ CurlGlobal::Add(CURL *easy, CurlRequest &request)
} }
void void
CurlGlobal::Remove(CURL *easy) CurlGlobal::Remove(CURL *easy) noexcept
{ {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
assert(easy != nullptr); assert(easy != nullptr);
...@@ -186,7 +186,7 @@ CurlGlobal::Remove(CURL *easy) ...@@ -186,7 +186,7 @@ CurlGlobal::Remove(CURL *easy)
} }
static CurlRequest * static CurlRequest *
ToRequest(CURL *easy) ToRequest(CURL *easy) noexcept
{ {
void *p; void *p;
CURLcode code = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &p); CURLcode code = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &p);
...@@ -202,7 +202,7 @@ ToRequest(CURL *easy) ...@@ -202,7 +202,7 @@ ToRequest(CURL *easy)
* Runs in the I/O thread. The caller must not hold locks. * Runs in the I/O thread. The caller must not hold locks.
*/ */
inline void inline void
CurlGlobal::ReadInfo() CurlGlobal::ReadInfo() noexcept
{ {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
...@@ -220,7 +220,7 @@ CurlGlobal::ReadInfo() ...@@ -220,7 +220,7 @@ CurlGlobal::ReadInfo()
} }
inline void inline void
CurlGlobal::UpdateTimeout(long timeout_ms) CurlGlobal::UpdateTimeout(long timeout_ms) noexcept
{ {
if (timeout_ms < 0) { if (timeout_ms < 0) {
timeout_event.Cancel(); timeout_event.Cancel();
...@@ -238,7 +238,8 @@ CurlGlobal::UpdateTimeout(long timeout_ms) ...@@ -238,7 +238,8 @@ CurlGlobal::UpdateTimeout(long timeout_ms)
} }
int 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; auto &global = *(CurlGlobal *)userp;
assert(_global == global.multi.Get()); assert(_global == global.multi.Get());
...@@ -248,13 +249,13 @@ CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms, void *user ...@@ -248,13 +249,13 @@ CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms, void *user
} }
void void
CurlGlobal::OnTimeout() CurlGlobal::OnTimeout() noexcept
{ {
SocketAction(CURL_SOCKET_TIMEOUT, 0); SocketAction(CURL_SOCKET_TIMEOUT, 0);
} }
void void
CurlGlobal::SocketAction(curl_socket_t fd, int ev_bitmask) CurlGlobal::SocketAction(curl_socket_t fd, int ev_bitmask) noexcept
{ {
int running_handles; int running_handles;
CURLMcode mcode = curl_multi_socket_action(multi.Get(), fd, ev_bitmask, CURLMcode mcode = curl_multi_socket_action(multi.Get(), fd, ev_bitmask,
......
...@@ -50,25 +50,25 @@ class CurlGlobal final { ...@@ -50,25 +50,25 @@ class CurlGlobal final {
public: public:
explicit CurlGlobal(EventLoop &_loop); explicit CurlGlobal(EventLoop &_loop);
EventLoop &GetEventLoop() { EventLoop &GetEventLoop() noexcept {
return timeout_event.GetEventLoop(); return timeout_event.GetEventLoop();
} }
void Add(CURL *easy, CurlRequest &request); void Add(CURL *easy, CurlRequest &request);
void Remove(CURL *easy); void Remove(CURL *easy) noexcept;
/** /**
* Check for finished HTTP responses. * Check for finished HTTP responses.
* *
* Runs in the I/O thread. The caller must not hold locks. * 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); 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() { void InvalidateSockets() {
SocketAction(CURL_SOCKET_TIMEOUT, 0); SocketAction(CURL_SOCKET_TIMEOUT, 0);
...@@ -85,11 +85,12 @@ public: ...@@ -85,11 +85,12 @@ public:
} }
private: private:
void UpdateTimeout(long timeout_ms); void UpdateTimeout(long timeout_ms) noexcept;
static int TimerFunction(CURLM *global, long timeout_ms, void *userp); static int TimerFunction(CURLM *global, long timeout_ms,
void *userp) noexcept;
/* callback for #timeout_event */ /* callback for #timeout_event */
void OnTimeout(); void OnTimeout() noexcept;
}; };
#endif #endif
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
std::multimap<std::string, std::string> &&headers) = 0; std::multimap<std::string, std::string> &&headers) = 0;
virtual void OnData(ConstBuffer<void> data) = 0; virtual void OnData(ConstBuffer<void> data) = 0;
virtual void OnEnd() = 0; virtual void OnEnd() = 0;
virtual void OnError(std::exception_ptr e) = 0; virtual void OnError(std::exception_ptr e) noexcept = 0;
}; };
#endif #endif
...@@ -57,7 +57,7 @@ CurlInit::CurlInit(EventLoop &event_loop) ...@@ -57,7 +57,7 @@ CurlInit::CurlInit(EventLoop &event_loop)
instance = new CurlGlobal(event_loop); instance = new CurlGlobal(event_loop);
} }
CurlInit::~CurlInit() CurlInit::~CurlInit() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (--ref > 0) if (--ref > 0)
......
...@@ -47,7 +47,7 @@ class CurlInit { ...@@ -47,7 +47,7 @@ class CurlInit {
public: public:
explicit CurlInit(EventLoop &event_loop); explicit CurlInit(EventLoop &event_loop);
~CurlInit(); ~CurlInit() noexcept;
CurlInit(const CurlInit &) = delete; CurlInit(const CurlInit &) = delete;
CurlInit &operator=(const CurlInit &) = delete; CurlInit &operator=(const CurlInit &) = delete;
......
...@@ -58,25 +58,26 @@ public: ...@@ -58,25 +58,26 @@ public:
/** /**
* Create an empty instance. * 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) if (handle != nullptr)
curl_multi_cleanup(handle); curl_multi_cleanup(handle);
} }
operator bool() const { operator bool() const noexcept {
return handle != nullptr; return handle != nullptr;
} }
CurlMulti &operator=(CurlMulti &&src) { CurlMulti &operator=(CurlMulti &&src) noexcept {
std::swap(handle, src.handle); std::swap(handle, src.handle);
return *this; return *this;
} }
CURLM *Get() { CURLM *Get() noexcept {
return handle; return handle;
} }
......
...@@ -66,13 +66,13 @@ CurlRequest::CurlRequest(CurlGlobal &_global, const char *url, ...@@ -66,13 +66,13 @@ CurlRequest::CurlRequest(CurlGlobal &_global, const char *url,
easy.SetOption(CURLOPT_URL, url); easy.SetOption(CURLOPT_URL, url);
} }
CurlRequest::~CurlRequest() CurlRequest::~CurlRequest() noexcept
{ {
FreeEasy(); FreeEasy();
} }
void void
CurlRequest::Start() CurlRequest::Start() noexcept
{ {
assert(!registered); assert(!registered);
...@@ -81,7 +81,7 @@ CurlRequest::Start() ...@@ -81,7 +81,7 @@ CurlRequest::Start()
} }
void void
CurlRequest::Stop() CurlRequest::Stop() noexcept
{ {
if (!registered) if (!registered)
return; return;
...@@ -91,7 +91,7 @@ CurlRequest::Stop() ...@@ -91,7 +91,7 @@ CurlRequest::Stop()
} }
void void
CurlRequest::FreeEasy() CurlRequest::FreeEasy() noexcept
{ {
if (!easy) if (!easy)
return; return;
...@@ -101,7 +101,7 @@ CurlRequest::FreeEasy() ...@@ -101,7 +101,7 @@ CurlRequest::FreeEasy()
} }
void void
CurlRequest::Resume() CurlRequest::Resume() noexcept
{ {
assert(registered); assert(registered);
...@@ -143,7 +143,7 @@ CurlRequest::FinishBody() ...@@ -143,7 +143,7 @@ CurlRequest::FinishBody()
} }
void void
CurlRequest::Done(CURLcode result) CurlRequest::Done(CURLcode result) noexcept
{ {
Stop(); Stop();
...@@ -180,7 +180,7 @@ IsResponseBoundaryHeader(StringView s) noexcept ...@@ -180,7 +180,7 @@ IsResponseBoundaryHeader(StringView s) noexcept
} }
inline void inline void
CurlRequest::HeaderFunction(StringView s) CurlRequest::HeaderFunction(StringView s) noexcept
{ {
if (state > State::HEADERS) if (state > State::HEADERS)
return; return;
...@@ -216,7 +216,8 @@ CurlRequest::HeaderFunction(StringView s) ...@@ -216,7 +216,8 @@ CurlRequest::HeaderFunction(StringView s)
} }
size_t 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; CurlRequest &c = *(CurlRequest *)stream;
...@@ -227,7 +228,7 @@ CurlRequest::_HeaderFunction(void *ptr, size_t size, size_t nmemb, void *stream) ...@@ -227,7 +228,7 @@ CurlRequest::_HeaderFunction(void *ptr, size_t size, size_t nmemb, void *stream)
} }
inline size_t 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); assert(received_size > 0);
...@@ -249,7 +250,8 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size) ...@@ -249,7 +250,8 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size)
} }
size_t 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; CurlRequest &c = *(CurlRequest *)stream;
...@@ -261,7 +263,7 @@ CurlRequest::WriteFunction(void *ptr, size_t size, size_t nmemb, void *stream) ...@@ -261,7 +263,7 @@ CurlRequest::WriteFunction(void *ptr, size_t size, size_t nmemb, void *stream)
} }
void void
CurlRequest::OnPostponeError() CurlRequest::OnPostponeError() noexcept
{ {
assert(postponed_error); assert(postponed_error);
......
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
*/ */
CurlRequest(CurlGlobal &_global, const char *url, CurlRequest(CurlGlobal &_global, const char *url,
CurlResponseHandler &_handler); CurlResponseHandler &_handler);
~CurlRequest(); ~CurlRequest() noexcept;
CurlRequest(const CurlRequest &) = delete; CurlRequest(const CurlRequest &) = delete;
CurlRequest &operator=(const CurlRequest &) = delete; CurlRequest &operator=(const CurlRequest &) = delete;
...@@ -91,16 +91,16 @@ public: ...@@ -91,16 +91,16 @@ public:
* *
* This method must be called in the event loop thread. * This method must be called in the event loop thread.
*/ */
void Start(); void Start() noexcept;
/** /**
* Unregister this request via CurlGlobal::Remove(). * Unregister this request via CurlGlobal::Remove().
* *
* This method must be called in the event loop thread. * This method must be called in the event loop thread.
*/ */
void Stop(); void Stop() noexcept;
CURL *Get() { CURL *Get() noexcept {
return easy.Get(); return easy.Get();
} }
...@@ -115,36 +115,36 @@ public: ...@@ -115,36 +115,36 @@ public:
*/ */
struct Pause {}; struct Pause {};
void Resume(); void Resume() noexcept;
/** /**
* A HTTP request is finished. Called by #CurlGlobal. * A HTTP request is finished. Called by #CurlGlobal.
*/ */
void Done(CURLcode result); void Done(CURLcode result) noexcept;
private: private:
/** /**
* Frees the current "libcurl easy" handle, and everything * Frees the current "libcurl easy" handle, and everything
* associated with it. * associated with it.
*/ */
void FreeEasy(); void FreeEasy() noexcept;
void FinishHeaders(); void FinishHeaders();
void FinishBody(); 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 */ /** called by curl when new data is available */
static size_t _HeaderFunction(void *ptr, size_t size, size_t nmemb, 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 */ /** called by curl when new data is available */
static size_t WriteFunction(void *ptr, size_t size, size_t nmemb, static size_t WriteFunction(void *ptr, size_t size, size_t nmemb,
void *stream); void *stream) noexcept;
}; };
#endif #endif
...@@ -41,26 +41,26 @@ class CurlSlist { ...@@ -41,26 +41,26 @@ class CurlSlist {
struct curl_slist *head = nullptr; struct curl_slist *head = nullptr;
public: public:
CurlSlist() = default; CurlSlist() noexcept = default;
CurlSlist(CurlSlist &&src) CurlSlist(CurlSlist &&src) noexcept
:head(std::exchange(src.head, nullptr)) {} :head(std::exchange(src.head, nullptr)) {}
~CurlSlist() { ~CurlSlist() noexcept {
if (head != nullptr) if (head != nullptr)
curl_slist_free_all(head); curl_slist_free_all(head);
} }
CurlSlist &operator=(CurlSlist &&src) { CurlSlist &operator=(CurlSlist &&src) noexcept {
std::swap(head, src.head); std::swap(head, src.head);
return *this; return *this;
} }
struct curl_slist *Get() { struct curl_slist *Get() noexcept {
return head; return head;
} }
void Clear() { void Clear() noexcept {
curl_slist_free_all(head); curl_slist_free_all(head);
head = nullptr; head = nullptr;
} }
......
...@@ -86,7 +86,7 @@ UPnPDeviceDirectory::Downloader::OnEnd() ...@@ -86,7 +86,7 @@ UPnPDeviceDirectory::Downloader::OnEnd()
} }
void void
UPnPDeviceDirectory::Downloader::OnError(std::exception_ptr e) UPnPDeviceDirectory::Downloader::OnError(std::exception_ptr e) noexcept
{ {
LogError(e); LogError(e);
Destroy(); Destroy();
......
...@@ -118,7 +118,7 @@ class UPnPDeviceDirectory final : UpnpCallback { ...@@ -118,7 +118,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
std::multimap<std::string, std::string> &&headers) override; std::multimap<std::string, std::string> &&headers) override;
void OnData(ConstBuffer<void> data) override; void OnData(ConstBuffer<void> data) override;
void OnEnd() override; void OnEnd() override;
void OnError(std::exception_ptr e) override; void OnError(std::exception_ptr e) noexcept override;
}; };
CurlInit curl; CurlInit curl;
......
...@@ -144,7 +144,7 @@ private: ...@@ -144,7 +144,7 @@ private:
} }
/* virtual methods from CurlResponseHandler */ /* 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); const std::lock_guard<Mutex> lock(mutex);
postponed_error = std::move(e); postponed_error = std::move(e);
SetDone(); SetDone();
......
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