Beispiel #1
0
static gboolean
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)) {
        client_close(client);
        return false;
    }

    g_timer_start(client->last_activity);

    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|G_IO_ERR|G_IO_HUP,
                           client_in_event, client);
        return false;
    }

    /* write more */
    return true;
}
Beispiel #2
0
void
client_write_output(struct client *client)
{
	if (client_is_expired(client) || !client->send_buf_used)
		return;

	if (!g_queue_is_empty(client->deferred_send)) {
		client_defer_output(client, client->send_buf,
				    client->send_buf_used);

		if (client_is_expired(client))
			return;

		/* try to flush the deferred buffers now; the current
		   server command may take too long to finish, and
		   meanwhile try to feed output to the client,
		   otherwise it will time out.  One reason why
		   deferring is slow might be that currently each
		   client_write() allocates a new deferred buffer.
		   This should be optimized after MPD 0.14. */
		client_write_deferred(client);
	} else
		client_write_direct(client, client->send_buf,
				    client->send_buf_used);

	client->send_buf_used = 0;
}