Use MSG_NOSIGNAL in GSocket if it's available
authorDan Winship <danw@gnome.org>
Wed, 19 Aug 2009 16:12:06 +0000 (12:12 -0400)
committerDan Winship <danw@gnome.org>
Wed, 19 Aug 2009 16:12:15 +0000 (12:12 -0400)
Even though we ignore SIGPIPE, gdb will still stop when the process
receives one, which sometimes confuses people into thinking the app
has crashed (eg, bug 578984, bug 590420), and is annoying anyway. So
use MSG_NOSIGNAL if it's there.

http://bugzilla.gnome.org/show_bug.cgi?id=591378

gio/gsocket.c

index e216bd0..dd60e03 100644 (file)
@@ -1707,6 +1707,16 @@ g_socket_receive_from (GSocket         *socket,
                                   error);
 }
 
+/* Although we ignore SIGPIPE, gdb will still stop if the app receives
+ * one, which can be confusing and annoying. So if possible, we want
+ * to suppress the signal entirely.
+ */
+#ifdef MSG_NOSIGNAL
+#define G_SOCKET_DEFAULT_SEND_FLAGS MSG_NOSIGNAL
+#else
+#define G_SOCKET_DEFAULT_SEND_FLAGS 0
+#endif
+
 /**
  * g_socket_send:
  * @socket: a #GSocket
@@ -1759,7 +1769,7 @@ g_socket_send (GSocket       *socket,
                                    G_IO_OUT, cancellable, error))
        return -1;
 
-      if ((ret = send (socket->priv->fd, buffer, size, 0)) < 0)
+      if ((ret = send (socket->priv->fd, buffer, size, G_SOCKET_DEFAULT_SEND_FLAGS)) < 0)
        {
          int errsv = get_socket_errno ();
 
@@ -2681,7 +2691,7 @@ g_socket_send_message (GSocket                *socket,
                                      G_IO_OUT, cancellable, error))
          return -1;
 
-       result = sendmsg (socket->priv->fd, &msg, flags);
+       result = sendmsg (socket->priv->fd, &msg, flags | G_SOCKET_DEFAULT_SEND_FLAGS);
        if (result < 0)
          {
            int errsv = get_socket_errno ();