client: check for G_IO_ERR and G_IO_HUP

When we do not explicitly catch G_IO_ERR and G_IO_HUP, GLib can go
into an infinite loop, because it won't deliver the socket error to
MPD.
This commit is contained in:
Max Kellermann 2009-01-30 15:56:53 +01:00
parent c38dd9e8d8
commit 76b217f71e

View File

@ -191,7 +191,8 @@ static void client_init(struct client *client, int fd)
/* we prefer to do buffering */
g_io_channel_set_buffered(client->channel, false);
client->source_id = g_io_add_watch(client->channel, G_IO_IN,
client->source_id = g_io_add_watch(client->channel,
G_IO_IN|G_IO_ERR|G_IO_HUP,
client_in_event, client);
client->lastTime = time(NULL);
@ -498,13 +499,12 @@ static int client_read(struct client *client)
}
static gboolean
client_out_event(G_GNUC_UNUSED GIOChannel *source,
G_GNUC_UNUSED GIOCondition condition,
client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
gpointer data);
static gboolean
client_in_event(G_GNUC_UNUSED GIOChannel *source,
G_GNUC_UNUSED GIOCondition condition,
GIOCondition condition,
gpointer data)
{
struct client *client = data;
@ -512,6 +512,11 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source,
assert(!client_is_expired(client));
if (condition != G_IO_IN) {
client_set_expired(client);
return false;
}
client->lastTime = time(NULL);
ret = client_read(client);
@ -533,7 +538,8 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source,
if (!g_queue_is_empty(client->deferred_send)) {
/* deferred buffers exist: schedule write */
client->source_id = g_io_add_watch(client->channel, G_IO_OUT,
client->source_id = g_io_add_watch(client->channel,
G_IO_OUT|G_IO_ERR|G_IO_HUP,
client_out_event, client);
return false;
}
@ -543,14 +549,18 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source,
}
static gboolean
client_out_event(G_GNUC_UNUSED GIOChannel *source,
G_GNUC_UNUSED GIOCondition condition,
client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
gpointer data)
{
struct client *client = data;
assert(!client_is_expired(client));
if (condition != G_IO_OUT) {
client_set_expired(client);
return false;
}
client_write_deferred(client);
if (client_is_expired(client)) {
@ -563,7 +573,8 @@ client_out_event(G_GNUC_UNUSED GIOChannel *source,
if (g_queue_is_empty(client->deferred_send)) {
/* done sending deferred buffers exist: schedule
read */
client->source_id = g_io_add_watch(client->channel, G_IO_IN,
client->source_id = g_io_add_watch(client->channel,
G_IO_IN|G_IO_ERR|G_IO_HUP,
client_in_event, client);
return false;
}