aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
ChannelHandler.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/Exports.h>
8#include <aws/crt/Types.h>
9#include <aws/io/channel.h>
10
11#include <chrono>
12#include <cstddef>
13
14struct aws_array_list;
15struct aws_io_message;
16
17namespace Aws
18{
19 namespace Crt
20 {
21 namespace Io
22 {
24 {
25 Read,
26 Write,
27 };
28
29 enum class MessageType
30 {
32 };
33
34 enum class TaskStatus
35 {
38 };
39
47 {
48 public:
49 virtual ~ChannelHandler() = default;
50
51 ChannelHandler(const ChannelHandler &) = delete;
53
54 protected:
68 virtual int ProcessReadMessage(struct aws_io_message *message) = 0;
69
79 virtual int ProcessWriteMessage(struct aws_io_message *message) = 0;
80
89 virtual int IncrementReadWindow(size_t size) = 0;
90
103 virtual void ProcessShutdown(
105 int errorCode,
106 bool freeScarceResourcesImmediately) = 0;
107
111 virtual size_t InitialWindowSize() = 0;
112
117 virtual size_t MessageOverhead() = 0;
118
122 virtual void ResetStatistics() {};
123
128 virtual void GatherStatistics(struct aws_array_list *) {}
129
130 public:
132 struct aws_channel_handler *SeatForCInterop(const std::shared_ptr<ChannelHandler> &selfRef);
133
137 bool ChannelsThreadIsCallersThread() const;
138
144 void ShutDownChannel(int errorCode);
145
150 void ScheduleTask(std::function<void(TaskStatus)> &&task);
151
157 void ScheduleTask(std::function<void(TaskStatus)> &&task, std::chrono::nanoseconds run_in);
158
159 protected:
160 ChannelHandler(Allocator *allocator = ApiAllocator());
161
165 struct aws_io_message *AcquireMessageFromPool(MessageType messageType, size_t sizeHint);
166
172 struct aws_io_message *AcquireMaxSizeMessageForWrite();
173
179 bool SendMessage(struct aws_io_message *message, ChannelDirection direction);
180
185 bool IncrementUpstreamReadWindow(size_t windowUpdateSize);
186
191 void OnShutdownComplete(ChannelDirection direction, int errorCode, bool freeScarceResourcesImmediately);
192
198 size_t DownstreamReadWindow() const;
199
204 size_t UpstreamMessageOverhead() const;
205
206 struct aws_channel_slot *GetSlot() const;
207
208 struct aws_channel_handler m_handler;
210
211 private:
212 std::shared_ptr<ChannelHandler> m_selfReference;
213 static struct aws_channel_handler_vtable s_vtable;
214
215 static void s_Destroy(struct aws_channel_handler *handler);
216 static int s_ProcessReadMessage(
217 struct aws_channel_handler *,
218 struct aws_channel_slot *,
219 struct aws_io_message *);
220 static int s_ProcessWriteMessage(
221 struct aws_channel_handler *,
222 struct aws_channel_slot *,
223 struct aws_io_message *);
224 static int s_IncrementReadWindow(struct aws_channel_handler *, struct aws_channel_slot *, size_t size);
225 static int s_ProcessShutdown(
226 struct aws_channel_handler *,
227 struct aws_channel_slot *,
228 enum aws_channel_direction,
229 int errorCode,
230 bool freeScarceResourcesImmediately);
231 static size_t s_InitialWindowSize(struct aws_channel_handler *);
232 static size_t s_MessageOverhead(struct aws_channel_handler *);
233 static void s_ResetStatistics(struct aws_channel_handler *);
234 static void s_GatherStatistics(struct aws_channel_handler *, struct aws_array_list *statsList);
235 };
236 } // namespace Io
237 } // namespace Crt
238} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition ChannelHandler.h:47
virtual void ProcessShutdown(ChannelDirection dir, int errorCode, bool freeScarceResourcesImmediately)=0
virtual int ProcessWriteMessage(struct aws_io_message *message)=0
virtual size_t MessageOverhead()=0
virtual void GatherStatistics(struct aws_array_list *)
Definition ChannelHandler.h:128
ChannelHandler(const ChannelHandler &)=delete
virtual int ProcessReadMessage(struct aws_io_message *message)=0
virtual void ResetStatistics()
Definition ChannelHandler.h:122
Allocator * m_allocator
Definition ChannelHandler.h:209
virtual int IncrementReadWindow(size_t size)=0
virtual ~ChannelHandler()=default
ChannelHandler & operator=(const ChannelHandler &)=delete
virtual size_t InitialWindowSize()=0
ChannelDirection
Definition ChannelHandler.h:24
MessageType
Definition ChannelHandler.h:30
TaskStatus
Definition ChannelHandler.h:35
aws_allocator Allocator
Definition Allocator.h:14
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
Definition Allocator.h:11