I'm using a pipe to communicate between two processes on Gnu/Linux. The receiving end closes the pipe while the sending end is still trying to send data. Here is some code that emulates the situation.
#include <unistd.h>
#include <boost/asio.hpp>
int main()
{
int pipe_fds[2];
if( ::pipe(pipe_fds) != 0 ) return 1;
// close the receiving end
::close( pipe_fds[0] );
boost::asio::io_service io;
boost::asio::posix::stream_descriptor sd( io, pipe_fds[1] );
boost::system::error_code ec;
sd.write_some( boost::asio::buffer("blah"), ec );
return 0;
}
When I run it I get a SIGPIPE; classic situation, I know. However, I see that boost::asio::error::basic_errors
has a broken_pipe
value. I would expect that to be returned in the error_code without a signal being raised.
Can this be done without creating a SIGPIPE handler for my process? For instance, is there a configuration option to boost::asio that I'm missing? Maybe something that would enable MSG_NOSIGNAL in the implementation?