
sig::action sa; sa.set_handler( SIG_IGN); sig::action old_sa( sa.run( SIGPIPE) ); boost::shared_ptr< void > guard( static_cast< void * >( 0), boost::bind( & sig::action::run, old_sa, SIGPIPE) );
::write(...)
As I mentioned in another message, at least on Linux, sendmsg can be used as replacement for writev that allows specification of MSG_NOSIGNAL.
Yes.
Your code might potentially be useful on Solaris and other platforms that do not support disabling the signal through mechanism like MSG_NOSIGNAL, although your code seems to introduce quite a lot of overhead per write call.
The code could be expanded to: struct sigaction sa, old_sa; if ( ::sigemptyset( & sa.sa_mask) < 0) throw std::runtime_error( ::strerror( errno) ); sa.sa_flags = ZERO; sa.sa_handler = SIG_IGN; if ( ::sigaction( SIGPIPE, & sa, & old_sa) < 0) throw std::runtime_error( ::strerror( errno) ); // shared_ptr has to call ::sigaction( SIGPIPE, & old_sa, 0) in order to // reset original signal handler So it seams to be only 3 clib-function calls for each write operation. Oliver

Oliver.Kowalke@infineon.com wrote:
sig::action sa; [--snip--]
if ( ::sigaction( SIGPIPE, & sa, & old_sa) < 0) throw std::runtime_error( ::strerror( errno) );
// shared_ptr has to call ::sigaction( SIGPIPE, & old_sa, 0) in order to
// reset original signal handler
So it seams to be only 3 clib-function calls for each write operation.
I'm aware that this wouldn't be needed for Linux, but I just though add something... My Linux man page says that sigaction is a *system* call, and I would guess that it's the same on most Unixes -- indeed a quick google seems to indicate that this is also the case for SunOS/Solaris (at least the function is listed in the "system calls" section). System calls can be hideously expensive compared to regular C library function calls depending on architecture. -- Bardur Arantsson <bardurREMOVE@THISimada.sdu.dk> <bardurREMOVE@THISscientician.net> - That plot makes perfect sense. Wink, wink - Bender, you said "wink, wink" out loud. - No, I didn't. Raise middle finger. Bender and Zoidberg / Futurama

My Linux man page says that sigaction is a *system* call, and I would guess that it's the same on most Unixes -- indeed a quick google seems to indicate that this is also the case for SunOS/Solaris (at least the function is listed in the "system calls" section). System calls can be hideously expensive compared to regular C library function calls depending on architecture.
Sigaction is definitely a syscall on most unices. While syscalls are not that expensive, at least on linux (i've done some benchmarks of null syscalls, and the cost of sigaction is almost the same of a null syscall), doing as less syscalls as possible is certanly a win.
participants (3)
-
Bardur Arantsson
-
Giovanni P. Deretta
-
Oliver.Kowalke@infineon.com