40 : m_fd (-1), m_readCallback (0), m_readThread (0), m_stop (false),
74 if (fcntl (
m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1)
122 ssize_t len = write (
m_evpipe[1], &zero,
sizeof (zero));
123 if (len !=
sizeof (zero))
124 NS_LOG_WARN (
"incomplete write(): " << std::strerror (errno));
164 FD_SET (
m_fd, &rfds);
170 fd_set readfds = rfds;
172 r = select (nfds, &readfds, NULL, NULL, NULL);
173 if (r == -1 && errno != EINTR)
178 if (FD_ISSET (
m_evpipe[0], &readfds))
184 ssize_t len = read (
m_evpipe[0], buf,
sizeof (buf));
191 if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)
209 if (FD_ISSET (
m_fd, &readfds))
219 else if (data.
m_len > 0)
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
A structure representing data read.
#define NS_LOG_FUNCTION(parameters)
NS_LOG_COMPONENT_DEFINE("FdReader")
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
Callback< void, uint8_t *, ssize_t > m_readCallback
#define NS_FATAL_ERROR(msg)
fatal error handling
void Stop(void)
Stop the read thread and reset internal state.
Ptr< SystemThread > m_readThread
int m_fd
The file descriptor to read from.
void Unref(void) const
Decrement the reference count.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
#define NS_LOG_LOGIC(msg)
#define NS_ASSERT_MSG(condition, message)
void Ref(void) const
Increment the reference count.
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 at Destroy time.