Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
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
18
19 AsyncRequestType request;
20 protected:
22 struct Internal;
23
24 Result read();
25
26 void afterRead(typename AsyncRequestType::Result& result, AsyncBufferView::ID bufferID);
27 void onEndCloseDescriptor();
28};
29
30template <typename AsyncRequestType>
32{
34
35 template <typename DescriptorType>
36 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& eventLoop,
37 const DescriptorType& descriptor);
38
41
42 AsyncRequestType request;
43
44 protected:
46 struct Internal;
47
48 Function<void(AsyncBufferView::ID)> callback;
49
50 Result write(AsyncBufferView::ID bufferID, Function<void(AsyncBufferView::ID)> cb);
51
52 void onEndCloseDescriptor();
53};
54
56struct ReadableFileStream : public AsyncRequestReadableStream<AsyncFileRead>
57{
58 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& eventLoop,
59 const FileDescriptor& descriptor);
60};
61
63struct WritableFileStream : public AsyncRequestWritableStream<AsyncFileWrite>
64{
65 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& eventLoop,
66 const FileDescriptor& descriptor);
67};
68
70struct ReadableSocketStream : public AsyncRequestReadableStream<AsyncSocketReceive>
71{
72 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& eventLoop,
73 const SocketDescriptor& descriptor);
74};
75
77struct WritableSocketStream : public AsyncRequestWritableStream<AsyncSocketSend>
78{
79 Result init(AsyncBuffersPool& buffersPool, Span<Request> requests, AsyncEventLoop& eventLoop,
80 const SocketDescriptor& descriptor);
81};
82
83} // 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:976
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.
AsyncEventLoop * eventLoop
AsyncFileRead / AsyncFileWrite / AsyncSocketReceive / AsyncSocketSend.
Definition AsyncRequestStreams.h:21
Definition AsyncRequestStreams.h:32
AsyncEventLoop * eventLoop
AsyncFileRead / AsyncFileWrite / AsyncSocketReceive / AsyncSocketSend.
Definition AsyncRequestStreams.h:45
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
File Descriptor (use SC::File to open and use it with strings and buffers).
Definition FileDescriptor.h:52
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
Uses an SC::AsyncFileRead to stream data from a file.
Definition AsyncRequestStreams.h:57
Uses an SC::AsyncFileWrite to stream data from a socket.
Definition AsyncRequestStreams.h:71
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
Low-level OS socket handle.
Definition SocketDescriptor.h:149
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:32
Uses an SC::AsyncFileWrite to stream data to a file.
Definition AsyncRequestStreams.h:64
Uses an SC::AsyncFileWrite to stream data to a socket.
Definition AsyncRequestStreams.h:78