diff options
author | Daniel Elstner <daniel.kitta@gmail.com> | 2010-02-27 22:59:15 +0100 |
---|---|---|
committer | Daniel Elstner <daniel.kitta@gmail.com> | 2010-02-27 22:59:15 +0100 |
commit | 6978bd38faae5dcb626929334b747f97e644717f (patch) | |
tree | 08cf65a6ae595070472640afb9a0f1aedd4c9a4b | |
parent | 000973dd11eba2023c35866cc6afd8901df15e5f (diff) | |
download | glibmm-6978bd38faae5dcb626929334b747f97e644717f.tar.gz |
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.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | examples/network/resolver.cc | 26 |
2 files changed, 27 insertions, 10 deletions
@@ -1,3 +1,14 @@ +2010-02-27 Daniel Elstner <daniel.kitta@gmail.com> + + 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 <space3000@gmail.com> 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 <config.h> #include <giomm.h> #include <iostream> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <cerrno> +#include <csignal> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <unistd.h> #include <gio/gio.h> @@ -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<Glib::IOSource> source = chan->create_watch (Glib::IO_IN); watch_conn = source->connect (sigc::bind (sigc::ptr_fun (async_cancel), cancellable)); |