xorp

AsyncFileWriter Class Reference

Write asynchronously to non-blocking file. More...

#include <asyncio.hh>

Inheritance diagram for AsyncFileWriter:
NONCOPYABLE AsyncFileOperator

List of all members.

Classes

class  BufferInfo

Public Member Functions

 AsyncFileWriter (EventLoop &e, XorpFd fd, uint32_t coalesce=1, int priority=XorpTask::PRIORITY_DEFAULT)
void add_buffer (const uint8_t *buffer, size_t buffer_bytes, const Callback &cb)
 Add an additional buffer for writing from.
void add_buffer_sendto (const uint8_t *buffer, size_t buffer_bytes, const IPvX &dst_addr, uint16_t dst_port, const Callback &cb)
 Add an additional buffer for writing from by using sendto(2).
void add_buffer_with_offset (const uint8_t *buffer, size_t buffer_bytes, size_t offset, const Callback &cb)
 Add an additional buffer for writing from.
void add_data (const vector< uint8_t > &data, const Callback &cb)
 Add additional data for writing from.
void add_data_sendto (const vector< uint8_t > &data, const IPvX &dst_addr, uint16_t dst_port, const Callback &cb)
 Add additional data for writing from by using sendto(2).
bool start ()
 Start asynchronous operation.
void stop ()
 Stop asynchronous operation.
size_t buffers_remaining () const
void flush_buffers ()
 Stop asynchronous operation and clear list of buffers.
virtual string toString () const

Protected Member Functions

void write (XorpFd, IoEventType)
void complete_transfer (ssize_t done)

Protected Attributes

uint32_t _coalesce
struct iovec * _iov
ref_ptr< int > _dtoken
list< BufferInfo * > _buffers

Detailed Description

Write asynchronously to non-blocking file.


Constructor & Destructor Documentation

AsyncFileWriter::AsyncFileWriter ( EventLoop e,
XorpFd  fd,
uint32_t  coalesce = 1,
int  priority = XorpTask::PRIORITY_DEFAULT 
)
Parameters:
eEventLoop that object should associate itself with.
fda file descriptor marked as non-blocking to write to.
coalescethe number of buffers to coalesce for each write() system call.

Member Function Documentation

void AsyncFileWriter::add_buffer ( const uint8_t *  buffer,
size_t  buffer_bytes,
const Callback cb 
)

Add an additional buffer for writing from.

Note that the buffer with the data is managed by the user.

Parameters:
bufferpointer to buffer.
buffer_bytessize of buffer in bytes.
cbCallback object to invoke when I/O is performed.
void AsyncFileWriter::add_buffer_sendto ( const uint8_t *  buffer,
size_t  buffer_bytes,
const IPvX dst_addr,
uint16_t  dst_port,
const Callback cb 
)

Add an additional buffer for writing from by using sendto(2).

Note that sendto()-buffers are never coalesced with other buffers.

Parameters:
bufferpointer to buffer.
buffer_bytessize of buffer in bytes.
dst_addrthe destination address to send the data to.
dst_portthe destination port (in host order) to send the data to.
cbCallback object to invoke when I/O is performed.
void AsyncFileWriter::add_buffer_with_offset ( const uint8_t *  buffer,
size_t  buffer_bytes,
size_t  offset,
const Callback cb 
)

Add an additional buffer for writing from.

Parameters:
bufferpointer to buffer.
buffer_bytessize of buffer in bytes.
offsetthe starting point to write from in the buffer.
cbCallback object to invoke when I/O is performed.
void AsyncFileWriter::add_data ( const vector< uint8_t > &  data,
const Callback cb 
)

Add additional data for writing from.

Note that the data is stored to write is stored internally by AsyncFileWriter.

Parameters:
datathe data to write.
cbCallback object to invoke when I/O is performed.
void AsyncFileWriter::add_data_sendto ( const vector< uint8_t > &  data,
const IPvX dst_addr,
uint16_t  dst_port,
const Callback cb 
)

Add additional data for writing from by using sendto(2).

Note that the data is stored to write is stored internally by AsyncFileWriter. Note that sendto()-buffers are never coalesced with other buffers.

Parameters:
datathe data to send.
dst_addrthe destination address to send the data to.
dst_portthe destination port (in host order) to send the data to.
cbCallback object to invoke when I/O is performed.
size_t AsyncFileWriter::buffers_remaining ( ) const [inline, virtual]
Returns:
the number of buffers available.

Implements AsyncFileOperator.

bool AsyncFileWriter::start ( ) [virtual]

Start asynchronous operation.

Returns:
true on success, false if no buffers are available.

Implements AsyncFileOperator.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations