Commit 7774cd27 authored by Max Kellermann's avatar Max Kellermann

client: moved code to client_defer_output()

Split the large function client_write_output() into two parts; this is the first code moving patch.
parent 4448b17e
...@@ -719,19 +719,15 @@ int client_print(int fd, const char *buffer, size_t buflen) ...@@ -719,19 +719,15 @@ int client_print(int fd, const char *buffer, size_t buflen)
return 0; return 0;
} }
static void client_write_output(struct client *client) static void client_defer_output(struct client *client,
const void *data, size_t length)
{ {
ssize_t ret; struct sllnode *buf = client->deferred_send;
struct sllnode *buf;
if (client->expired || !client->send_buf_used) assert(client->deferred_send != NULL);
return;
if ((buf = client->deferred_send)) { client->deferred_bytes += sizeof(struct sllnode) + length;
client->deferred_bytes += sizeof(struct sllnode) if (client->deferred_bytes > client_max_output_buffer_size) {
+ client->send_buf_used;
if (client->deferred_bytes >
client_max_output_buffer_size) {
ERROR("client %i: output buffer size (%lu) is " ERROR("client %i: output buffer size (%lu) is "
"larger than the max (%lu)\n", "larger than the max (%lu)\n",
client->num, client->num,
...@@ -742,10 +738,21 @@ static void client_write_output(struct client *client) ...@@ -742,10 +738,21 @@ static void client_write_output(struct client *client)
} else { } else {
while (buf->next) while (buf->next)
buf = buf->next; buf = buf->next;
buf->next = new_sllnode(client->send_buf, buf->next = new_sllnode(data, length);
client->send_buf_used);
} }
} else { }
static void client_write_output(struct client *client)
{
ssize_t ret;
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, if ((ret = write(client->fd, client->send_buf,
client->send_buf_used)) < 0) { client->send_buf_used)) < 0) {
if (errno == EAGAIN || errno == EINTR) { if (errno == EAGAIN || errno == EINTR) {
......
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