|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include <sys/select.h>
48 : m_fd (-1), m_readCallback (0), m_readThread (0), m_stop (false),
82 if (fcntl (
m_evpipe[0], F_SETFL, tmp | O_NONBLOCK) == -1)
131 if (len !=
sizeof (
zero))
133 NS_LOG_WARN (
"incomplete write(): " << std::strerror (errno));
174 FD_SET (
m_fd, &rfds);
180 fd_set readfds = rfds;
182 r = select (nfds, &readfds, NULL, NULL, NULL);
183 if (r == -1 && errno != EINTR)
188 if (FD_ISSET (
m_evpipe[0], &readfds))
194 ssize_t len = read (
m_evpipe[0], buf,
sizeof (buf));
201 if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)
219 if (FD_ISSET (
m_fd, &readfds))
229 else if (
data.m_len > 0)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
int m_fd
The file descriptor to read from.
NS_FATAL_x macro definitions.
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
ns3::SimpleRefCount declaration and template implementation.
Callback< void, uint8_t *, ssize_t > m_readCallback
The main thread callback function to invoke when we have data.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Ptr< SystemThread > m_readThread
The thread doing the read, created and launched by Start().
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
void DestroyEvent(void)
Event handler scheduled for destroy time to halt the thread.
void Ref(void) const
Increment the reference count.
EventId m_destroyEvent
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
void Unref(void) const
Decrement the reference count.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void Run(void)
The asynchronous function which performs the read.
System-independent thread class ns3::SystemThread declaration.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
virtual ~FdReader()
Destructor.
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
ns3::Simulator declaration.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
bool m_stop
Signal the read thread to stop.
void Stop(void)
Stop the read thread and reset internal state.
int m_evpipe[2]
Pipe used to signal events between threads.
virtual FdReader::Data DoRead(void)=0
The read implementation.
ns3::FdReader declaration.
A structure representing data read.
void Nullify(void)
Discard the implementation, set it to null.