mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 06:26:15 +01:00
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
This commit is contained in:
parent
12d65f2509
commit
04aee2d920
@ -3207,7 +3207,6 @@ typedef struct {
|
|||||||
GPollFD pollfd;
|
GPollFD pollfd;
|
||||||
GSocket *socket;
|
GSocket *socket;
|
||||||
GIOCondition condition;
|
GIOCondition condition;
|
||||||
gint64 timeout_time;
|
|
||||||
} GSocketSource;
|
} GSocketSource;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -3216,22 +3215,7 @@ socket_source_prepare (GSource *source,
|
|||||||
{
|
{
|
||||||
GSocketSource *socket_source = (GSocketSource *)source;
|
GSocketSource *socket_source = (GSocketSource *)source;
|
||||||
|
|
||||||
if (socket_source->timeout_time)
|
*timeout = -1;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
socket_source->pollfd.revents = update_condition (socket_source->socket);
|
socket_source->pollfd.revents = update_condition (socket_source->socket);
|
||||||
@ -3259,6 +3243,7 @@ socket_source_dispatch (GSource *source,
|
|||||||
GSocketSourceFunc func = (GSocketSourceFunc)callback;
|
GSocketSourceFunc func = (GSocketSourceFunc)callback;
|
||||||
GSocketSource *socket_source = (GSocketSource *)source;
|
GSocketSource *socket_source = (GSocketSource *)source;
|
||||||
GSocket *socket = socket_source->socket;
|
GSocket *socket = socket_source->socket;
|
||||||
|
gint64 timeout;
|
||||||
guint events;
|
guint events;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
@ -3268,17 +3253,19 @@ socket_source_dispatch (GSource *source,
|
|||||||
events = socket_source->pollfd.revents;
|
events = socket_source->pollfd.revents;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (socket_source->socket->priv->timed_out)
|
timeout = g_source_get_ready_time (source);
|
||||||
events |= socket_source->condition & (G_IO_IN | G_IO_OUT);
|
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);
|
ret = (*func) (socket, events & socket_source->condition, user_data);
|
||||||
|
|
||||||
if (socket->priv->timeout)
|
if (socket->priv->timeout)
|
||||||
socket_source->timeout_time = g_get_monotonic_time () +
|
g_source_set_ready_time (source, g_get_monotonic_time () + socket->priv->timeout * 1000000);
|
||||||
socket->priv->timeout * 1000000;
|
|
||||||
|
|
||||||
else
|
else
|
||||||
socket_source->timeout_time = 0;
|
g_source_set_ready_time (source, -1);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -3384,11 +3371,9 @@ socket_source_new (GSocket *socket,
|
|||||||
g_source_add_poll (source, &socket_source->pollfd);
|
g_source_add_poll (source, &socket_source->pollfd);
|
||||||
|
|
||||||
if (socket->priv->timeout)
|
if (socket->priv->timeout)
|
||||||
socket_source->timeout_time = g_get_monotonic_time () +
|
g_source_set_ready_time (source, g_get_monotonic_time () + socket->priv->timeout * 1000000);
|
||||||
socket->priv->timeout * 1000000;
|
|
||||||
|
|
||||||
else
|
else
|
||||||
socket_source->timeout_time = 0;
|
g_source_set_ready_time (source, -1);
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user