nidas v1.2.3
|
A basic Unix I/O device, such as a named pipe, or a watched file. More...
#include <UnixIODevice.h>
Public Member Functions | |
UnixIODevice () | |
Constructor. | |
UnixIODevice (const std::string &name) | |
Constructor, passing the name of the device. | |
~UnixIODevice () | |
Destructor. | |
int | getReadFd () const |
The file descriptor used when reading from this device. | |
int | getWriteFd () const |
The file descriptor used when writing to this device. | |
void | open (int flags) |
open the device. | |
size_t | read (void *buf, size_t len) |
Read from the device. | |
size_t | read (void *buf, size_t len, int msecTimeout) |
Read from the device with a timeout in milliseconds. | |
size_t | write (const void *buf, size_t len) |
Write to the device. | |
void | ioctl (int request, void *buf, size_t) |
void | close () |
close the device | |
virtual void | setName (const std::string &val) |
Set the device name to be opened for this sensor. | |
virtual const std::string & | getName () const |
virtual size_t | getBytesAvailable () const |
Return how many bytes are available to read on this IODevice. | |
Protected Attributes | |
int | _fd |
Private Attributes | |
std::string | _devname |
Whether to reopen this sensor on an IOException. | |
A basic Unix I/O device, such as a named pipe, or a watched file.
|
inline |
Constructor.
Does not open any actual device.
|
inline |
Constructor, passing the name of the device.
Does not open the device.
References nidas::core::IODevice::setName().
|
inline |
Destructor.
Does not close the device.
|
inlinevirtual |
close the device
nidas::util::IOException |
Implements nidas::core::IODevice.
References _fd, close(), fd, and nidas::core::IODevice::getName().
Referenced by close().
Return how many bytes are available to read on this IODevice.
This method is only useful when ioctl FIONREAD is supported on this this IODevice, as for example with a UDP socket. It is not available, and not necessary, on most other devices, like serial ports, TCP sockets, or devices with nidas driver module support, in which case it will return an nidas::util::IOException. It is an optimization for use with UDP sockets, where after select determines that data is available on the socket file descriptor, a read will only read one datagram, even if there are more than one packet available, which would not be optimal if a sensor generated many small packets. Rather than returning back to select, we check if there are more datagrams to read. This is not necessary on other types of IODevices, where it is just a matter of using a big enough buffer to get all (or most) available data after a select.
According to man udp(7), FIONREAD will return 0 if the size of the next packet is 0. So, if select/poll indicate there is data available, one read at least should be done, just in case a sensor sends a datagram of length 0, otherwise it will never be consumed.
nidas::util::IOException |
References err, nidas::core::IODevice::getName(), nidas::core::IODevice::getReadFd(), and nidas::core::IODevice::ioctl().
Referenced by nidas::core::DSMSensor::getBytesAvailable().
References nidas::core::IODevice::_devname.
Referenced by nidas::core::SerialPortIODevice::applyTermios(), nidas::core::ServerSocketIODevice::close(), nidas::core::TCPSocketIODevice::close(), nidas::core::UDPSocketIODevice::close(), close(), nidas::core::IODevice::getBytesAvailable(), ioctl(), nidas::core::ServerSocketIODevice::ioctl(), nidas::core::SocketIODevice::ioctl(), nidas::core::SerialPortIODevice::open(), nidas::core::ServerSocketIODevice::open(), nidas::core::SocketIODevice::open(), open(), read(), read(), nidas::core::SerialPortIODevice::setRTS485(), nidas::core::SerialPortIODevice::write(), and write().
|
inlinevirtual |
The file descriptor used when reading from this device.
Implements nidas::core::IODevice.
References _fd.
|
inlinevirtual |
The file descriptor used when writing to this device.
Implements nidas::core::IODevice.
References _fd.
Implements nidas::core::IODevice.
References _fd, nidas::core::IODevice::getName(), and ioctl().
Referenced by ioctl(), nidas::core::SerialPortIODevice::open(), nidas::core::SerialPortIODevice::setRTS485(), and nidas::core::SerialPortIODevice::write().
open the device.
nidas::util::IOException |
Implements nidas::core::IODevice.
References _fd, nidas::core::IODevice::getName(), nidas::core::getSample(), and open().
Referenced by nidas::core::SerialPortIODevice::open(), and open().
Read from the device.
nidas::util::IOException |
Implements nidas::core::IODevice.
References _fd, nidas::core::IODevice::getName(), nidas::core::getSample(), len, and read().
Read from the device with a timeout in milliseconds.
nidas::util::IOException |
Implements nidas::core::IODevice.
References _fd, nidas::core::IODevice::getName(), nidas::core::getSample(), len, MSECS_PER_SEC, NSECS_PER_MSEC, and read().
Set the device name to be opened for this sensor.
References nidas::core::IODevice::_devname, and nidas::core::getSample().
Referenced by nidas::core::DSMSensor::open(), and UnixIODevice().
Write to the device.
nidas::util::IOException |
Implements nidas::core::IODevice.
References _fd, nidas::core::IODevice::getName(), nidas::core::getSample(), len, and write().
Referenced by write().
|
privateinherited |
Whether to reopen this sensor on an IOException.
Referenced by nidas::core::IODevice::getName(), and nidas::core::IODevice::setName().
|
protected |
Referenced by nidas::core::SerialPortIODevice::applyTermios(), close(), getReadFd(), nidas::core::SerialPortIODevice::getUsecsPerByte(), getWriteFd(), ioctl(), nidas::core::SerialPortIODevice::open(), open(), read(), read(), nidas::core::SerialPortIODevice::setRTS485(), nidas::core::SerialPortIODevice::write(), and write().