LeechCraft 0.6.70-16373-g319c272718
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 return Reply_.isFinished ();
18 }
19
20 void NRAwaiter::await_suspend (std::coroutine_handle<> handle) noexcept
21 {
22 auto finishedConn = QObject::connect (&Reply_,
23 &QNetworkReply::finished,
24 [=, this]
25 {
26 Reply_.deleteLater ();
27 handle ();
28 });
29 QObject::connect (&Reply_,
30 &QNetworkReply::errorOccurred,
31 [=, this]
32 {
33 QObject::disconnect (finishedConn);
34 Reply_.deleteLater ();
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}
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
Definition constants.h:15
NetworkResult await_resume() const noexcept
bool await_ready() const noexcept
void await_suspend(std::coroutine_handle<> handle) noexcept
#define UTIL_THREADS_API