All of lore.kernel.org
 help / color / mirror / Atom feed
From: Slawomir Bochenski <lkslawek@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Slawomir Bochenski <lkslawek@gmail.com>
Subject: [PATCH v3 4/4] Fix handling asynchronous plugin reads
Date: Mon, 13 Jun 2011 13:24:37 +0200	[thread overview]
Message-ID: <1307964277-12590-1-git-send-email-lkslawek@gmail.com> (raw)
In-Reply-To: <1307957658-11330-3-git-send-email-lkslawek@gmail.com>

Calling OBEX_ResumeRequest() from handle_async_io() may result in direct
calling obex_event_cb() (this happens when obex_write_stream() will
deliver not enough bytes to fully fill OpenOBEX TX packet). In this case
set_io_watch will fail if handle_async_io() is called from
obex_object_set_io_flags(), because the watch is already installed.
Originally when code returns from OBEX_ResumeRequest(), handle_async_io()
returns FALSE which makes obex_object_set_io_flags() remove this watch.

This patch adds variable for tracking whether subsequent calls suspended
get request, causing obex_object_set_io_flags() remove the watch only
when the request is not suspended.
---
 src/obex-priv.h |    1 +
 src/obex.c      |   19 +++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/obex-priv.h b/src/obex-priv.h
index 8c722dc..164bc78 100644
--- a/src/obex-priv.h
+++ b/src/obex-priv.h
@@ -46,6 +46,7 @@ struct obex_session {
 	obex_object_t *obj;
 	struct obex_mime_type_driver *driver;
 	gboolean streaming;
+	gboolean suspended;
 };
 
 int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
diff --git a/src/obex.c b/src/obex.c
index 1bdb6be..99fedc3 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -311,6 +311,7 @@ static void os_reset_session(struct obex_session *os)
 	os->offset = 0;
 	os->size = OBJECT_SIZE_DELETE;
 	os->streaming = FALSE;
+	os->suspended = FALSE;
 }
 
 static void obex_session_free(struct obex_session *os)
@@ -698,6 +699,8 @@ static void suspend_get(struct obex_session *os, obex_t *obex,
 {
 	obex_headerdata_t hd;
 
+	os->suspended = TRUE;
+
 	if (os->streaming) {
 		OBEX_SuspendRequest(obex, obj);
 		return;
@@ -728,13 +731,21 @@ static gboolean handle_async_io(void *object, int flags, int err,
 		ret = obex_read_stream(os, os->obex, os->obj);
 
 proceed:
-	if (ret < 0) {
+	os->suspended = FALSE;
+
+	if (ret == -EAGAIN) {
+		suspend_get(os, os->obex, os->obj);
+	} else if (ret < 0) {
 		os_set_response(os->obj, err);
 		OBEX_CancelRequest(os->obex, TRUE);
-	} else
+	} else {
 		OBEX_ResumeRequest(os->obex);
+	}
 
-	return FALSE;
+	if (os->suspended)
+		return TRUE;
+	else
+		return FALSE;
 }
 
 static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
@@ -1225,7 +1236,7 @@ static void obex_event_cb(obex_t *obex, obex_object_t *obj, int mode,
 	case OBEX_EV_STREAMEMPTY:
 		err = obex_write_stream(os, obex, obj);
 		if (err == -EAGAIN) {
-			OBEX_SuspendRequest(obex, obj);
+			suspend_get(os, obex, obj);
 			os->obj = obj;
 			os->driver->set_io_watch(os->object, handle_async_io,
 									os);
-- 
1.7.4.1


  reply	other threads:[~2011-06-13 11:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-07 13:09 Various GET functionality fixes (obsoletes: Renewed new missed calls handling) Slawomir Bochenski
2011-06-07 13:09 ` [PATCH 1/4] Revert API changes to mime driver read function Slawomir Bochenski
2011-06-07 13:09 ` [PATCH 2/4] Remove redundant code Slawomir Bochenski
2011-06-07 13:10 ` [PATCH 3/4] Modify obex_write_stream logic Slawomir Bochenski
2011-06-07 13:10 ` [PATCH 4/4] Fix handling asynchronous plugin reads Slawomir Bochenski
2011-06-08  4:27   ` Luiz Augusto von Dentz
2011-06-13  9:34     ` Various GET functionality fixes (obsoletes: Renewed new missed calls handling) Slawomir Bochenski
2011-06-13  9:34       ` [PATCH 3/4] Modify obex_write_stream logic Slawomir Bochenski
2011-06-15 13:30         ` Luiz Augusto von Dentz
2011-06-15 13:39           ` Johan Hedberg
2011-06-15 14:59             ` Slawomir Bochenski
2011-06-16  8:27               ` Luiz Augusto von Dentz
2011-06-16  8:58                 ` Slawomir Bochenski
2011-06-16  9:19                   ` Slawomir Bochenski
2011-06-16 16:51                 ` Vinicius Costa Gomes
2011-06-17  7:35                   ` Luiz Augusto von Dentz
2011-06-17  7:59                     ` Slawomir Bochenski
2011-06-13  9:34       ` [PATCH 4/4] Fix handling asynchronous plugin reads Slawomir Bochenski
2011-06-13 11:24         ` Slawomir Bochenski [this message]
2011-06-14  6:33           ` [PATCH v3 " Luiz Augusto von Dentz
2011-06-14  6:58             ` Slawomir Bochenski
2011-06-15 13:06               ` Johan Hedberg
2011-06-15 15:08                 ` Slawomir Bochenski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1307964277-12590-1-git-send-email-lkslawek@gmail.com \
    --to=lkslawek@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.