[glib/wip/danw/socket1] gsocket: add G_IO_ERROR_CONNECTION_DISCONNECTED
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/danw/socket1] gsocket: add G_IO_ERROR_CONNECTION_DISCONNECTED
- Date: Wed, 1 Oct 2014 14:04:01 +0000 (UTC)
commit b4aa1f5abb03ad77133770d13cfd09e69d815789
Author: Dan Winship <danw gnome org>
Date: Fri Apr 25 15:38:24 2014 -0400
gsocket: add G_IO_ERROR_CONNECTION_DISCONNECTED
Add G_IO_ERROR_CONNECTION_DISCONNECTED, and add a note to
g_socket_send() pointing out that (unlike with g_socket_receive()),
there are several possible outcomes when trying to write to a socket
that has already been closed by the peer.
https://bugzilla.gnome.org/show_bug.cgi?id=728928
gio/gioenums.h | 4 +++-
gio/gioerror.c | 11 +++++++++++
gio/gsocket.c | 6 ++++++
3 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 1ca5be5..8e05568 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -470,6 +470,7 @@ typedef enum {
* @G_IO_ERROR_PROXY_NOT_ALLOWED: Proxy connection is not allowed by ruleset.
* Since 2.26
* @G_IO_ERROR_BROKEN_PIPE: Broken pipe. Since 2.36
+ * @G_IO_ERROR_CONNECTION_DISCONNECTED: Connection disconnected by peer. Since 2.42
*
* Error codes returned by GIO functions.
*
@@ -532,7 +533,8 @@ typedef enum {
G_IO_ERROR_PROXY_AUTH_FAILED,
G_IO_ERROR_PROXY_NEED_AUTH,
G_IO_ERROR_PROXY_NOT_ALLOWED,
- G_IO_ERROR_BROKEN_PIPE
+ G_IO_ERROR_BROKEN_PIPE,
+ G_IO_ERROR_CONNECTION_DISCONNECTED
} GIOErrorEnum;
diff --git a/gio/gioerror.c b/gio/gioerror.c
index fbae67d..4d804c7 100644
--- a/gio/gioerror.c
+++ b/gio/gioerror.c
@@ -242,6 +242,12 @@ g_io_error_from_errno (gint err_no)
break;
#endif
+#ifdef ECONNRESET
+ case ECONNRESET:
+ return G_IO_ERROR_CONNECTION_DISCONNECTED;
+ break;
+#endif
+
default:
return G_IO_ERROR_FAILED;
break;
@@ -305,6 +311,11 @@ g_io_error_from_win32_error (gint error_code)
case WSAEAFNOSUPPORT:
return G_IO_ERROR_NOT_SUPPORTED;
+ case WSAECONNRESET:
+ case WSAECONNABORTED:
+ case WSAECONNSHUTDOWN:
+ return G_IO_ERROR_CONNECTION_DISCONNECTED;
+
default:
return G_IO_ERROR_FAILED;
}
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 4d863ce..9e85e19 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -2718,6 +2718,12 @@ g_socket_receive_from (GSocket *socket,
*
* On error -1 is returned and @error is set accordingly.
*
+ * If the remote peer has closed the connection, a call to
+ * g_socket_send() may still appear to succeed, or it may return
+ * %G_IO_ERROR_BROKEN_PIPE or %G_IO_ERROR_CONNECTION_DISCONNECTED,
+ * depending on the exact state of the socket at the time you try to
+ * write to it.
+ *
* Returns: Number of bytes written (which may be less than @size), or -1
* on error
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]