Commit d2d11d70 authored by Max Kellermann's avatar Max Kellermann

client: always attempt to flush deferred buffers

When a response is very long (e.g. a large playlist > 100k songs), most of it will end up in the deferred buffers. Filling the deferred queue is very expensive currently, because a new buffer is allocated for every client_write() operation. This may lead to long delays, and the client might give up and disconnect meanwhile. This patch makes MPD attempt to flush the deferred queue as often as possible, to work around this problem. Due to the MPD 0.14 code freeze, we should not optimize the buffering code now.
parent d96cda95
...@@ -700,10 +700,19 @@ static void client_write_output(struct client *client) ...@@ -700,10 +700,19 @@ static void client_write_output(struct client *client)
if (client_is_expired(client) || !client->send_buf_used) if (client_is_expired(client) || !client->send_buf_used)
return; return;
if (!g_queue_is_empty(client->deferred_send)) if (!g_queue_is_empty(client->deferred_send)) {
client_defer_output(client, client->send_buf, client_defer_output(client, client->send_buf,
client->send_buf_used); client->send_buf_used);
else
/* 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_write_direct(client, client->send_buf,
client->send_buf_used); client->send_buf_used);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment