Starts a socket receive operation, receiving bytes from a remote endpoint. More...
#include <Async.h>
Classes | |
struct | CompletionData |
Completion data for AsyncSocketReceive. More... | |
struct | Result |
Callback result for AsyncSocketReceive. More... | |
Public Member Functions | |
SC::Result | start (AsyncEventLoop &eventLoop, const SocketDescriptor &socketDescriptor, Span< char > data) |
Starts a socket receive operation. More... | |
SC::Result | start (AsyncEventLoop &eventLoop) |
Starts a socket receive operation. More... | |
Public Member Functions inherited from SC::AsyncRequest | |
void | setDebugName (const char *newDebugName) |
AsyncEventLoop * | getEventLoop () const |
Get the event loop associated with this AsyncRequest. More... | |
void | cacheInternalEventLoop (AsyncEventLoop &loop) |
Caches the event loop associated with this AsyncRequest. More... | |
Result | setThreadPoolAndTask (ThreadPool &pool, AsyncTask &task) |
Sets the thread pool and task to use for this request. More... | |
void | resetThreadPoolAndTask () |
Resets anything previously set with setThreadPoolAndTask. More... | |
AsyncRequest (Type type) | |
Constructs a free async request of given type. More... | |
Result | stop () |
Stops the async operation. More... | |
bool | isFree () const |
Public Attributes | |
Function< void(Result &)> | callback |
Called after data has been received. More... | |
Span< char > | buffer |
The writeable span of memory where to data will be written. More... | |
SocketDescriptor::Handle | handle = SocketDescriptor::Invalid |
Public Attributes inherited from SC::AsyncRequest | |
AsyncRequest * | next = nullptr |
AsyncRequest * | prev = nullptr |
Additional Inherited Members | |
Public Types inherited from SC::AsyncRequest | |
enum class | Type : uint8_t { LoopTimeout , LoopWakeUp , LoopWork , ProcessExit , SocketAccept , SocketConnect , SocketSend , SocketReceive , SocketClose , FileRead , FileWrite , FileClose , FilePoll } |
Type of async request. More... | |
Protected Member Functions inherited from SC::AsyncRequest | |
Result | validateAsync () |
void | queueSubmission (AsyncEventLoop &eventLoop) |
Protected Attributes inherited from SC::AsyncRequest | |
AsyncEventLoop * | eventLoop = nullptr |
AsyncTask * | asyncTask = nullptr |
Starts a socket receive operation, receiving bytes from a remote endpoint.
Callback will be called when some data is read from socket.
Socket library can be used to create a Socket but the socket should be created with SC::SocketFlags::NonBlocking and associated to the event loop with SC::AsyncEventLoop::associateExternallyCreatedTCPSocket or though AsyncSocketAccept.
Alternatively SC::AsyncEventLoop::createAsyncTCPSocket creates and associates the socket to the loop.
Additional notes:
SC::Result SC::AsyncSocketReceive::start | ( | AsyncEventLoop & | eventLoop | ) |
Starts a socket receive operation.
Callback will be called when some data is read from socket.
eventLoop | The event loop where queuing this async request |
SC::Result SC::AsyncSocketReceive::start | ( | AsyncEventLoop & | eventLoop, |
const SocketDescriptor & | socketDescriptor, | ||
Span< char > | data | ||
) |
Starts a socket receive operation.
Callback will be called when some data is read from socket.
eventLoop | The event loop where queuing this async request |
socketDescriptor | The socket from which to receive data |
data | Span of memory where to write received bytes |
Span<char> SC::AsyncSocketReceive::buffer |
The writeable span of memory where to data will be written.