Sane C++ Libraries
C++ Platform Abstraction Libraries
AsyncRequestStreams.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Async/Async.h"
5#include "AsyncStreams.h"
6
9namespace SC
10{
11template <typename AsyncRequestType>
13{
15
16 template <typename DescriptorType>
17 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& loop,
18 const DescriptorType& descriptor);
19
22
23 AsyncRequestType request;
24
25 protected:
26 struct Internal;
27
28 Result read();
29
30 void afterRead(typename AsyncRequestType::Result& result, AsyncBufferView::ID bufferID);
31 void onEndCloseDescriptor();
32};
33
34template <typename AsyncRequestType>
36{
38
39 template <typename DescriptorType>
40 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& loop,
41 const DescriptorType& descriptor);
42
45
46 AsyncRequestType request;
47
48 protected:
49 struct Internal;
50
51 Function<void(AsyncBufferView::ID)> callback;
52
53 Result write(AsyncBufferView::ID bufferID, Function<void(AsyncBufferView::ID)> cb);
54
55 void onEndCloseDescriptor();
56};
57
58// clang-format off
60struct ReadableFileStream : public AsyncRequestReadableStream<AsyncFileRead>{};
62struct WritableFileStream : public AsyncRequestWritableStream<AsyncFileWrite>{};
64struct ReadableSocketStream : public AsyncRequestReadableStream<AsyncSocketReceive>{};
66struct WritableSocketStream : public AsyncRequestWritableStream<AsyncSocketSend>{};
67// clang-format on
68
69} // namespace SC
Holds a Span of AsyncBufferView (allocated by user) holding available memory for the streams.
Definition: AsyncStreams.h:66
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition: Async.h:933
Async source abstraction emitting data events in caller provided byte buffers.
Definition: AsyncStreams.h:100
Definition: AsyncRequestStreams.h:13
Result registerAutoCloseDescriptor(bool value)
Registers or unregisters a listener to AsyncReadableStream::eventEnd to close descriptor.
Definition: AsyncRequestStreams.h:36
Result registerAutoCloseDescriptor(bool value)
Registers or unregisters a listener to AsyncWritableStream::eventFinish to close descriptor.
Async destination abstraction where bytes can be written to.
Definition: AsyncStreams.h:190
Wraps function pointers, member functions and lambdas without ever allocating.
Definition: Function.h:50
Uses an SC::AsyncFileRead to stream data from a file.
Definition: AsyncRequestStreams.h:60
Uses an SC::AsyncFileWrite to stream data from a socket.
Definition: AsyncRequestStreams.h:64
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition: Result.h:12
View over a contiguous sequence of items (pointer + size in elements).
Definition: Span.h:21
Uses an SC::AsyncFileWrite to stream data to a file.
Definition: AsyncRequestStreams.h:62
Uses an SC::AsyncFileWrite to stream data to a socket.
Definition: AsyncRequestStreams.h:66