Stream.h
1/* Copyright (C) 2026 by Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_HTTP_STREAM_H
6#define PT_HTTP_STREAM_H
7
8#include <Pt/Http/Api.h>
9#include <Pt/Connectable.h>
10#include <Pt/NonCopyable.h>
11#include <Pt/Signal.h>
12#include <string>
13#include <cstddef>
14#include <iosfwd>
15
16namespace Pt {
17
18namespace System {
19class EventLoop;
20}
21
22namespace Http {
23
24class Connection;
25class StreamSession;
26
88class PT_HTTP_API Stream : public Connectable
89 , private NonCopyable
90{
91 friend class Connection;
92 friend class StreamSession;
93
94 public:
101
104 bool isValid() const
105 { return _connection != 0; }
106
109 StreamSession* session() const
110 { return _session; }
111
114 const std::string& protocol() const
115 { return _protocolName; }
116
121 void close();
122
125 std::streambuf* buffer();
126
130
135 std::size_t endInput();
136
140
143 std::size_t endOutput();
144
147 void cancel();
148
151 void setTimeout(std::size_t ms);
152
158
162 { return _inputReady; }
163
167 { return _outputReady; }
168
169 protected:
170 Stream(Connection& connection, const std::string& protocol);
171
172 void openSession(StreamSession& session);
173
174 void closeSession(StreamSession& session);
175
176 private:
177 Connection* _connection;
178 StreamSession* _session;
179 std::string _protocolName;
180 Signal<> _inputReady;
181 Signal<> _outputReady;
182};
183
184} // namespace Http
185
186} // namespace Pt
187
188#endif // PT_HTTP_STREAM_H
Connectable()
Default constructor.
Represents a connection between a Signal/Delegate and a slot.
Definition Connection.h:96
Binds one session object to one HTTP stream.
Definition StreamSession.h:54
One HTTP stream on a connection.
Definition Stream.h:90
void cancel()
Cancels a pending transfer of this stream.
~Stream()
Destructor.
StreamSession * session() const
Returns the bound stream session, or null.
Definition Stream.h:109
void setTimeout(std::size_t ms)
Sets the stream timeout in milliseconds.
const std::string & protocol() const
Returns the Upgrade header value.
Definition Stream.h:114
void close()
Ends this stream.
bool isValid() const
Returns true when the connection still owns this stream.
Definition Stream.h:104
Signal & inputReady()
Returns the signal emitted when input is ready.
Definition Stream.h:161
System::EventLoop * loop() const
Returns the event loop of the owning connection.
std::streambuf * buffer()
Returns the stream buffer of the connection.
void beginOutput()
Begins a write of the bytes buffered in buffer().
std::size_t endInput()
Completes the read started by beginInput().
std::size_t endOutput()
Completes the write started by beginOutput().
void beginInput()
Begins a read into the stream buffer.
Signal & outputReady()
Returns the signal emitted when output is ready.
Definition Stream.h:166
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Multicast Signal to call multiple slots.
Definition Signal.h:190
Event loop of a thread or process.
Definition EventLoop.h:83
HTTP clients and servers.
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33