aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientWrite.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-14 23:42:06 +0100
committerMax Kellermann <max@duempel.org>2013-01-15 12:15:33 +0100
commit39439b80f5d1574e67f337a047869cf067c396b7 (patch)
tree5e28e61d4895da86189d14cde9f1e238c18079a8 /src/ClientWrite.cxx
parent396480cf94fbeda581acb6a78c42c7ec610d04a4 (diff)
downloadmpd-39439b80f5d1574e67f337a047869cf067c396b7.tar.gz
mpd-39439b80f5d1574e67f337a047869cf067c396b7.tar.xz
mpd-39439b80f5d1574e67f337a047869cf067c396b7.zip
Client: rebase on the new BufferedSocket class
Diffstat (limited to 'src/ClientWrite.cxx')
-rw-r--r--src/ClientWrite.cxx91
1 files changed, 1 insertions, 90 deletions
diff --git a/src/ClientWrite.cxx b/src/ClientWrite.cxx
index 86abc152c..23b515a3d 100644
--- a/src/ClientWrite.cxx
+++ b/src/ClientWrite.cxx
@@ -20,98 +20,9 @@
#include "config.h"
#include "ClientInternal.hxx"
-#include <assert.h>
#include <string.h>
#include <stdio.h>
-static size_t
-client_write_direct(Client *client, const void *data, size_t length)
-{
- assert(client != NULL);
- assert(client->channel != NULL);
- assert(data != NULL);
- assert(length > 0);
-
- gsize bytes_written;
- GError *error = NULL;
- GIOStatus status =
- g_io_channel_write_chars(client->channel, (const gchar *)data,
- length, &bytes_written, &error);
- switch (status) {
- case G_IO_STATUS_NORMAL:
- return bytes_written;
-
- case G_IO_STATUS_AGAIN:
- return 0;
-
- case G_IO_STATUS_EOF:
- /* client has disconnected */
-
- client->SetExpired();
- return 0;
-
- case G_IO_STATUS_ERROR:
- /* I/O error */
-
- client->SetExpired();
- g_warning("failed to write to %i: %s",
- client->num, error->message);
- g_error_free(error);
- return 0;
- }
-
- /* unreachable */
- assert(false);
- return 0;
-}
-
-void
-client_write_deferred(Client *client)
-{
- assert(!client_is_expired(client));
-
- while (true) {
- size_t length;
- const void *data = client->output_buffer.Read(&length);
- if (data == nullptr)
- break;
-
- size_t nbytes = client_write_direct(client, data, length);
- if (nbytes == 0)
- return;
-
- client->output_buffer.Consume(nbytes);
-
- if (nbytes < length)
- return;
-
- g_timer_start(client->last_activity);
- }
-}
-
-static void
-client_defer_output(Client *client, const void *data, size_t length)
-{
- if (!client->output_buffer.Append(data, length)) {
- g_warning("[%u] output buffer size is "
- "larger than the max (%lu)",
- client->num,
- (unsigned long)client_max_output_buffer_size);
- /* cause client to close */
- client->SetExpired();
- return;
- }
-}
-
-void
-client_write_output(Client *client)
-{
- if (client->IsExpired())
- return;
-
- client_write_deferred(client);
-}
-
/**
* Write a block of data to the client.
*/
@@ -122,7 +33,7 @@ client_write(Client *client, const char *data, size_t length)
if (client->IsExpired() || length == 0)
return;
- client_defer_output(client, data, length);
+ client->Write(data, length);
}
void