libcommonc++  0.7
AsyncIOTask Class Reference

An object representing an asynchronous I/O operation. More...

#include <AsyncIOTask.h++>

Public Member Functions

 AsyncIOTask ()
 Construct a new AsyncIOTask. More...
 
 ~AsyncIOTask ()
 Destructor. More...
 
bool isCompleted ()
 Determine if the asynchronous I/O task has completed (either successfully or with an error); and, if so, determine the result of the operation. More...
 
void cancel ()
 Attempt to cancel the asynchronous I/O task. More...
 
void waitFor (timespan_ms_t timeout)
 Wait for an asynchronous I/O task to complete. More...
 
size_t getBytesTransferred ()
 Get the number of bytes transferred by the I/O task. More...
 

Friends

class Stream
 
class AsyncIOPoller
 

Detailed Description

An object representing an asynchronous I/O operation.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ AsyncIOTask()

Construct a new AsyncIOTask.

The to collect the results of the task, either:

  • Periodically call isCompleted() until that method returns true, or
  • Call waitFor() to block until the operation completes.

◆ ~AsyncIOTask()

Destructor.

Member Function Documentation

◆ cancel()

void cancel ( )

Attempt to cancel the asynchronous I/O task.

Whether a given I/O task is actually cancellable is implementation-defined. Note that due to limitations in the Win32 API, on Windows versions prior to Vista this call will cancel all pending asynchronous I/O operations for the stream associated with this task.

Exceptions
IOExceptionIf the task could not be cancelled.

◆ getBytesTransferred()

size_t getBytesTransferred ( )

Get the number of bytes transferred by the I/O task.

This method should only be called after it has been determined that the task has completed via a call to isCompleted().

Returns
The number of bytes that were transferred. Returns 0 if the operation is still in progress, or if its result has not yet been collected via a call to isCompleted().

◆ isCompleted()

bool isCompleted ( )

Determine if the asynchronous I/O task has completed (either successfully or with an error); and, if so, determine the result of the operation.

If the I/O task involved a ByteBuffer, that buffer's position is bumped by the number of bytes that were transferred.

Returns
true if the task has completed; false if it is still in progress.
Exceptions
IOExceptionIf an I/O error occurred during the operation.
InterruptedExceptionIf the I/O task was cancelled via a call to cancel().

◆ waitFor()

void waitFor ( timespan_ms_t  timeout)

Wait for an asynchronous I/O task to complete.

Parameters
timeoutThe maximum amount of time to wait, in milliseconds.
Exceptions
TimeoutExceptionIf the operation times out.
IOExceptionIf an I/O error occurred during the operation.
InterruptedExceptionIf the I/O task was cancelled via a call to cancel().

Friends And Related Function Documentation

◆ AsyncIOPoller

friend class AsyncIOPoller
friend

◆ Stream

friend class Stream
friend

The documentation for this class was generated from the following files: