Diff between b19d1fbde86e6722d5fd0704f948a1699533fcb6 and 42d94c84a262f58fb44a1475b7960a1edd3301e8

Changed Files

File Additions Deletions Status
gobex/gobex.c +28 -0 modified
gobex/gobex.h +4 -0 modified

Full Patch

diff --git a/gobex/gobex.c b/gobex/gobex.c
index 3ad645a..c3a8b2c 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -53,6 +53,8 @@ struct _GObex {
 	size_t tx_data;
 	size_t tx_sent;
 
+	gboolean suspended;
+
 	guint write_source;
 
 	gssize io_rx_mtu;
@@ -250,6 +252,11 @@ static gboolean write_data(GIOChannel *io, GIOCondition cond,
 		obex->tx_sent = 0;
 	}
 
+	if (obex->suspended) {
+		obex->write_source = 0;
+		return FALSE;
+	}
+
 	if (!obex->write(obex, NULL))
 		goto stop_tx;
 
@@ -268,6 +275,9 @@ static void enable_tx(GObex *obex)
 {
 	GIOCondition cond;
 
+	if (obex->suspended)
+		return;
+
 	if (obex->write_source > 0)
 		return;
 
@@ -512,6 +522,24 @@ gboolean g_obex_remove_request_function(GObex *obex, gint id)
 	return TRUE;
 }
 
+void g_obex_suspend(GObex *obex)
+{
+	if (obex->write_source > 0) {
+		g_source_remove(obex->write_source);
+		obex->write_source = 0;
+	}
+
+	obex->suspended = TRUE;
+}
+
+void g_obex_resume(GObex *obex)
+{
+	obex->suspended = FALSE;
+
+	if (g_queue_get_length(obex->tx_queue) > 0 || obex->tx_data > 0)
+		enable_tx(obex);
+}
+
 static void parse_connect_data(GObex *obex, GObexPacket *pkt)
 {
 	const struct connect_data *data;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 034213f..318add9 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -53,6 +53,10 @@ gint g_obex_add_request_function(GObex *obex, guint8 opcode,
 						GObexRequestFunc func,
 						gpointer user_data);
 gboolean g_obex_remove_request_function(GObex *obex, gint id);
+
+void g_obex_suspend(GObex *obex);
+void g_obex_resume(GObex *obex);
+
 GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
 						gssize rx_mtu, gssize tx_mtu);