[glib] gsocket: make use of g_source_set_ready_time()
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gsocket: make use of g_source_set_ready_time()
- Date: Sat, 22 Feb 2014 15:27:53 +0000 (UTC)
commit 04aee2d9201551810c2f9345b5b64ed7bf4e910e
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Feb 13 16:59:28 2014 -0500
gsocket: make use of g_source_set_ready_time()
Drop our own hand-rolled version of the same functionality.
https://bugzilla.gnome.org/show_bug.cgi?id=724707
gio/gsocket.c | 39 ++++++++++++---------------------------
1 files changed, 12 insertions(+), 27 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index c7262d6..a77f390 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -3207,7 +3207,6 @@ typedef struct {
GPollFD pollfd;
GSocket *socket;
GIOCondition condition;
- gint64 timeout_time;
} GSocketSource;
static gboolean
@@ -3216,22 +3215,7 @@ socket_source_prepare (GSource *source,
{
GSocketSource *socket_source = (GSocketSource *)source;
- if (socket_source->timeout_time)
- {
- gint64 now;
-
- now = g_source_get_time (source);
- /* Round up to ensure that we don't try again too early */
- *timeout = (socket_source->timeout_time - now + 999) / 1000;
- if (*timeout < 0)
- {
- socket_source->socket->priv->timed_out = TRUE;
- *timeout = 0;
- return TRUE;
- }
- }
- else
- *timeout = -1;
+ *timeout = -1;
#ifdef G_OS_WIN32
socket_source->pollfd.revents = update_condition (socket_source->socket);
@@ -3259,6 +3243,7 @@ socket_source_dispatch (GSource *source,
GSocketSourceFunc func = (GSocketSourceFunc)callback;
GSocketSource *socket_source = (GSocketSource *)source;
GSocket *socket = socket_source->socket;
+ gint64 timeout;
guint events;
gboolean ret;
@@ -3268,17 +3253,19 @@ socket_source_dispatch (GSource *source,
events = socket_source->pollfd.revents;
#endif
- if (socket_source->socket->priv->timed_out)
- events |= socket_source->condition & (G_IO_IN | G_IO_OUT);
+ timeout = g_source_get_ready_time (source);
+ if (timeout >= 0 && timeout < g_source_get_time (source))
+ {
+ socket->priv->timed_out = TRUE;
+ events |= (G_IO_IN | G_IO_OUT);
+ }
ret = (*func) (socket, events & socket_source->condition, user_data);
if (socket->priv->timeout)
- socket_source->timeout_time = g_get_monotonic_time () +
- socket->priv->timeout * 1000000;
-
+ g_source_set_ready_time (source, g_get_monotonic_time () + socket->priv->timeout * 1000000);
else
- socket_source->timeout_time = 0;
+ g_source_set_ready_time (source, -1);
return ret;
}
@@ -3384,11 +3371,9 @@ socket_source_new (GSocket *socket,
g_source_add_poll (source, &socket_source->pollfd);
if (socket->priv->timeout)
- socket_source->timeout_time = g_get_monotonic_time () +
- socket->priv->timeout * 1000000;
-
+ g_source_set_ready_time (source, g_get_monotonic_time () + socket->priv->timeout * 1000000);
else
- socket_source->timeout_time = 0;
+ g_source_set_ready_time (source, -1);
return source;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]