Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::AsyncSocketClose Struct Reference

Starts a socket close operation. More...

#include <Async.h>

Inheritance diagram for SC::AsyncSocketClose:
SC::AsyncRequest

Public Types

using CompletionData = AsyncCompletionData
 Completion data for AsyncSocketClose. More...
 
using Result = AsyncResultOf< AsyncSocketClose, CompletionData >
 Callback result for AsyncSocketClose. More...
 
- 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...
 

Public Member Functions

SC::Result start (AsyncEventLoop &eventLoop, const SocketDescriptor &socketDescriptor)
 Starts a socket close operation. More...
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
AsyncEventLoopgetEventLoop () const
 Get the event loop associated with this AsyncRequest. More...
 
void cacheInternalEventLoop (AsyncEventLoop &loop)
 Caches the event loop associated with this AsyncRequest. 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

int code = 0
 Return code of close socket operation. More...
 
Function< void(Result &)> callback
 Callback called after fully closing the socket. More...
 
- Public Attributes inherited from SC::AsyncRequest
AsyncRequestnext = nullptr
 
AsyncRequestprev = nullptr
 

Friends

struct AsyncEventLoop
 

Additional Inherited Members

- Protected Member Functions inherited from SC::AsyncRequest
Result validateAsync ()
 
Result queueSubmission (AsyncEventLoop &eventLoop)
 
Result queueSubmission (AsyncEventLoop &eventLoop, ThreadPool &threadPool, AsyncTask &task)
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncEventLoopeventLoop = nullptr
 
AsyncTaskasyncTask = nullptr
 

Detailed Description

Starts a socket close operation.

Callback will be called when the socket has been fully closed.

// Assuming an already created (and running) AsyncEventLoop named `eventLoop`
// and a connected or accepted socket named `client`
// ...
AsyncSocketClose asyncClose;
asyncClose.callback = [&](AsyncSocketClose::Result& result)
{
if(result.isValid())
{
console.printLine("Socket was closed successfully");
}
};
SC_TRY(asyncClose.start(eventLoop, client));
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:47
AsyncResultOf< AsyncSocketClose, CompletionData > Result
Callback result for AsyncSocketClose.
Definition: Async.h:660

Member Typedef Documentation

◆ CompletionData

◆ Result

Member Function Documentation

◆ start()

SC::Result SC::AsyncSocketClose::start ( AsyncEventLoop eventLoop,
const SocketDescriptor socketDescriptor 
)

Starts a socket close operation.

Callback will be called when the socket has been fully closed.

Parameters
eventLoopThe event loop where queuing this async request
socketDescriptorThe socket to be closed
Returns
Valid Result if the request has been successfully queued

Member Data Documentation

◆ callback

Function<void(Result&)> SC::AsyncSocketClose::callback

Callback called after fully closing the socket.

◆ code

int SC::AsyncSocketClose::code = 0

Return code of close socket operation.


The documentation for this struct was generated from the following file: