/soc/2013/ashmew2/filetransferY: c0b7ead84a9e: Changed GByteArra...

Ashish Gupta ashmew2 at gmail.com
Sun Feb 16 07:07:14 EST 2014


Changeset: c0b7ead84a9ee41dd116b857bbf8c3bd793372a5
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2014-02-16 15:27 +0530
Branch:	 default
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferY/rev/c0b7ead84a9e

Description:

Changed GByteArray to PurpleCircularBuffer

diffstat:

 libpurple/protocols/jabber/google/google_session.c |   3 +-
 libpurple/protocols/jabber/google/google_session.h |   2 +-
 libpurple/protocols/jabber/google/google_share.c   |  25 ++++++++++-----------
 libpurple/xfer.c                                   |   2 +-
 4 files changed, 15 insertions(+), 17 deletions(-)

diffs (101 lines):

diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -100,8 +100,7 @@ google_session_destroy(GoogleSession *se
 				share_session);
 			g_object_unref(share_session->share_agent);
 		}
-
-		g_byte_array_unref(share_session->buffer);
+		purple_circular_buffer_reset(share_session->buffer);
 
 		for (temp = share_session->remote_share_candidates; temp; temp =
 			     g_slist_delete_link(temp, temp)) {
diff --git a/libpurple/protocols/jabber/google/google_session.h b/libpurple/protocols/jabber/google/google_session.h
--- a/libpurple/protocols/jabber/google/google_session.h
+++ b/libpurple/protocols/jabber/google/google_session.h
@@ -49,7 +49,7 @@ typedef struct {
 				 */
 	gchar *channel_name;
 	NiceComponentState agent_state;
-	GByteArray *buffer;
+	PurpleCircularBuffer *buffer;
 	GoogleXferChannelState channel_state;
 	gint stream_id;
 	gboolean candidates_gathered;
diff --git a/libpurple/protocols/jabber/google/google_share.c b/libpurple/protocols/jabber/google/google_share.c
--- a/libpurple/protocols/jabber/google/google_share.c
+++ b/libpurple/protocols/jabber/google/google_share.c
@@ -197,7 +197,8 @@ cb_nice_recv(NiceAgent *agent, guint str
 			curlen+=len;
 
 			if (len <= purple_xfer_get_bytes_remaining(xfer)) {
-				g_byte_array_append(share_session->buffer, curr, len);
+				purple_circular_buffer_append(share_session->buffer, curr,
+								len);
 				purple_xfer_prpl_ready(xfer);
 			} else {
 				purple_debug_error("google-share",
@@ -777,7 +778,7 @@ gtalk_xfer_end(PurpleXfer *xfer)
 }
 
 static gssize
-gtalk_xfer_read(guchar **out_buffer, PurpleXfer *xfer)
+gtalk_xfer_read(guchar **out_buffer, size_t buf_size, PurpleXfer *xfer)
 {
 	GoogleSession *session =
 		(GoogleSession *) purple_xfer_get_protocol_data(xfer);
@@ -789,16 +790,14 @@ gtalk_xfer_read(guchar **out_buffer, Pur
 	gsize tmp;
 
 	/*	size = share_session->buffer->bufused;*/
-	size = g_bytes_get_size(share_session->buffer);
+	size = purple_circular_buffer_get_used(share_session->buffer);
 	*out_buffer = buffer = g_malloc(size);
-	gsize total_read = 0;
-	while (total_read<size) {
-		gsize dsize;
-		gconstpointer *read_ptr = g_bytes_get_data(share_session->buffer, &dsize);
-		memcpy(buffer, read_ptr, dsize);
-		total_read += dsize;
-		buffer+=dsize;
-		g_byte_array_remove_range(share_session->buffer, 0, dsize);
+
+	while ((tmp = purple_circular_buffer_get_max_read(share_session->buffer))) {
+		const gchar *output = purple_circular_buffer_get_output(share_session->buffer);
+		memcpy(buffer, output, tmp);
+		buffer += tmp;
+		purple_circular_buffer_mark_read(share_session->buffer, tmp);
 	}
 
 	return size;
@@ -1109,7 +1108,7 @@ gtalk_xfer_new_session(JabberStream *js,
 		jid = g_strdup(who);
 	}
 
-	share_session->buffer = g_byte_array_sized_new(65536);
+	share_session->buffer = purple_circular_buffer_new(65536);
 	session->id.id = jabber_get_next_id(js);
 	session->id.initiator = me;
 	session->share = 1;
@@ -1272,7 +1271,7 @@ gtalk_xfer_handle_initiate(JabberStream 
 		purple_xfer_set_end_fnc(share_session->xfer, gtalk_xfer_end);
 
 		purple_xfer_set_protocol_data(share_session->xfer, session);
-		share_session->buffer = g_byte_array_sized_new(65536);
+		share_session->buffer = purple_circular_buffer_new(65536);
 		session->session_data = share_session;
 
 		result = jabber_iq_new(js,JABBER_IQ_RESULT);
diff --git a/libpurple/xfer.c b/libpurple/xfer.c
--- a/libpurple/xfer.c
+++ b/libpurple/xfer.c
@@ -1264,7 +1264,7 @@ purple_xfer_write_file(PurpleXfer *xfer,
 			purple_xfer_cancel_local(xfer);
 			return FALSE;
 		}
-		wc = fwrite(buffer, size, 1, priv->dest_fp);
+		wc = fwrite(buffer, 1, size, priv->dest_fp);
 	}
 
 	if (wc != size) {



More information about the Commits mailing list