A class that asynchronously reads from a file descriptor. More...
#include "fd-reader.h"
 Inheritance diagram for ns3::FdReader:
 Inheritance diagram for ns3::FdReader: Collaboration diagram for ns3::FdReader:
 Collaboration diagram for ns3::FdReader:| Classes | |
| struct | Data | 
| A structure representing data read.  More... | |
| Public Member Functions | |
| FdReader () | |
| Constructor. | |
| virtual | ~FdReader () | 
| Destructor. | |
| void | Start (int fd, Callback< void, uint8_t *, ssize_t > readCallback) | 
| Start a new read thread. | |
| void | Stop () | 
| Stop the read thread and reset internal state. | |
|  Public Member Functions inherited from ns3::SimpleRefCount< FdReader > | |
| SimpleRefCount () | |
| Default constructor. | |
| SimpleRefCount (const SimpleRefCount &o) | |
| Copy constructor. | |
| uint32_t | GetReferenceCount () const | 
| Get the reference count of the object. | |
| SimpleRefCount & | operator= (const SimpleRefCount &o) | 
| Assignment operator. | |
| void | Ref () const | 
| Increment the reference count. | |
| void | Unref () const | 
| Decrement the reference count. | |
| Protected Member Functions | |
| virtual FdReader::Data | DoRead ()=0 | 
| The read implementation. | |
| Protected Attributes | |
| int | m_fd | 
| The file descriptor to read from. | |
| Private Member Functions | |
| void | DestroyEvent () | 
| Event handler scheduled for destroy time to halt the thread. | |
| void | Run () | 
| The asynchronous function which performs the read. | |
| Private Attributes | |
| EventId | m_destroyEvent | 
| The event scheduled for destroy time which will invoke DestroyEvent and halt the thread. | |
| int | m_evpipe [2] | 
| Pipe used to signal events between threads. | |
| Callback< void, uint8_t *, ssize_t > | m_readCallback | 
| The main thread callback function to invoke when we have data. | |
| std::thread | m_readThread | 
| The thread doing the read, created and launched by Start(). | |
| bool | m_stop | 
| Signal the read thread to stop. | |
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 45 of file fd-reader.h.
| ns3::FdReader::FdReader | ( | ) | 
Constructor.
Definition at line 34 of file unix-fd-reader.cc.
References m_evpipe, and NS_LOG_FUNCTION.
| 
 | virtual | 
Destructor.
Definition at line 44 of file unix-fd-reader.cc.
References NS_LOG_FUNCTION, and Stop().
 Here is the call graph for this function:
 Here is the call graph for this function:| 
 | private | 
Event handler scheduled for destroy time to halt the thread.
Definition at line 102 of file unix-fd-reader.cc.
References NS_LOG_FUNCTION, Stop(), and ns3::SimpleRefCount< FdReader >::Unref().
Referenced by Start().
 Here is the call graph for this function:
 Here is the call graph for this function: Here is the caller graph for this function:
 Here is the caller graph for this function:| 
 | 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, ns3::NetmapNetDeviceFdReader, and ns3::TapBridgeFdReader.
Referenced by Run().
 Here is the caller graph for this function:
 Here is the caller graph for this function:| 
 | private | 
The asynchronous function which performs the read.
Definition at line 154 of file unix-fd-reader.cc.
References data, DoRead(), m_evpipe, m_fd, m_readCallback, m_stop, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by Start().
 Here is the call graph for this function:
 Here is the call graph for this function: Here is the caller graph for this function:
 Here is the caller graph for this function:| void ns3::FdReader::Start | ( | int | fd, | 
| Callback< void, uint8_t *, ssize_t > | readCallback ) | 
Start a new read thread.
| [in] | fd | A valid file descriptor open for reading. | 
| [in] | readCallback | A callback to invoke when new data is available. | 
Definition at line 51 of file unix-fd-reader.cc.
References DestroyEvent(), ns3::EventId::IsPending(), m_destroyEvent, m_evpipe, m_fd, m_readCallback, m_readThread, NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::SimpleRefCount< FdReader >::Ref(), Run(), and ns3::Simulator::ScheduleDestroy().
 Here is the call graph for this function:
 Here is the call graph for this function:| void ns3::FdReader::Stop | ( | ) | 
Stop the read thread and reset internal state.
This does not close the file descriptor used for reading.
Definition at line 110 of file unix-fd-reader.cc.
References m_evpipe, m_fd, m_readCallback, m_readThread, m_stop, NS_LOG_FUNCTION, NS_LOG_WARN, and ns3::Callback< R, UArgs >::Nullify().
Referenced by ~FdReader(), and DestroyEvent().
 Here is the call graph for this function:
 Here is the call graph for this function: Here is the caller graph for this function:
 Here is the caller graph for this function:| 
 | private | 
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
Definition at line 147 of file fd-reader.h.
Referenced by Start().
| 
 | private | 
Pipe used to signal events between threads.
Definition at line 139 of file fd-reader.h.
Referenced by FdReader(), Run(), Start(), and Stop().
| 
 | protected | 
The file descriptor to read from.
Definition at line 124 of file fd-reader.h.
Referenced by ns3::FdNetDeviceFdReader::DoRead(), ns3::NetmapNetDeviceFdReader::DoRead(), ns3::TapBridgeFdReader::DoRead(), Run(), Start(), and Stop().
| 
 | private | 
The main thread callback function to invoke when we have data.
Definition at line 133 of file fd-reader.h.
| 
 | private | 
The thread doing the read, created and launched by Start().
Definition at line 136 of file fd-reader.h.
| 
 | private | 
Signal the read thread to stop.
Definition at line 141 of file fd-reader.h.