[gnio] Add g_socket_check_pending_error



commit af1379291e36b52cf158597f40f7a05059ade98f
Author: Alexander Larsson <alexl redhat com>
Date:   Thu May 7 18:57:25 2009 +0200

    Add g_socket_check_pending_error
    
    We need this for async connect.
---
 gio/gsocket.c |   39 ++++++++++++++++++++++++++++++++++++++-
 gio/gsocket.h |    2 ++
 2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/gio/gsocket.c b/gio/gsocket.c
index f015093..5c3dd20 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -1435,7 +1435,7 @@ g_socket_accept (GSocket       *socket,
  * non-blocking I/O is enabled. Then %G_IO_ERROR_PENDING is returned
  * and the user can be notified of the connectiong finishing by waiting
  * for the G_IO_OUT condition. The result of the connection can then be
- * checked with g_socket_get_pending_error().
+ * checked with g_socket_check_pending_error().
  *
  * Returns: %TRUE if connected, %FALSE on error.
  *
@@ -1490,6 +1490,43 @@ g_socket_connect (GSocket         *socket,
 }
 
 /**
+ * g_socket_check_pending_error:
+ * @socket: a #GSocket
+ * @error: #GError for error reporting, or %NULL to ignore.
+ *
+ * Checks and resets the pending error for the socket. This is typically
+ * used to check for errors when g_socket_connect() is used in non-blocking mode.
+ *
+ * Returns: %TRUE if no error, %FALSE otherwise, setting @error to the error
+ *
+ * Since: 2.22
+ **/
+gboolean
+g_socket_check_pending_error (GSocket  *socket,
+			      GError  **error)
+{
+  guint optlen;
+  int value;
+
+  if (getsockopt (socket->priv->fd, SOL_SOCKET, SO_ERROR, (void *)&value, &optlen) != 0)
+    {
+      int errsv = get_socket_errno ();
+
+      g_set_error (error, G_IO_ERROR, socket_io_error_from_errno (errsv),
+		   _("Unable to get pending error: %s"), socket_strerror (errsv));
+      return FALSE;
+    }
+
+  if (value != 0)
+    {
+      g_set_error (error, G_IO_ERROR, socket_io_error_from_errno (value),
+		   "%s", socket_strerror (value));
+      return FALSE;
+    }
+  return TRUE;
+}
+
+/**
  * g_socket_receive:
  * @socket: a #GSocket
  * @buffer: a buffer to read data into (which should be at least count bytes long).
diff --git a/gio/gsocket.h b/gio/gsocket.h
index 3e7c70a..87c917d 100644
--- a/gio/gsocket.h
+++ b/gio/gsocket.h
@@ -174,6 +174,8 @@ gboolean               g_socket_bind                    (GSocket
 gboolean               g_socket_connect                 (GSocket                 *socket,
 							 GSocketAddress          *address,
 							 GError                 **error);
+gboolean               g_socket_check_pending_error     (GSocket                 *socket,
+							 GError                 **error);
 GIOCondition           g_socket_condition_check         (GSocket                 *socket,
 							 GIOCondition             condition);
 gboolean               g_socket_condition_wait          (GSocket                 *socket,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]