|
26 | 26 | #include <trantor/utils/Logger.h> |
27 | 27 | #include <trantor/utils/MsgBuffer.h> |
28 | 28 | #include <trantor/utils/NonCopyable.h> |
| 29 | +#include <trantor/net/TcpConnection.h> |
29 | 30 | #include <algorithm> |
| 31 | +#include <functional> |
| 32 | +#include <memory> |
30 | 33 | #include <string> |
31 | | -#include <thread> |
| 34 | +#include <future> |
32 | 35 | #include <unordered_map> |
33 | 36 | #include <assert.h> |
34 | 37 | #include <stdio.h> |
@@ -97,6 +100,7 @@ class HttpRequestImpl : public HttpRequest |
97 | 100 | streamFinishCb_ = nullptr; |
98 | 101 | streamExceptionPtr_ = nullptr; |
99 | 102 | startProcessing_ = false; |
| 103 | + connPtr_.reset(); |
100 | 104 | } |
101 | 105 |
|
102 | 106 | trantor::EventLoop *getLoop() |
@@ -326,6 +330,11 @@ class HttpRequestImpl : public HttpRequest |
326 | 330 | peerCertificate_ = cert; |
327 | 331 | } |
328 | 332 |
|
| 333 | + void setConnectionPtr(const std::shared_ptr<trantor::TcpConnection> &ptr) |
| 334 | + { |
| 335 | + connPtr_ = ptr; |
| 336 | + } |
| 337 | + |
329 | 338 | void addHeader(const char *start, const char *colon, const char *end); |
330 | 339 |
|
331 | 340 | void removeHeader(std::string key) override |
@@ -554,6 +563,15 @@ class HttpRequestImpl : public HttpRequest |
554 | 563 | return keepAlive_; |
555 | 564 | } |
556 | 565 |
|
| 566 | + bool connected() const noexcept override |
| 567 | + { |
| 568 | + if (auto conn = connPtr_.lock()) |
| 569 | + { |
| 570 | + return conn->connected(); |
| 571 | + } |
| 572 | + return false; |
| 573 | + } |
| 574 | + |
557 | 575 | bool isOnSecureConnection() const noexcept override |
558 | 576 | { |
559 | 577 | return isOnSecureConnection_; |
@@ -705,6 +723,7 @@ class HttpRequestImpl : public HttpRequest |
705 | 723 | RequestStreamReaderPtr streamReaderPtr_; |
706 | 724 | std::exception_ptr streamExceptionPtr_; |
707 | 725 | bool startProcessing_{false}; |
| 726 | + std::weak_ptr<trantor::TcpConnection> connPtr_; |
708 | 727 |
|
709 | 728 | protected: |
710 | 729 | std::string content_; |
|
0 commit comments