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>
12struct SC_COMPILER_EXPORT AsyncRequestReadableStream : public AsyncReadableStream
13{
15
17 void setAutoCloseDescriptor(bool value) { autoCloseDescriptor = value; }
18
19 AsyncRequestType request;
20 protected:
21 struct Internal;
22 AsyncEventLoop* eventLoop = nullptr;
23
24 bool autoCloseDescriptor = false;
25 bool justUnrefBuffer = false;
26
27 Result read();
28
29 void afterRead(typename AsyncRequestType::Result& result, AsyncBufferView::ID bufferID);
30 void onCloseStopRequest();
31};
32
33template <typename AsyncRequestType>
34struct SC_COMPILER_EXPORT AsyncRequestWritableStream : public AsyncWritableStream
35{
37
38 template <typename DescriptorType>
39 Result init(AsyncBuffersPool& buffersPool, AsyncEventLoop& eventLoop, const DescriptorType& descriptor);
40
42 void setAutoCloseDescriptor(bool value) { autoCloseDescriptor = value; }
43
44 AsyncRequestType request;
45
46 protected:
47 struct Internal;
48 AsyncEventLoop* eventLoop = nullptr;
49
50 bool autoCloseDescriptor = false;
51 bool justUnrefBuffer = false;
52
53 Function<void(AsyncBufferView::ID)> callback;
54
55 Result write(AsyncBufferView::ID bufferID, Function<void(AsyncBufferView::ID)> cb);
56
57 void onFinishStopRequest();
58};
59
61struct SC_COMPILER_EXPORT ReadableFileStream : public AsyncRequestReadableStream<AsyncFileRead>
62{
63 Result init(AsyncBuffersPool& buffersPool, AsyncEventLoop& eventLoop, const FileDescriptor& descriptor);
64};
65
67struct SC_COMPILER_EXPORT WritableFileStream : public AsyncRequestWritableStream<AsyncFileWrite>
68{
69 Result init(AsyncBuffersPool& buffersPool, AsyncEventLoop& eventLoop, const FileDescriptor& descriptor);
70};
71
73struct SC_COMPILER_EXPORT ReadableSocketStream : public AsyncRequestReadableStream<AsyncSocketReceive>
74{
75 Result init(AsyncBuffersPool& buffersPool, AsyncEventLoop& eventLoop, const SocketDescriptor& descriptor);
76};
77
79struct SC_COMPILER_EXPORT WritableSocketStream : public AsyncRequestWritableStream<AsyncSocketSend>
80{
81 Result init(AsyncBuffersPool& buffersPool, AsyncEventLoop& eventLoop, const SocketDescriptor& descriptor);
82};
83
84} // namespace SC
struct SC_COMPILER_EXPORT Function
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
Definition AsyncStreams.h:52
Holds a Span of AsyncBufferView (allocated by user) holding available memory for the streams.
Definition AsyncStreams.h:140
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1195
Async source abstraction emitting data events in caller provided byte buffers.
Definition AsyncStreams.h:187
Definition AsyncRequestStreams.h:13
void setAutoCloseDescriptor(bool value)
Automatically closes descriptor during read stream close event.
Definition AsyncRequestStreams.h:17
Definition AsyncRequestStreams.h:35
void setAutoCloseDescriptor(bool value)
Automatically closes descriptor during write stream finish event.
Definition AsyncRequestStreams.h:42
Async destination abstraction where bytes can be written to.
Definition AsyncStreams.h:284
[UniqueHandleDeclaration2Snippet]
Definition File.h:78
Uses an SC::AsyncFileRead to stream data from a file.
Definition AsyncRequestStreams.h:62
Uses an SC::AsyncFileWrite to stream data from a socket.
Definition AsyncRequestStreams.h:74
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
Low-level OS socket handle.
Definition Socket.h:153
Uses an SC::AsyncFileWrite to stream data to a file.
Definition AsyncRequestStreams.h:68
Uses an SC::AsyncFileWrite to stream data to a socket.
Definition AsyncRequestStreams.h:80