19#include <sys/select.h>
71 if (fcntl(
m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1)
120 if (len !=
sizeof(
zero))
122 NS_LOG_WARN(
"incomplete write(): " << std::strerror(errno));
169 fd_set readfds = rfds;
171 r = select(nfds, &readfds,
nullptr,
nullptr,
nullptr);
172 if (r == -1 && errno != EINTR)
177 if (FD_ISSET(
m_evpipe[0], &readfds))
183 ssize_t len = read(
m_evpipe[0], buf,
sizeof(buf));
190 if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)
208 if (FD_ISSET(
m_fd, &readfds))
218 else if (
data.m_len > 0)
void Nullify()
Discard the implementation, set it to null.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
int m_evpipe[2]
Pipe used to signal events between threads.
void Run()
The asynchronous function which performs the read.
void Stop()
Stop the read thread and reset internal state.
bool m_stop
Signal the read thread to stop.
EventId m_destroyEvent
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
virtual FdReader::Data DoRead()=0
The read implementation.
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
void DestroyEvent()
Event handler scheduled for destroy time to halt the thread.
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().
int m_fd
The file descriptor to read from.
virtual ~FdReader()
Destructor.
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
NS_FATAL_x macro definitions.
ns3::FdReader declaration.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SimpleRefCount declaration and template implementation.
ns3::Simulator declaration.
A structure representing data read.