LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
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 
13 namespace 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 
48 namespace LC
49 {
50  UTIL_THREADS_API Util::detail::NRAwaiter operator co_await (QNetworkReply& reply)
51  {
52  return { reply };
53  }
54 }
NetworkResult await_resume() const noexcept
void await_suspend(std::coroutine_handle<> handle) noexcept
#define UTIL_THREADS_API
Definition: threadsconfig.h:16
bool await_ready() const noexcept
auto Tup2 &&tup2 noexcept
Definition: ctstringutils.h:41