LeechCraft 0.6.70-19424-g027e980fd1
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 &Reply_,
30 handle);
31 ErrorConn_ = QObject::connect (&Reply_,
32 &QNetworkReply::errorOccurred,
33 &Reply_,
34 [this, handle]
35 {
36 QObject::disconnect (std::move (FinishedConn_).Release ());
37 handle ();
38 });
39 }
40
42 {
43 if (Reply_.error () != QNetworkReply::NoError)
44 return NetworkReplyError { Reply_.error (), Reply_.errorString (), Reply_.url () };
45
46 return NetworkReplySuccess { Reply_.readAll (), Reply_.header (QNetworkRequest::LocationHeader) };
47 }
48}
NetworkResult await_resume() const noexcept
bool await_ready() const noexcept
RaiiSignalConnection FinishedConn_
void await_suspend(std::coroutine_handle<> handle) noexcept
RaiiSignalConnection ErrorConn_