LeechCraft  0.6.70-18450-gabe19ee3b0
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  Reply_.deleteLater ();
18  }
19 
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 
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:68