A class that asynchronously reads from a file descriptor. More...
#include <unix-fd-reader.h>
Inheritance diagram for ns3::FdReader:Classes | |
| struct | Data |
| A structure representing data read. More... | |
Public Member Functions | |
| void | Start (int fd, Callback< void, uint8_t *, ssize_t > readCallback) |
| void | Stop (void) |
Public Member Functions inherited from ns3::SimpleRefCount< FdReader > | |
| SimpleRefCount (const SimpleRefCount &o) | |
| uint32_t | GetReferenceCount (void) const |
| SimpleRefCount & | operator= (const SimpleRefCount &o) |
| void | Ref (void) const |
| void | Unref (void) const |
Protected Member Functions | |
| virtual FdReader::Data | DoRead (void)=0 |
| The read implementation. More... | |
Protected Attributes | |
| int | m_fd |
| The file descriptor to read from. More... | |
Private Member Functions | |
| void | DestroyEvent (void) |
| void | Run (void) |
Private Attributes | |
| EventId | m_destroyEvent |
| int | m_evpipe [2] |
|
Callback< void, uint8_t *, ssize_t > | m_readCallback |
| Ptr< SystemThread > | m_readThread |
| bool | m_stop |
Additional Inherited Members | |
Static Public Member Functions inherited from ns3::SimpleRefCount< FdReader > | |
| static void | Cleanup (void) |
A class that asynchronously reads from a file descriptor.
This class can be used to start a system thread that reads from a given file descriptor and invokes a given callback when data is received. This class handles thread management automatically but the DoRead() method must be implemented by a subclass.
Definition at line 40 of file unix-fd-reader.h.
|
protectedpure virtual |
The read implementation.
The value of m_len returned controls further processing. The callback function is only invoked when m_len is positive; any data read is not processed when m_len is negative; reading stops when m_len is zero.
The management of memory associated with m_buf must be compatible with the read callback.
Implemented in ns3::FdNetDeviceFdReader, and ns3::TapBridgeFdReader.
| void ns3::FdReader::Start | ( | int | fd, |
| Callback< void, uint8_t *, ssize_t > | readCallback | ||
| ) |
Start a new read thread.
| fd | A valid file descriptor open for reading. |
| readCallback | A callback to invoke when new data is available. |
Definition at line 54 of file unix-fd-reader.cc.
References ns3::EventId::IsRunning(), m_fd, ns3::MakeCallback(), NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::SimpleRefCount< FdReader >::Ref(), and ns3::Simulator::ScheduleDestroy().
| void ns3::FdReader::Stop | ( | void | ) |
Stop the read thread and reset internal state. This does not close the file descriptor used for reading.
Definition at line 113 of file unix-fd-reader.cc.
References m_fd, NS_LOG_FUNCTION, and NS_LOG_WARN.
|
protected |
The file descriptor to read from.
Definition at line 96 of file unix-fd-reader.h.
Referenced by ns3::TapBridgeFdReader::DoRead(), ns3::FdNetDeviceFdReader::DoRead(), Start(), and Stop().