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

Starts a file close operation, closing the OS file descriptor. More...

#include <Async.h>

Inheritance diagram for SC::AsyncFileClose:
SC::AsyncRequest

Public Types

using CompletionData = AsyncCompletionData
 Completion data for AsyncFileClose. More...
 
using Result = AsyncResultOf< AsyncFileClose, CompletionData >
 Callback result for AsyncFileClose. 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, FileDescriptor::Handle fileDescriptor)
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
AsyncEventLoopgetEventLoop () const
 Get 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...
 

Public Attributes

int code = 0
 Return code of close socket operation. More...
 
Function< void(Result &)> callback
 Callback called after fully closing the file descriptor. 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)
 
- Static Protected Member Functions inherited from SC::AsyncRequest
static void updateTime (AsyncEventLoop &loop)
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncEventLoopeventLoop = nullptr
 
AsyncTaskasyncTask = nullptr
 

Detailed Description

Starts a file close operation, closing the OS file descriptor.

Callback will be called when the file is actually closed.
File library can be used to open the file and obtain a blocking or non-blocking file descriptor handle.

// Assuming an already created (and running) AsyncEventLoop named eventLoop
// ...
// Open a file and associated it with event loop
FileDescriptor fd;
FileDescriptor::OpenOptions options;
options.blocking = false;
SC_TRY(fd.open("MyFile.txt", FileDescriptor::WriteCreateTruncate, options));
// Create the file close request
FileDescriptor::Handle handle;
SC_TRY(fd.get(handle, Result::Error("handle")));
AsyncFileClose asyncFileClose;
asyncFileClose.callback = [&](AsyncFileClose::Result& result)
{
if(result.isValid())
{
console.printLine("File was closed successfully");
}
};
SC_TRY(asyncFileClose.start(eventLoop, handle));
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:47
Result associateExternallyCreatedFileDescriptor(FileDescriptor &outDescriptor)
Associates a File descriptor created externally with the eventLoop.
AsyncResultOf< AsyncFileClose, CompletionData > Result
Callback result for AsyncFileClose.
Definition: Async.h:802
@ WriteCreateTruncate
Opens in write mode, creating or truncating it if another file exists at same location.
Definition: FileDescriptor.h:63
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition: Result.h:23

Member Typedef Documentation

◆ CompletionData

◆ Result

Member Data Documentation

◆ callback

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

Callback called after fully closing the file descriptor.

◆ code

int SC::AsyncFileClose::code = 0

Return code of close socket operation.


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