From 6978bd38faae5dcb626929334b747f97e644717f Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Sat, 27 Feb 2010 22:59:15 +0100 Subject: Avoid compiler warning in resolver example * examples/network/resolver.cc (interrupted): Check the return value of the write() call to avoid a warning from GCC. Save and restore the value of errno to make the signal handler reentrant. Get rid of the signal() call to re-establish the default handler, as there is not much of a point in doing so for this handler. (main): Create the pipe before installing the signal handler. --- ChangeLog | 11 +++++++++++ examples/network/resolver.cc | 26 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81986cce..a228e08e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-02-27 Daniel Elstner + + Avoid compiler warning in resolver example + + * examples/network/resolver.cc (interrupted): Check the return value + of the write() call to avoid a warning from GCC. Save and restore + the value of errno to make the signal handler reentrant. Get rid of + the signal() call to re-establish the default handler, as there is + not much of a point in doing so for this handler. + (main): Create the pipe before installing the signal handler. + 2010-02-22 Michael Gio::MemoryInputStream::add_data(): Minor documentation fix. diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc index a77be37b..b05200c6 100644 --- a/examples/network/resolver.cc +++ b/examples/network/resolver.cc @@ -19,14 +19,15 @@ * Boston, MA 02111-1307, USA. */ -#include "config.h" +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -434,13 +435,15 @@ do_connectable (const std::string& arg, gboolean synchronous) } #ifdef G_OS_UNIX -static int cancel_fds[2]; +static volatile int cancel_fd; static void interrupted (int /*sig*/) { - signal (SIGINT, SIG_DFL); - write (cancel_fds[1], "x", 1); + const int save_errno = errno; + while (write(cancel_fd, "", 1) < 0 && errno == EINTR) + {} + errno = save_errno; } static bool @@ -494,13 +497,16 @@ main (int argc, char **argv) /* Set up cancellation; we want to cancel if the user ^C's the * program, but we can't cancel directly from an interrupt. */ - signal (SIGINT, interrupted); + int cancel_fds[2]; - if (pipe (cancel_fds) == -1) + if (pipe (cancel_fds) < 0) { perror ("pipe"); exit (1); } + cancel_fd = cancel_fds[1]; + signal (SIGINT, interrupted); + chan = Glib::IOChannel::create_from_fd (cancel_fds[0]); Glib::RefPtr source = chan->create_watch (Glib::IO_IN); watch_conn = source->connect (sigc::bind (sigc::ptr_fun (async_cancel), cancellable)); -- cgit v1.2.1