46 : m_fd (-1), m_readCallback (0), m_readThread (0), m_stop (false),
80 if (fcntl (
m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1)
129 if (len !=
sizeof (
zero))
130 NS_LOG_WARN (
"incomplete write(): " << std::strerror (errno));
170 FD_SET (
m_fd, &rfds);
176 fd_set readfds = rfds;
178 r = select (nfds, &readfds, NULL, NULL, NULL);
179 if (r == -1 && errno != EINTR)
184 if (FD_ISSET (
m_evpipe[0], &readfds))
190 ssize_t len = read (
m_evpipe[0], buf,
sizeof (buf));
197 if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)
215 if (FD_ISSET (
m_fd, &readfds))
225 else if (
data.m_len > 0)
NS_FATAL_x macro definitions.
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
void DestroyEvent(void)
Event handler scheduled for destroy time to halt the thread.
A structure representing data read.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void Unref(void) const
Decrement the reference count.
virtual ~FdReader()
Destructor.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
System-independent thread class ns3::SystemThread declaration.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
ns3::Simulator declaration.
Callback< void, uint8_t *, ssize_t > m_readCallback
The main thread callback function to invoke when we have data.
bool m_stop
Signal the read thread to stop.
void Run(void)
The asynchronous function which performs the read.
void Stop(void)
Stop the read thread and reset internal state.
ns3::FdReader declaration.
Ptr< SystemThread > m_readThread
The thread doing the read, created and launched by Start().
int m_fd
The file descriptor to read from.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
EventId m_destroyEvent
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
void Nullify(void)
Discard the implementation, set it to null.
virtual FdReader::Data DoRead(void)=0
The read implementation.
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire when Simulator::Destroy is called.
void Ref(void) const
Increment the reference count.
int m_evpipe[2]
Pipe used to signal events between threads.
ns3::SimpleRefCount declaration and template implementation.