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

A class that asynchronously reads from a file descriptor. More...

#include <unix-fd-reader.h>

+ Inheritance diagram for ns3::FdReader:
+ Collaboration diagram for ns3::FdReader:

Classes

struct  Data
 A structure representing data read. More...

Public Member Functions

 FdReader ()
virtual ~FdReader ()
void Start (int fd, Callback< void, uint8_t *, ssize_t > readCallback)
void Stop (void)
- Public Member Functions inherited from ns3::SimpleRefCount< FdReader >
 SimpleRefCount ()
 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.

Protected Attributes

int m_fd
 The file descriptor to read from.

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.

Constructor & Destructor Documentation

ns3::FdReader::FdReader ( )

Definition at line 39 of file unix-fd-reader.cc.

References m_evpipe.

ns3::FdReader::~FdReader ( )
virtual

Definition at line 47 of file unix-fd-reader.cc.

References Stop().

+ Here is the call graph for this function:

Member Function Documentation

void ns3::FdReader::DestroyEvent ( void  )
private

Definition at line 103 of file unix-fd-reader.cc.

References Stop(), and ns3::SimpleRefCount< FdReader >::Unref().

Referenced by Start().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Referenced by Run().

+ Here is the caller graph for this function:

void ns3::FdReader::Run ( void  )
private

Definition at line 150 of file unix-fd-reader.cc.

References DoRead(), ns3::FdReader::Data::m_buf, m_evpipe, m_fd, ns3::FdReader::Data::m_len, m_readCallback, m_stop, and NS_FATAL_ERROR.

Referenced by Start().

+ Here is the call 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.

Parameters
fdA valid file descriptor open for reading.
readCallbackA callback to invoke when new data is available.

Definition at line 52 of file unix-fd-reader.cc.

References DestroyEvent(), ns3::EventId::IsRunning(), m_destroyEvent, m_evpipe, m_fd, m_readCallback, m_readThread, ns3::MakeCallback(), NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_LOGIC, ns3::SimpleRefCount< FdReader >::Ref(), Run(), ns3::Simulator::ScheduleDestroy(), and ns3::SystemThread::Start().

Referenced by ns3::TapBridge::StartTapDevice().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 109 of file unix-fd-reader.cc.

References ns3::SystemThread::Join(), m_evpipe, m_fd, m_readCallback, m_readThread, m_stop, NS_LOG_WARN, ns3::Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::Nullify(), and zero.

Referenced by DestroyEvent(), ns3::TapBridge::StopTapDevice(), and ~FdReader().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

EventId ns3::FdReader::m_destroyEvent
private

Definition at line 107 of file unix-fd-reader.h.

Referenced by Start().

int ns3::FdReader::m_evpipe[2]
private

Definition at line 105 of file unix-fd-reader.h.

Referenced by FdReader(), Run(), Start(), and Stop().

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(), Run(), Start(), and Stop().

Callback<void, uint8_t *, ssize_t> ns3::FdReader::m_readCallback
private

Definition at line 103 of file unix-fd-reader.h.

Referenced by Run(), Start(), and Stop().

Ptr<SystemThread> ns3::FdReader::m_readThread
private

Definition at line 104 of file unix-fd-reader.h.

Referenced by Start(), and Stop().

bool ns3::FdReader::m_stop
private

Definition at line 106 of file unix-fd-reader.h.

Referenced by Run(), and Stop().


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