LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
networkreply.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "networkreply.h"
10#include <QNetworkReply>
11#include "networkresult.h"
12
13namespace LC::Util::detail
14{
16 {
17 Reply_.deleteLater ();
18 }
19
20 bool NRAwaiter::await_ready () const noexcept
21 {
22 return Reply_.isFinished ();
23 }
24
25 void NRAwaiter::await_suspend (std::coroutine_handle<> handle) noexcept
26 {
27 FinishedConn_ = QObject::connect (&Reply_,
28 &QNetworkReply::finished,
29 handle);
30 ErrorConn_ = QObject::connect (&Reply_,
31 &QNetworkReply::errorOccurred,
32 [this, handle]
33 {
34 QObject::disconnect (std::move (FinishedConn_).Release ());
35 handle ();
36 });
37 }
38
40 {
41 if (Reply_.error () != QNetworkReply::NoError)
42 return NetworkReplyError { Reply_.error (), Reply_.errorString (), Reply_.url () };
43
44 return NetworkReplySuccess { Reply_.readAll (), Reply_.header (QNetworkRequest::LocationHeader) };
45 }
46}
47
48namespace LC
49{
50 UTIL_THREADS_API Util::detail::NRAwaiter operator co_await (QNetworkReply& reply)
51 {
52 return { reply };
53 }
54}
Definition constants.h:15
NetworkResult await_resume() const noexcept
bool await_ready() const noexcept
RaiiSignalConnection FinishedConn_
void await_suspend(std::coroutine_handle<> handle) noexcept
RaiiSignalConnection ErrorConn_
#define UTIL_THREADS_API