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...
 
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 (Function< void(AsyncResult &)> *afterStopped=nullptr)
 Ask to stop current async operation. More...
 
bool isFree () const
 Returns true if this request is free. More...
 
bool isCancelling () const
 Returns true if this request is being cancelled. More...
 
bool isActive () const
 Returns true if this request is active or being reactivated. More...
 
Type getType () const
 Returns request type. 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 ()
 
void queueSubmission (AsyncEventLoop &eventLoop)
 
- 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;
File::OpenOptions options;
options.blocking = false;
SC_TRY(File(fd).open("MyFile.txt", File::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:48
Result associateExternallyCreatedFileDescriptor(FileDescriptor &outDescriptor)
Associates a File descriptor created externally with the eventLoop.
AsyncResultOf< AsyncFileClose, CompletionData > Result
Callback result for AsyncFileClose.
Definition: Async.h:887
@ WriteCreateTruncate
Opens in write mode, creating or truncating it if another file exists at same location.
Definition: File.h:29
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition: Result.h:24

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: