aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-28 20:03:58 +0200
committerMax Kellermann <max@duempel.org>2008-08-28 20:03:58 +0200
commit709b795e4aaa1356324253f975b28d1edf59d855 (patch)
tree88e9ac97d9ab3ce45dfc38907dd8a58c38bc861b
parent4516bd117cfe95156e2ade4f92737cc94d19863d (diff)
downloadmpd-709b795e4aaa1356324253f975b28d1edf59d855.tar.gz
mpd-709b795e4aaa1356324253f975b28d1edf59d855.tar.xz
mpd-709b795e4aaa1356324253f975b28d1edf59d855.zip
moved code to client_write()
Move the second part of client_write_output() into a separate function.
-rw-r--r--src/client.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/client.c b/src/client.c
index 529e3012d..f8e475a2d 100644
--- a/src/client.c
+++ b/src/client.c
@@ -744,41 +744,43 @@ static void client_defer_output(struct client *client,
*buf_r = new_sllnode(data, length);
}
-static void client_write_output(struct client *client)
+static void client_write(struct client *client,
+ const char *data, size_t length)
{
ssize_t ret;
+ assert(client->deferred_send == NULL);
+
+ if ((ret = write(client->fd, data, length)) < 0) {
+ if (errno == EAGAIN || errno == EINTR) {
+ client->deferred_send = new_sllnode(data, length);
+ } else {
+ DEBUG("client %i: problems writing\n", client->num);
+ client->expired = 1;
+ return;
+ }
+ } else if ((size_t)ret < client->send_buf_used) {
+ client->deferred_send = new_sllnode(data + ret, length - ret);
+ }
+
+ if (client->deferred_send) {
+ DEBUG("client %i: buffer created\n", client->num);
+ client->deferred_bytes =
+ client->deferred_send->size
+ + sizeof(struct sllnode);
+ }
+}
+
+static void client_write_output(struct client *client)
+{
if (client->expired || !client->send_buf_used)
return;
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) {
- client->deferred_send =
- new_sllnode(client->send_buf,
- client->send_buf_used);
- } else {
- DEBUG("client %i: problems writing\n",
- client->num);
- client->expired = 1;
- return;
- }
- } else if ((size_t)ret < client->send_buf_used) {
- client->deferred_send =
- new_sllnode(client->send_buf + ret,
- client->send_buf_used - ret);
- }
- if (client->deferred_send) {
- DEBUG("client %i: buffer created\n", client->num);
- client->deferred_bytes =
- client->deferred_send->size
- + sizeof(struct sllnode);
- }
- }
+ else
+ client_write(client, client->send_buf, client->send_buf_used);
client->send_buf_used = 0;
}