class::fs::Aio

class fs::Aio
  : public api::FsWorkObject

The Asynchronous IO class is used for performing asynchronous operations on hardware devices. When calling synchronous IO, the read/write function is called and then returns when the operation is complete. With Asynchronous IO, the read/write function returns immediately and the Aio class can be used to see when the operation completes.

On Stratify OS, synchronous operations will always cause the running thread to yield the processor. This can be avoided by using the Aio class. Consider the following example:

#include <sapi/hal.hpp>
#include <sapi/sys.hpp>
#include <sapi/var.hpp>

int main(int argc, char * argv[]){
   String buf = "Hello World!\n";
   Uart uart(0); //we will read/write data to UART port 0
   Aio aio(buf.data(), buf.size()); //aio uses buf as it's data

   uart.init(); //init the UART with default settings

 //First a synchronous write
   uart.write(buf.c_str(), buf.size());  //this will return when the bytes are written
 //While bytes are writing, the processor will be used on another thread

 //Now the AIO version
   uart.write(aio);
 //This thread keeps the processor -- so we can do something else in parallel

   while( aio.done() == false ){
   Timer::wait_milliseconds(5); //wait for the operation to complete
   }

   return 0;
}

Summary

[Aio](#classfs_1_1_aio_1a4c5ec9d0405e15ceca31a0c464512b88)()

[Aio](#classfs_1_1_aio_1a4dead803498fd8b01eb90ad21e35c8d6)(  

const arg::SourceBuffer buf,
const arg::Size nbytes,
const arg::Location offset
)

[Aio](#classfs_1_1_aio_1a29d98b45422bfd65ec24ceeeb41ebbec)(  

arg::DestinationBuffer buf,
const arg::Size nbytes,
const arg::Location offset
)

void * buffer() const

int error()

bool is_busy() const

bool is_done() const

int nbytes() const

int offset() const

Aio & operator<<(

var::Data & data
)

Aio & refer_to(

const arg::DestinationBuffer & buf,
const arg::Size & nbytes
)

Aio & refer_to(

const arg::SourceBuffer & buf,
const arg::Size & nbytes
)

Aio & refer_to(

arg::DestinationData data
)

Aio & refer_to(

const arg::SourceData data
)

int ret()

Aio & set_offset(

int offset
)

Aio & set_signal(

int number,
int value
)

Aio & set_signal_number(

int number
)

Aio & set_signal_value(

int value
)

int suspend(

int timeout_usec
)

template<>
static Aio create_reference(

T & value,
const arg::Location offset
)

template<>
static Aio create_reference(

const T & value,
const arg::Location offset
)

static int suspend(

struct aiocb *const list,
int nent,
int timeout_usec
)

Members

Aio()

Constructs an empy AIO object.


Aio(

const arg::SourceBuffer buf,
const arg::Size nbytes,
const arg::Location offset
)

Constructs a new Aio object.

Parameters

  • buf The buffer for data transactions

  • nbytes The number of bytes to transfer on transactions

  • offset The file/device offset location


Aio(

arg::DestinationBuffer buf,
const arg::Size nbytes,
const arg::Location offset
)


void * buffer() const

Returns the buffer pointer.


int error()

Returns the error number of the operation.


bool is_busy() const

Returns true if operation is still in progress.


bool is_done() const

Returns true if operation is complete.


int nbytes() const

Returns the number of bytes to transfer.


int offset() const

Returns the offset (or channel for Dac, Adc, Pwm, etc).


Aio & operator<<(

var::Data & data
)


Aio & refer_to(

const arg::DestinationBuffer & buf,
const arg::Size & nbytes
)

Sets the buffer pointer.

Parameters

  • buf A pointer to the data buffer

  • nbytes The number of bytes to transfer


Aio & refer_to(

const arg::SourceBuffer & buf,
const arg::Size & nbytes
)


Aio & refer_to(

arg::DestinationData data
)

Sets the buffer using a var::Data object.

Parameters

  • data The data object

The data object must not change the buffer allocation after calling this method. If it does, it will need to set the buffer again.


Aio & refer_to(

const arg::SourceData data
)


int ret()

Returns the return value of the operation.


Aio & set_offset(

int offset
)

Sets the offset (or channcel for Dac, Adc, Pwm, etc).


Aio & set_signal(

int number,
int value
)

Causes the calling thread to receive a signal when the operation completes.

Parameters

  • number The signal number (ie SIGTERM) use -1 to prevent a signal from being sent

  • value The signal value (passed as an argument to the handler if using siginfo)

Returns

Zero on success


Aio & set_signal_number(

int number
)


Aio & set_signal_value(

int value
)


int suspend(

int timeout_usec
)

Blocks until the operation completes or timeout is reached.

Parameters

  • timeout_usec The timeout in microseconds (0 to block indefinitely)

template<>

static Aio create_reference(

T & value,
const arg::Location offset
)


template<>

static Aio create_reference(

const T & value,
const arg::Location offset
)


static int suspend(

struct aiocb *const list,
int nent,
int timeout_usec
)

Blocks until all transfers in list have completed or timeout is reached.

Parameters

  • list A list of AIO structures

  • nent The number of entities in the list

  • timeout_usec Timeout in microseconds to block (0 to block indefinitely)


X

Thanks for Coming!

Subscribe to news and updates