@@ -457,6 +457,7 @@ class DataSink {
457
457
458
458
std::function<bool (const char *data, size_t data_len)> write;
459
459
std::function<bool ()> is_writable;
460
+ std::function<bool ()> is_alive;
460
461
std::function<void ()> done;
461
462
std::function<void (const Headers &trailer)> done_with_trailer;
462
463
std::ostream os;
@@ -639,6 +640,7 @@ class Stream {
639
640
640
641
virtual bool is_readable () const = 0;
641
642
virtual bool is_writable () const = 0;
643
+ virtual bool is_alive () const = 0;
642
644
643
645
virtual ssize_t read (char *ptr, size_t size) = 0;
644
646
virtual ssize_t write (const char *ptr, size_t size) = 0;
@@ -2135,6 +2137,7 @@ class BufferStream final : public Stream {
2135
2137
2136
2138
bool is_readable () const override ;
2137
2139
bool is_writable () const override ;
2140
+ bool is_alive () const override ;
2138
2141
ssize_t read (char *ptr, size_t size) override ;
2139
2142
ssize_t write (const char *ptr, size_t size) override ;
2140
2143
void get_remote_ip_and_port (std::string &ip, int &port) const override ;
@@ -2945,6 +2948,7 @@ class SocketStream final : public Stream {
2945
2948
2946
2949
bool is_readable () const override ;
2947
2950
bool is_writable () const override ;
2951
+ bool is_alive () const override ;
2948
2952
ssize_t read (char *ptr, size_t size) override ;
2949
2953
ssize_t write (const char *ptr, size_t size) override ;
2950
2954
void get_remote_ip_and_port (std::string &ip, int &port) const override ;
@@ -2975,6 +2979,7 @@ class SSLSocketStream final : public Stream {
2975
2979
2976
2980
bool is_readable () const override ;
2977
2981
bool is_writable () const override ;
2982
+ bool is_alive () const override ;
2978
2983
ssize_t read (char *ptr, size_t size) override ;
2979
2984
ssize_t write (const char *ptr, size_t size) override ;
2980
2985
void get_remote_ip_and_port (std::string &ip, int &port) const override ;
@@ -4088,6 +4093,7 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,
4088
4093
};
4089
4094
4090
4095
data_sink.is_writable = [&]() -> bool { return strm.is_writable (); };
4096
+ data_sink.is_alive = [&]() -> bool { return strm.is_alive (); };
4091
4097
4092
4098
while (offset < end_offset && !is_shutting_down ()) {
4093
4099
if (!strm.is_writable ()) {
@@ -4134,6 +4140,7 @@ write_content_without_length(Stream &strm,
4134
4140
};
4135
4141
4136
4142
data_sink.is_writable = [&]() -> bool { return strm.is_writable (); };
4143
+ data_sink.is_alive = [&]() -> bool { return strm.is_alive (); };
4137
4144
4138
4145
data_sink.done = [&](void ) { data_available = false ; };
4139
4146
@@ -4186,6 +4193,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
4186
4193
};
4187
4194
4188
4195
data_sink.is_writable = [&]() -> bool { return strm.is_writable (); };
4196
+ data_sink.is_alive = [&]() -> bool { return strm.is_alive (); };
4189
4197
4190
4198
auto done_with_trailer = [&](const Headers *trailer) {
4191
4199
if (!ok) { return ; }
@@ -5484,6 +5492,10 @@ inline bool SocketStream::is_writable() const {
5484
5492
is_socket_alive (sock_);
5485
5493
}
5486
5494
5495
+ inline bool SocketStream::is_alive () const {
5496
+ return is_socket_alive (sock_);
5497
+ }
5498
+
5487
5499
inline ssize_t SocketStream::read (char *ptr, size_t size) {
5488
5500
#ifdef _WIN32
5489
5501
size =
@@ -5558,6 +5570,8 @@ inline bool BufferStream::is_readable() const { return true; }
5558
5570
5559
5571
inline bool BufferStream::is_writable () const { return true ; }
5560
5572
5573
+ inline bool BufferStream::is_alive () const { return true ; }
5574
+
5561
5575
inline ssize_t BufferStream::read (char *ptr, size_t size) {
5562
5576
#if defined(_MSC_VER) && _MSC_VER < 1910
5563
5577
auto len_read = buffer._Copy_s (ptr, size, size, position);
@@ -8348,6 +8362,10 @@ inline bool SSLSocketStream::is_writable() const {
8348
8362
is_socket_alive (sock_);
8349
8363
}
8350
8364
8365
+ inline bool SSLSocketStream::is_alive () const {
8366
+ return is_socket_alive (sock_);
8367
+ }
8368
+
8351
8369
inline ssize_t SSLSocketStream::read (char *ptr, size_t size) {
8352
8370
if (SSL_pending (ssl_) > 0 ) {
8353
8371
return SSL_read (ssl_, ptr, static_cast <int >(size));
0 commit comments