A Discrete-Event Network Simulator
API
Files | Namespaces | Functions
Fatal Implementation.

Files

file  fatal-impl.cc
 ns3::FatalImpl::RegisterStream(), ns3::FatalImpl::UnregisterStream(), and ns3::FatalImpl::FlushStreams() implementations; see Implementation note!
 
file  fatal-impl.h
 ns3::FatalImpl::RegisterStream(), ns3::FatalImpl::UnregisterStream(), and ns3::FatalImpl::FlushStreams() declarations.
 

Namespaces

 ns3::FatalImpl
 Implementation namespace for fatal error handlers.
 
 ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}
 Unnamed namespace for fatal streams memory implementation and signal handler.
 

Functions

void ns3::FatalImpl::FlushStreams (void)
 Flush all currently registered streams. More...
 
std::list< std::ostream * > * ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::GetStreamList (void)
 Get the stream list, initializing it if necessary. More...
 
std::list< std::ostream * > ** ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::PeekStreamList (void)
 Static variable pointing to the list of output streams to be flushed on fatal errors. More...
 
void ns3::FatalImpl::RegisterStream (std::ostream *stream)
 Register a stream to be flushed on abnormal exit. More...
 
void ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::sigHandler (int sig)
 Overrides normal SIGSEGV handler once the HandleTerminate function is run. More...
 
void ns3::FatalImpl::UnregisterStream (std::ostream *stream)
 Unregister a stream for flushing on abnormal exit. More...
 

Detailed Description

Function Documentation

◆ FlushStreams()

void ns3::FatalImpl::FlushStreams ( void  )

Flush all currently registered streams.

This function iterates through each registered stream and unregisters them. The default SIGSEGV handler is overridden when this function is being executed, and will be restored when this function returns.

If a SIGSEGV is encountered (most likely due to a bad ostream* being registered, or a registered osteam* pointing to an ostream that had already been destroyed), this function will skip the bad ostream* and continue to flush the next stream. The function will then terminate raising SIGIOT (aka SIGABRT)

DO NOT call this function until the program is ready to crash.

Definition at line 149 of file fatal-impl.cc.

References NS_LOG_FUNCTION_NOARGS, ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::PeekStreamList(), and ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::sigHandler().

Referenced by ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::sigHandler().

◆ GetStreamList()

std::list<std::ostream*>* ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::GetStreamList ( void  )

Get the stream list, initializing it if necessary.

Returns
The stream list.

Definition at line 86 of file fatal-impl.cc.

References NS_LOG_FUNCTION_NOARGS, and ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::PeekStreamList().

Referenced by ns3::FatalImpl::RegisterStream().

◆ PeekStreamList()

std::list<std::ostream*>** ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::PeekStreamList ( void  )

Static variable pointing to the list of output streams to be flushed on fatal errors.

Returns
The address of the static pointer.

Definition at line 73 of file fatal-impl.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::FatalImpl::FlushStreams(), ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::GetStreamList(), and ns3::FatalImpl::UnregisterStream().

◆ RegisterStream()

void ns3::FatalImpl::RegisterStream ( std::ostream *  stream)

Register a stream to be flushed on abnormal exit.

If a std::terminate() call is encountered after the stream had been registered and before it has been unregistered, stream->flush() will be called. Users of this function should ensure the stream remains valid until it had been unregistered.

Parameters
[in]streamThe stream to be flushed on abnormal exit.

Definition at line 100 of file fatal-impl.cc.

References ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::GetStreamList(), and NS_LOG_FUNCTION.

Referenced by ns3::AsciiFile::AsciiFile(), ns3::OutputStreamWrapper::OutputStreamWrapper(), and ns3::PcapFile::PcapFile().

◆ sigHandler()

void ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::sigHandler ( int  sig)

Overrides normal SIGSEGV handler once the HandleTerminate function is run.

This is private to the fatal implementation.

Parameters
[in]sigThe signal condition.

Definition at line 140 of file fatal-impl.cc.

References ns3::FatalImpl::FlushStreams(), and NS_LOG_FUNCTION.

Referenced by ns3::FatalImpl::FlushStreams().

◆ UnregisterStream()

void ns3::FatalImpl::UnregisterStream ( std::ostream *  stream)

Unregister a stream for flushing on abnormal exit.

After a stream had been unregistered, stream->flush() will no longer be called should abnormal termination be encountered.

If the stream is not registered, nothing will happen.

Parameters
[in]streamThe stream to be unregistered.

Definition at line 107 of file fatal-impl.cc.

References NS_LOG_FUNCTION, and ns3::FatalImpl::anonymous_namespace{fatal-impl.cc}::PeekStreamList().

Referenced by ns3::AsciiFile::~AsciiFile(), ns3::OutputStreamWrapper::~OutputStreamWrapper(), and ns3::PcapFile::~PcapFile().