aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-28 20:03:51 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-01 18:35:18 -0700
commit7ff63fec2ca1c2c45d28a1907ab1e08e0356996e (patch)
tree04ff8f3a98b710b729291f18c85aeff3a669930d /src
parent4184435c697ba953e0a224da5d8f7f4e880c1644 (diff)
downloadmpd-7ff63fec2ca1c2c45d28a1907ab1e08e0356996e.tar.gz
mpd-7ff63fec2ca1c2c45d28a1907ab1e08e0356996e.tar.xz
mpd-7ff63fec2ca1c2c45d28a1907ab1e08e0356996e.zip
client: moved code to client_defer_output()
Split the large function client_write_output() into two parts; this is the first code moving patch.
Diffstat (limited to 'src')
-rw-r--r--src/client.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/client.c b/src/client.c
index 3065a6940..586d4d212 100644
--- a/src/client.c
+++ b/src/client.c
@@ -716,33 +716,40 @@ int client_print(int fd, const char *buffer, size_t buflen)
return 0;
}
+static void client_defer_output(struct client *client,
+ const void *data, size_t length)
+{
+ struct sllnode *buf = client->deferred_send;
+
+ assert(client->deferred_send != NULL);
+
+ client->deferred_bytes += sizeof(struct sllnode) + length;
+ if (client->deferred_bytes > client_max_output_buffer_size) {
+ ERROR("client %i: output buffer size (%lu) is "
+ "larger than the max (%lu)\n",
+ client->num,
+ (unsigned long)client->deferred_bytes,
+ (unsigned long)client_max_output_buffer_size);
+ /* cause client to close */
+ client->expired = 1;
+ } else {
+ while (buf->next)
+ buf = buf->next;
+ buf->next = new_sllnode(data, length);
+ }
+}
+
static void client_write_output(struct client *client)
{
ssize_t ret;
- struct sllnode *buf;
if (client->expired || !client->send_buf_used)
return;
- if ((buf = client->deferred_send)) {
- client->deferred_bytes += sizeof(struct sllnode)
- + client->send_buf_used;
- if (client->deferred_bytes >
- client_max_output_buffer_size) {
- ERROR("client %i: output buffer size (%lu) is "
- "larger than the max (%lu)\n",
- client->num,
- (unsigned long)client->deferred_bytes,
- (unsigned long)client_max_output_buffer_size);
- /* cause client to close */
- client->expired = 1;
- } else {
- while (buf->next)
- buf = buf->next;
- buf->next = new_sllnode(client->send_buf,
- client->send_buf_used);
- }
- } else {
+ if (client->deferred_send != NULL)
+ client_defer_output(client, client->send_buf,
+ client->send_buf_used);
+ else {
if ((ret = write(client->fd, client->send_buf,
client->send_buf_used)) < 0) {
if (errno == EAGAIN || errno == EINTR) {