|
Boost : |
From: Oliver.Kowalke_at_[hidden]
Date: 2005-12-13 02:07:32
>> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk