A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ns3::FdReader Class Referenceabstract

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
 
SimpleRefCountoperator= (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< SystemThreadm_readThread
 
bool m_stop
 

Additional Inherited Members

- Static Public Member Functions inherited from ns3::SimpleRefCount< FdReader >
static void Cleanup (void)
 

Detailed Description

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.

Member Function Documentation

virtual FdReader::Data ns3::FdReader::DoRead ( void  )
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.

Returns
A structure representing what was read.

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.

Parameters
fdA valid file descriptor open for reading.
readCallbackA 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.

Member Data Documentation

int ns3::FdReader::m_fd
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().


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