From 39439b80f5d1574e67f337a047869cf067c396b7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Jan 2013 23:42:06 +0100 Subject: Client: rebase on the new BufferedSocket class --- src/ClientEvent.cxx | 90 +++++------------------------------------------------ 1 file changed, 8 insertions(+), 82 deletions(-) (limited to 'src/ClientEvent.cxx') diff --git a/src/ClientEvent.cxx b/src/ClientEvent.cxx index 201709c7..905cf0c0 100644 --- a/src/ClientEvent.cxx +++ b/src/ClientEvent.cxx @@ -19,92 +19,18 @@ #include "config.h" #include "ClientInternal.hxx" -#include "Main.hxx" -#include "event/Loop.hxx" -#include - -static gboolean -client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition, - gpointer data) +void +Client::OnSocketError(GError *error) { - Client *client = (Client *)data; - - assert(!client->IsExpired()); - - if (condition != G_IO_OUT) { - client->SetExpired(); - return false; - } - - client_write_deferred(client); + g_warning("error on client %d: %s", num, error->message); + g_error_free(error); - if (client->IsExpired()) { - client->Close(); - return false; - } - - g_timer_start(client->last_activity); - - if (client->output_buffer.IsEmpty()) { - /* done sending deferred buffers exist: schedule - read */ - client->source_id = g_io_add_watch(client->channel, - GIOCondition(G_IO_IN|G_IO_ERR|G_IO_HUP), - client_in_event, client); - return false; - } - - /* write more */ - return true; + SetExpired(); } -gboolean -client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition, - gpointer data) +void +Client::OnSocketClosed() { - Client *client = (Client *)data; - enum command_return ret; - - assert(!client->IsExpired()); - - if (condition != G_IO_IN) { - client->SetExpired(); - return false; - } - - g_timer_start(client->last_activity); - - ret = client_read(client); - switch (ret) { - case COMMAND_RETURN_OK: - case COMMAND_RETURN_IDLE: - case COMMAND_RETURN_ERROR: - break; - - case COMMAND_RETURN_KILL: - client->Close(); - main_loop->Break(); - return false; - - case COMMAND_RETURN_CLOSE: - client->Close(); - return false; - } - - if (client->IsExpired()) { - client->Close(); - return false; - } - - if (!client->output_buffer.IsEmpty()) { - /* deferred buffers exist: schedule write */ - client->source_id = g_io_add_watch(client->channel, - GIOCondition(G_IO_OUT|G_IO_ERR|G_IO_HUP), - client_out_event, client); - return false; - } - - /* read more */ - return true; + SetExpired(); } -- cgit v1.2.3