#include <vpr/IO/BlockIO.h>
Inheritance diagram for vpr::BlockIO:


Public Member Functions | |
| virtual const std::string & | getName () const |
| Gets the name of this I/O device. | |
| virtual ReturnStatus | open ()=0 |
| Opens the I/O device. | |
| virtual ReturnStatus | close ()=0 |
| Closes the I/O device. | |
| virtual bool | isOpen () const |
| Gets the open state of this I/O device. | |
| virtual ReturnStatus | setBlocking (bool blocking)=0 |
| Reconfigures the I/O device so that it is in blocking or non-blocking mode depending on the given parameter. | |
| virtual bool | isBlocking () const |
| Gets the current blocking state for the I/O device. | |
| virtual IOSys::Handle | getHandle () const=0 |
| Gets the vpr::IOSys::Handle object for this I/O device. | |
| vpr::ReturnStatus | read (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads at most the specified number of bytes from the I/O device into the given buffer. | |
| vpr::ReturnStatus | read (std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads at most the specified number of bytes from the I/O device into the given buffer. | |
| vpr::ReturnStatus | read (std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads at most the specified number of bytes from the I/O device into the given buffer. | |
| vpr::ReturnStatus | readn (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads exactly the specified number of bytes from the I/O device into the given buffer. | |
| vpr::ReturnStatus | readn (std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads exactly the specified number of bytes from the I/O device into the given buffer. | |
| vpr::ReturnStatus | readn (std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Reads exactly the specified number of bytes from the I/O device into the given buffer. | |
| virtual vpr::Uint32 | availableBytes () const |
| Return the number of avaiable bytes for reading. | |
| vpr::ReturnStatus | write (const void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Write the buffer to the I/O device. | |
| vpr::ReturnStatus | write (const std::string &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Writes the buffer to the I/O device. | |
| vpr::ReturnStatus | write (const std::vector< vpr::Uint8 > &buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Writes the buffer to the I/O device. | |
| bool | isReadBlocked (const vpr::Interval &timeout=vpr::Interval::NoWait) |
| Tests if reading from this I/O device will block. | |
| bool | isWriteBlocked (const vpr::Interval &timeout=vpr::Interval::NoWait) |
| Tests if writing to this I/O device will block. | |
| void | setIOStatStrategy (vpr::BaseIOStatsStrategy *strat) |
| Sets the IO stats strategy to use. | |
| vpr::BaseIOStatsStrategy * | getIOStatStrategy () const |
| Gets the current IO stats strategy. | |
Protected Member Functions | |
| BlockIO () | |
| Default constructor. | |
| BlockIO (const std::string &name) | |
| Constructor. | |
| BlockIO (const BlockIO &other) | |
| Copy constructor. | |
| virtual | ~BlockIO () |
| Destructor. | |
| virtual vpr::ReturnStatus | read_s (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Read strategy. | |
| virtual vpr::ReturnStatus | readn_s (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Read strategy. | |
| virtual vpr::ReturnStatus | write_s (const void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Write strategy. | |
| virtual vpr::ReturnStatus | read_i (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)=0 |
| Implementation of the read() template method. | |
| virtual vpr::ReturnStatus | readn_i (void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesRead, const vpr::Interval timeout=vpr::Interval::NoTimeout)=0 |
| Implementation of the readn() template method. | |
| virtual vpr::ReturnStatus | write_i (const void *buffer, const vpr::Uint32 length, vpr::Uint32 &bytesWritten, const vpr::Interval timeout=vpr::Interval::NoTimeout)=0 |
| Implementation of the write() template method. | |
Protected Attributes | |
| std::string | mName |
| The name of the I/O device. | |
| bool | mOpen |
| Flag telling if the device is open. | |
| bool | mBlocking |
| Flag telling if blocking for reads and writes is enabled. | |
| vpr::BaseIOStatsStrategy * | mStatsStrategy |
| Perf monitor. | |
Friends | |
| class | vpr::BaseIOStatsStrategy |
Definition at line 67 of file BlockIO.h.
| vpr::BlockIO::BlockIO | ( | ) | [protected] |
Default constructor.
This is provided for subclasses where a "named" device does not make sense.
Definition at line 104 of file BlockIO.cpp.
00105 : mOpen(false) 00106 , mBlocking(true) 00107 , mStatsStrategy(NULL) 00108 { 00109 /* Do nothing. */ ; 00110 }
| vpr::BlockIO::BlockIO | ( | const std::string & | name | ) | [protected] |
Constructor.
mName; the open mode is set to blocking; the open state is set to false; and the blocking mode for reads and writes is set to true.| name | The name for this device. |
Definition at line 112 of file BlockIO.cpp.
00113 : mName(name) 00114 , mOpen(false) 00115 , mBlocking(true) 00116 , mStatsStrategy(NULL) 00117 { 00118 /* Do nothing. */ ; 00119 }
| vpr::BlockIO::BlockIO | ( | const BlockIO & | other | ) | [protected] |
Copy constructor.
| other | A constant reference to another vpr::BlockIO object used as the source for the copy. |
Definition at line 121 of file BlockIO.cpp.
00122 : mName(other.mName) 00123 , mOpen(other.mOpen) 00124 , mBlocking(other.mBlocking) 00125 , mStatsStrategy(NULL) 00126 { 00127 /* Do nothing. */ ; 00128 }
| vpr::BlockIO::~BlockIO | ( | ) | [protected, virtual] |
| virtual const std::string& vpr::BlockIO::getName | ( | ) | const [inline, virtual] |
Gets the name of this I/O device.
The significance of the name depends on the specific device type.
mName object is returned to the caller.Reimplemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Definition at line 80 of file BlockIO.h.
00081 { 00082 return mName; 00083 }
| virtual ReturnStatus vpr::BlockIO::open | ( | ) | [pure virtual] |
Opens the I/O device.
mOpen is set to true.vpr::ReturnStatus::Fail is returned otherwise.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
| virtual ReturnStatus vpr::BlockIO::close | ( | ) | [pure virtual] |
Closes the I/O device.
mOpen is set to false.vpr::ReturnStatus::Fail is returned otherwise.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
| virtual bool vpr::BlockIO::isOpen | ( | ) | const [inline, virtual] |
Gets the open state of this I/O device.
mOpen is returned to the caller.true is returned if the device is open; false otherwise. Reimplemented in vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Definition at line 122 of file BlockIO.h.
00123 { 00124 return mOpen; 00125 }
| virtual ReturnStatus vpr::BlockIO::setBlocking | ( | bool | blocking | ) | [pure virtual] |
Reconfigures the I/O device so that it is in blocking or non-blocking mode depending on the given parameter.
If the device has not been opened yet, it will be opened in blocking or non-blocking mode appropriately when open() is called.
| blocking | A true value puts the I/O device into blocking mode. A false value puts it into non-blocking mode. |
vpr::ReturnStatus::Fail is returned otherwise.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
| virtual bool vpr::BlockIO::isBlocking | ( | ) | const [inline, virtual] |
Gets the current blocking state for the I/O device.
mBlocking is set correctly.Reimplemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Definition at line 152 of file BlockIO.h.
00153 { 00154 return mBlocking; 00155 }
| virtual IOSys::Handle vpr::BlockIO::getHandle | ( | ) | const [pure virtual] |
Gets the vpr::IOSys::Handle object for this I/O device.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Referenced by isReadBlocked(), and isWriteBlocked().
| vpr::ReturnStatus vpr::BlockIO::read | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads at most the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead argument.| buffer | A pointer to the buffer where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 192 of file BlockIO.h.
Referenced by vpr::Socket_t< SocketConfig_ >::recv().
00195 { 00196 return this->read_s(buffer, length, bytesRead, timeout); 00197 }
| vpr::ReturnStatus vpr::BlockIO::read | ( | std::string & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads at most the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead argument.| buffer | A reference to the buffer (a std::string object) where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 225 of file BlockIO.h.
00228 { 00229 vpr::ReturnStatus status; 00230 00231 // Allocate the temporary buffer, zero it, and read in the current 00232 // buffer from the device. 00233 buffer.resize(length); 00234 memset(&buffer[0], '\0', buffer.size()); 00235 status = this->read(&buffer[0], buffer.size(), bytesRead, timeout); 00236 00237 return status; 00238 }
| vpr::ReturnStatus vpr::BlockIO::read | ( | std::vector< vpr::Uint8 > & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads at most the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead argument.| buffer | A pointer to the buffer (a vector of vpr::Uint8 values) where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 267 of file BlockIO.h.
00270 { 00271 vpr::ReturnStatus status; 00272 buffer.resize(length); 00273 00274 // Allocate the temporary buffer, zero it, and read in the current 00275 // buffer from the device. 00276 memset(&buffer[0], '\0', buffer.size()); 00277 status = this->read(&buffer[0], buffer.size(), bytesRead, timeout); 00278 00279 // size it down if needed, if (bytesRead == length), then resize does 00280 // nothing... 00281 if ( status.success() ) 00282 { 00283 buffer.resize(bytesRead); 00284 } 00285 00286 return status; 00287 }
| vpr::ReturnStatus vpr::BlockIO::readn | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads exactly the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.| buffer | A pointer to the buffer where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 313 of file BlockIO.h.
Referenced by vpr::Socket_t< SocketConfig_ >::recvn().
00316 { 00317 return this->readn_s(buffer, length, bytesRead, timeout); 00318 }
| vpr::ReturnStatus vpr::BlockIO::readn | ( | std::string & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads exactly the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.| buffer | A reference to the buffer (a std::string object) where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 344 of file BlockIO.h.
00347 { 00348 vpr::ReturnStatus status; 00349 00350 // Allocate the temporary buffer, zero it, and read in the current 00351 // buffer from the device. 00352 buffer.resize(length); 00353 memset(&buffer[0], '\0', buffer.size()); 00354 status = this->readn(&buffer[0], buffer.size(), bytesRead, timeout); 00355 00356 if ( status.success() ) 00357 { 00358 buffer.resize(bytesRead); 00359 } 00360 00361 return status; 00362 }
| vpr::ReturnStatus vpr::BlockIO::readn | ( | std::vector< vpr::Uint8 > & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Reads exactly the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller.| buffer | A pointer to the buffer (a vector of vpr::Uint8 values) where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Definition at line 391 of file BlockIO.h.
00394 { 00395 vpr::ReturnStatus status; 00396 00397 // Allocate the temporary buffer, zero it, and read in the current 00398 // buffer from the device. 00399 00400 buffer.resize(length); 00401 memset(&buffer[0], '\0', buffer.size()); 00402 status = this->readn(&buffer[0], buffer.size(), bytesRead, timeout); 00403 00404 if ( status.success() ) 00405 { 00406 buffer.resize(bytesRead); 00407 } 00408 00409 return status; 00410 }
| virtual vpr::Uint32 vpr::BlockIO::availableBytes | ( | ) | const [inline, virtual] |
Return the number of avaiable bytes for reading.
Reimplemented in vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Definition at line 413 of file BlockIO.h.
| vpr::ReturnStatus vpr::BlockIO::write | ( | const void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesWritten, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Write the buffer to the I/O device.
bytesWritten parameter.| buffer | A pointer to the buffer to be written. | |
| length | The length of the buffer. | |
| bytesWritten | The number of bytes written to the device. | |
| timeout | The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the write operation could not be completed.
vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the write operation failed.
Definition at line 443 of file BlockIO.h.
Referenced by vpr::Socket_t< SocketConfig_ >::send().
00446 { 00447 return this->write_s(buffer, length, bytesWritten,timeout); 00448 }
| vpr::ReturnStatus vpr::BlockIO::write | ( | const std::string & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesWritten, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Writes the buffer to the I/O device.
bytesWritten parameter.| buffer | A reference to the buffer (a std::string object) to be written. | |
| length | The length of the buffer. | |
| bytesWritten | The number of bytes written to the device. | |
| timeout | The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the write operation could not be completed.
vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the write operation failed.
Definition at line 476 of file BlockIO.h.
References vprASSERT.
00479 { 00480 vprASSERT(length <= buffer.size() && "length was bigger than the data given"); 00481 return this->write(buffer.c_str(), length, bytesWritten,timeout); 00482 }
| vpr::ReturnStatus vpr::BlockIO::write | ( | const std::vector< vpr::Uint8 > & | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesWritten, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [inline] |
Writes the buffer to the I/O device.
bytesWritten parameter.| buffer | A pointer to the buffer (a vector of vpr::Uint8 values) to be written. | |
| length | The length of the buffer. | |
| bytesWritten | The number of bytes written to the device. | |
| timeout | The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock is returned if the handle is in non-blocking mode, and the write operation could not be completed.
vpr::ReturnStatus::Timeout is returned if the write could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the write operation failed.
Definition at line 510 of file BlockIO.h.
References vprASSERT.
00514 { 00515 vprASSERT(length <= buffer.size() && "length was bigger than the data given"); 00516 return this->write(&buffer[0], length, bytesWritten,timeout); 00517 }
| bool vpr::BlockIO::isReadBlocked | ( | const vpr::Interval & | timeout = vpr::Interval::NoWait |
) |
Tests if reading from this I/O device will block.
| timeout | Give a timeout period to wait for the device to unblock for reading. This is optional and defaults to vpr::Interval::NoWait which will simply poll the device and return immediately. |
true is returned if reading will block; false otherwise. Definition at line 50 of file BlockIO.cpp.
References vpr::Selector_t< RealSelectorImp >::addHandle(), getHandle(), vpr::SelectorBase::Read, vpr::Selector_t< RealSelectorImp >::select(), and vpr::Selector_t< RealSelectorImp >::setIn().
00051 { 00052 bool is_blocked; 00053 vpr::Selector selector; 00054 vpr::IOSys::Handle handle; 00055 vpr::Uint16 num_events; 00056 vpr::ReturnStatus status; 00057 00058 handle = getHandle(); 00059 selector.addHandle(handle); 00060 selector.setIn(handle, vpr::Selector::Read); 00061 00062 // Test the handle to get its read state. 00063 status = selector.select(num_events, timeout); 00064 00065 if ( num_events == 1 ) 00066 { 00067 is_blocked = false; 00068 } 00069 else 00070 { 00071 is_blocked = true; 00072 } 00073 00074 return is_blocked; 00075 }
| bool vpr::BlockIO::isWriteBlocked | ( | const vpr::Interval & | timeout = vpr::Interval::NoWait |
) |
Tests if writing to this I/O device will block.
| timeout | Give a timeout period to wait for the device to unblock for writing. This is optional and defaults to vpr::Interval::NoWait which will simply poll the device and return immediately. |
true is returned if writing will block; false otherwise. Definition at line 77 of file BlockIO.cpp.
References vpr::Selector_t< RealSelectorImp >::addHandle(), getHandle(), vpr::Selector_t< RealSelectorImp >::select(), vpr::Selector_t< RealSelectorImp >::setIn(), and vpr::SelectorBase::Write.
00078 { 00079 bool is_blocked; 00080 vpr::Selector selector; 00081 vpr::IOSys::Handle handle; 00082 vpr::Uint16 num_events; 00083 vpr::ReturnStatus status; 00084 00085 handle = getHandle(); 00086 selector.addHandle(handle); 00087 selector.setIn(handle, vpr::Selector::Write); 00088 00089 // Test the handle to get its write state. 00090 status = selector.select(num_events, timeout); 00091 00092 if ( num_events == 1 ) 00093 { 00094 is_blocked = false; 00095 } 00096 else 00097 { 00098 is_blocked = true; 00099 } 00100 00101 return is_blocked; 00102 }
| void vpr::BlockIO::setIOStatStrategy | ( | vpr::BaseIOStatsStrategy * | strat | ) | [inline] |
Sets the IO stats strategy to use.
Definition at line 554 of file BlockIO.h.
References vpr::BaseIOStatsStrategy::setRealObject().
Referenced by vpr::Socket_t< SocketConfig_ >::initSocket_t().
00555 { 00556 mStatsStrategy = strat; 00557 if(mStatsStrategy != NULL) // If we have a non-NULL strategy 00558 { 00559 mStatsStrategy->setRealObject(this); // Tell it about us 00560 } 00561 }
| vpr::BaseIOStatsStrategy* vpr::BlockIO::getIOStatStrategy | ( | ) | const [inline] |
Gets the current IO stats strategy.
Definition at line 566 of file BlockIO.h.
00567 { 00568 return mStatsStrategy; 00569 }
| vpr::ReturnStatus vpr::BlockIO::read_s | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, virtual] |
Read strategy.
Definition at line 135 of file BlockIO.cpp.
References mStatsStrategy, read_i(), and vpr::BaseIOStatsStrategy::read_s().
00138 { 00139 vpr::ReturnStatus status; 00140 00141 if(mStatsStrategy != NULL) 00142 { 00143 mStatsStrategy->read_s(status, buffer, length, bytesRead, timeout); 00144 } 00145 else 00146 { 00147 status = read_i(buffer, length, bytesRead, timeout); 00148 } 00149 00150 return status; 00151 }
| vpr::ReturnStatus vpr::BlockIO::readn_s | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, virtual] |
Read strategy.
Definition at line 153 of file BlockIO.cpp.
References mStatsStrategy, readn_i(), and vpr::BaseIOStatsStrategy::readn_s().
00156 { 00157 vpr::ReturnStatus status; 00158 00159 if(mStatsStrategy != NULL) 00160 { 00161 mStatsStrategy->readn_s(status, buffer, length, bytesRead, timeout); 00162 } 00163 else 00164 { 00165 status = readn_i(buffer, length, bytesRead, timeout); 00166 } 00167 00168 return status; 00169 }
| vpr::ReturnStatus vpr::BlockIO::write_s | ( | const void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesWritten, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, virtual] |
Write strategy.
Definition at line 171 of file BlockIO.cpp.
References mStatsStrategy, write_i(), and vpr::BaseIOStatsStrategy::write_s().
00175 { 00176 vpr::ReturnStatus status; 00177 00178 if(mStatsStrategy != NULL) 00179 { 00180 mStatsStrategy->write_s(status, buffer, length, bytesWritten, 00181 timeout); 00182 } 00183 else 00184 { 00185 status = write_i(buffer, length, bytesWritten, timeout); 00186 } 00187 00188 return status; 00189 }
| virtual vpr::ReturnStatus vpr::BlockIO::read_i | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, pure virtual] |
Implementation of the read() template method.
This reads at most the specified number of bytes from the I/O device into the given buffer.
length bytes long. bytesRead parameter.| buffer | A pointer to the buffer where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
vpr::ReturnStatus::Fail is returned if the read operation failed.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Referenced by read_s(), and vpr::BaseIOStatsStrategy::read_s().
| virtual vpr::ReturnStatus vpr::BlockIO::readn_i | ( | void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesRead, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, pure virtual] |
Implementation of the readn() template method.
This reads exactly the specified number of bytes from the I/O device into the given buffer.
length bytes long. length bytes copied into it from the device, and the number of bytes read successfully is returned to the caller via the bytesRead parameter.| buffer | A pointer to the buffer where the device's buffer contents are to be stored. | |
| length | The number of bytes to be read. | |
| bytesRead | The number of bytes read into the buffer. | |
| timeout | The maximum amount of time to wait for data to be available for reading. This argument is optional and defaults to vpr::Interval::NoTimeout. |
vpr::ReturnStatus::Fail is returned if the read operation failed.
vpr::ReturnStatus::WouldBlock if the device is in non-blocking mode, and there is no data to read.
vpr::ReturnStatus::Timeout is returned if the read could not begin within the timeout interval.
Implemented in vpr::FileHandle_t< RealFileHandleImpl >, vpr::SerialPort_t< RealSerialPortImpl >, vpr::Socket_t< SockConfig_ >, and vpr::Socket_t< SocketConfig_ >.
Referenced by readn_s(), and vpr::BaseIOStatsStrategy::readn_s().
| virtual vpr::ReturnStatus vpr::BlockIO::write_i | ( | const void * | buffer, | |
| const vpr::Uint32 | length, | |||
| vpr::Uint32 & | bytesWritten, | |||
| const vpr::Interval | timeout = vpr::Interval::NoTimeout | |||
| ) | [protected, pure virtual] |
Implementation of the write() template method.
This writes the given buffer to the I/O device.
bytesWritten parameter.| buffer | A pointer to the buffer to be written. | |
| length | The length of the buffer. | |
| bytesWritten | The number of bytes written to the device. | |
| timeout | The maximum amount of time to wait for data to be available for writing. This argument is optional and defaults to vpr::Interval::NoTimeout. |