summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsandmann <sandmann>2007-01-15 02:56:28 +0000
committersandmann <sandmann>2007-01-15 02:56:28 +0000
commitfa1cd758381eb5380954996d466736ec88179412 (patch)
treeb168a97cf66da8d49a1ece55a491242e49401ac9
parente3411fa8e046e3ba92c9b9c626ce5a63337b95e5 (diff)
convert http write buffer
-rw-r--r--src/lachttp.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/lachttp.c b/src/lachttp.c
index aa2b120..77b28a5 100644
--- a/src/lachttp.c
+++ b/src/lachttp.c
@@ -1,7 +1,7 @@
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
/* Lac - Library for asynchronous communication
- * Copyright (C) 2001, 2002, 2003 Søren Sandmann (sandmann@daimi.au.dk)
+ * Copyright (C) 2001-2007 Søren Sandmann (sandmann@daimi.au.dk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -249,7 +249,7 @@ struct _HttpTransport {
gboolean pipelining;
gboolean broken_server;
guint successful_requests;
- GString * write_buffer;
+ LacByteQueue * write_buffer;
gint write_timeout;
gint answer_timeout;
gboolean did_pipeline; /* if TRUE, we did pipeline at some point,
@@ -435,8 +435,10 @@ request_serialize (LacHttpRequest *request, const gchar *connection)
const gchar *method = "";
GList *list;
+#if 0
const gchar *content;
gsize content_len;
+#endif
result = g_string_new ("");
@@ -497,9 +499,15 @@ request_serialize (LacHttpRequest *request, const gchar *connection)
g_string_append_printf (result, CRLF);
+#if 0
+ /* FIXME: we can't append the content here since it might be binary,
+ * and our caller calls strlen() on it. We need to return a GString
+ * or something.
+ */
content = lac_byte_queue_peek (request->content, &content_len);
g_string_append_len (result, content, content_len);
+#endif
return g_string_free (result, FALSE);
}
@@ -1934,9 +1942,12 @@ http_host_cancel_request (HttpHost *host, LacHttpRequest *request)
static void
http_transport_delete_write_buffer (HttpTransport *transport)
{
- if (transport->write_buffer->len > 0)
+ gsize n_bytes = lac_byte_queue_get_length (transport->write_buffer);
+
+ if (n_bytes > 0)
{
- g_string_truncate (transport->write_buffer, 0);
+ lac_byte_queue_delete_head (transport->write_buffer, n_bytes);
+
if (transport->write_timeout)
{
g_source_remove (transport->write_timeout);
@@ -2068,13 +2079,15 @@ http_transport_reset_answer_timeout (HttpTransport *transport)
static void
http_transport_flush_write_buffer (HttpTransport *transport)
{
- if (transport->write_buffer->len > 0)
+ gsize n_bytes;
+ const gchar *bytes = lac_byte_queue_peek (transport->write_buffer, &n_bytes);
+
+ if (n_bytes > 0)
{
- lac_connection_write (
- transport->connection,
- transport->write_buffer->str, transport->write_buffer->len);
-
- g_string_truncate (transport->write_buffer, 0);
+ /* FIXME: should we have a lac_connection_write_byte_queue()? */
+ lac_connection_write (transport->connection, (guint8 *)bytes, n_bytes);
+
+ lac_byte_queue_delete_head (transport->write_buffer, n_bytes);
}
}
@@ -2131,8 +2144,8 @@ http_transport_transmit_request (HttpTransport *transport,
g_source_remove (transport->write_timeout);
transport->write_timeout = 0;
}
-
- g_string_append (transport->write_buffer, serialized);
+
+ lac_byte_queue_append (transport->write_buffer, serialized, strlen (serialized));
g_free (serialized);
#if 0
@@ -2582,7 +2595,7 @@ http_transport_new (HttpHost *host,
transport->pipelining = pipelining;
transport->broken_server = broken;
transport->successful_requests = 0;
- transport->write_buffer = g_string_new ("");
+ transport->write_buffer = lac_byte_queue_new ();
transport->write_timeout = 0;
transport->answer_timeout = 0;
@@ -2613,7 +2626,7 @@ http_transport_destroy (HttpTransport *transport)
g_assert (g_queue_is_empty (transport->in_progress));
g_queue_free (transport->in_progress);
- g_string_free (transport->write_buffer, TRUE);
+ lac_byte_queue_free (transport->write_buffer, TRUE);
g_free (transport);
}