moved code to client_write()
Move the second part of client_write_output() into a separate function.
This commit is contained in:
38
src/client.c
38
src/client.c
@@ -744,41 +744,43 @@ static void client_defer_output(struct client *client,
|
|||||||
*buf_r = new_sllnode(data, length);
|
*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;
|
ssize_t ret;
|
||||||
|
|
||||||
if (client->expired || !client->send_buf_used)
|
assert(client->deferred_send == NULL);
|
||||||
return;
|
|
||||||
|
|
||||||
if (client->deferred_send != NULL)
|
if ((ret = write(client->fd, data, length)) < 0) {
|
||||||
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) {
|
if (errno == EAGAIN || errno == EINTR) {
|
||||||
client->deferred_send =
|
client->deferred_send = new_sllnode(data, length);
|
||||||
new_sllnode(client->send_buf,
|
|
||||||
client->send_buf_used);
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG("client %i: problems writing\n",
|
DEBUG("client %i: problems writing\n", client->num);
|
||||||
client->num);
|
|
||||||
client->expired = 1;
|
client->expired = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if ((size_t)ret < client->send_buf_used) {
|
} else if ((size_t)ret < client->send_buf_used) {
|
||||||
client->deferred_send =
|
client->deferred_send = new_sllnode(data + ret, length - ret);
|
||||||
new_sllnode(client->send_buf + ret,
|
|
||||||
client->send_buf_used - ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->deferred_send) {
|
if (client->deferred_send) {
|
||||||
DEBUG("client %i: buffer created\n", client->num);
|
DEBUG("client %i: buffer created\n", client->num);
|
||||||
client->deferred_bytes =
|
client->deferred_bytes =
|
||||||
client->deferred_send->size
|
client->deferred_send->size
|
||||||
+ sizeof(struct sllnode);
|
+ 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
|
||||||
|
client_write(client, client->send_buf, client->send_buf_used);
|
||||||
|
|
||||||
client->send_buf_used = 0;
|
client->send_buf_used = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user