* [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0
@ 2012-01-11 13:22 Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 2/3] gobex: introduce g_obex_get_rsp_pkt Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2012-01-11 13:22 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When calling driver_get_headers it may not be ready but after the backend
respond the result can still be 0 which indicades no headers need to
added and we can start sending the body.
---
src/obex.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/src/obex.c b/src/obex.c
index 6307eaa..eb91f4c 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -643,16 +643,26 @@ static gssize driver_get_headers(struct obex_session *os)
total += len;
}
- if (total == 0) {
- g_obex_packet_free(rsp);
- return 0;
+ if (total != 0) {
+ g_obex_send(os->obex, rsp, NULL);
+ os->get_rsp = g_obex_add_request_function(os->obex,
+ G_OBEX_OP_GET,
+ cmd_get_rsp, os);
+ goto done;
}
- g_obex_send(os->obex, rsp, NULL);
-
- os->get_rsp = g_obex_add_request_function(os->obex, G_OBEX_OP_GET,
- cmd_get_rsp, os);
+ g_obex_packet_free(rsp);
+ if (os->size != OBJECT_SIZE_UNKNOWN && os->size < UINT32_MAX)
+ g_obex_get_rsp(os->obex, send_data, transfer_complete,
+ os, NULL,
+ G_OBEX_HDR_LENGTH, os->size,
+ G_OBEX_HDR_INVALID);
+ else
+ g_obex_get_rsp(os->obex, send_data, transfer_complete,
+ os, NULL,
+ G_OBEX_HDR_INVALID);
+done:
os->headers_sent = TRUE;
print_event(-1, G_OBEX_RSP_CONTINUE);
@@ -887,22 +897,8 @@ int obex_get_stream_start(struct obex_session *os, const char *filename)
g_obex_suspend(os->obex);
os->driver->set_io_watch(os->object, handle_async_io, os);
return 0;
- } else if (err < 0) {
+ } else if (err < 0)
return err;
- } else if (err > 0)
- return 0;
-
- if (os->size != OBJECT_SIZE_UNKNOWN && os->size < UINT32_MAX)
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_LENGTH, os->size,
- G_OBEX_HDR_INVALID);
- else
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_INVALID);
-
- print_event(G_OBEX_OP_GET, G_OBEX_RSP_SUCCESS);
return 0;
}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH obexd 2/3] gobex: introduce g_obex_get_rsp_pkt
2012-01-11 13:22 [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Luiz Augusto von Dentz
@ 2012-01-11 13:22 ` Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 3/3] Fix not responding SUCCESS code to GET in some conditions Luiz Augusto von Dentz
2012-01-11 13:55 ` [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2012-01-11 13:22 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
g_obex_get_rsp_pkt takes a response packet which sometimes is more
convenient for adding headers.
---
gobex/gobex-transfer.c | 35 +++++++++++++++++++++++------------
gobex/gobex.h | 4 ++++
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 614d2d1..a779e4f 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -543,16 +543,12 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
return ret;
}
-static void transfer_get_req_first(struct transfer *transfer,
- guint8 first_hdr_id, va_list args)
+static void transfer_get_req_first(struct transfer *transfer, GObexPacket *rsp)
{
GError *err = NULL;
- GObexPacket *rsp;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
- rsp = g_obex_packet_new_valist(G_OBEX_RSP_CONTINUE, TRUE,
- first_hdr_id, args);
g_obex_packet_add_body(rsp, get_get_data, transfer);
if (!g_obex_send(transfer->obex, rsp, &err)) {
@@ -578,12 +574,11 @@ static void transfer_get_req(GObex *obex, GObexPacket *req, gpointer user_data)
}
}
-guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
- GObexFunc complete_func, gpointer user_data,
- GError **err, guint8 first_hdr_id, ...)
+guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
+ GObexDataProducer data_func, GObexFunc complete_func,
+ gpointer user_data, GError **err)
{
struct transfer *transfer;
- va_list args;
guint id;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);
@@ -591,9 +586,7 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_producer = data_func;
- va_start(args, first_hdr_id);
- transfer_get_req_first(transfer, first_hdr_id, args);
- va_end(args);
+ transfer_get_req_first(transfer, rsp);
if (!g_slist_find(transfers, transfer))
return 0;
@@ -611,6 +604,24 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
return transfer->id;
}
+guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
+ GObexFunc complete_func, gpointer user_data,
+ GError **err, guint8 first_hdr_id, ...)
+{
+ GObexPacket *rsp;
+ va_list args;
+
+ g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);
+
+ va_start(args, first_hdr_id);
+ rsp = g_obex_packet_new_valist(G_OBEX_RSP_CONTINUE, TRUE,
+ first_hdr_id, args);
+ va_end(args);
+
+ return g_obex_get_rsp_pkt(obex, rsp, data_func, complete_func,
+ user_data, err);
+}
+
gboolean g_obex_cancel_transfer(guint id)
{
struct transfer *transfer = NULL;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index f3a7f94..1c47c68 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -118,6 +118,10 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...);
+guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
+ GObexDataProducer data_func, GObexFunc complete_func,
+ gpointer user_data, GError **err);
+
gboolean g_obex_cancel_transfer(guint id);
const char *g_obex_strerror(guint8 err_code);
--
1.7.7.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH obexd 3/3] Fix not responding SUCCESS code to GET in some conditions
2012-01-11 13:22 [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 2/3] gobex: introduce g_obex_get_rsp_pkt Luiz Augusto von Dentz
@ 2012-01-11 13:22 ` Luiz Augusto von Dentz
2012-01-11 13:55 ` [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2012-01-11 13:22 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When there is no body to be transfer obexd is responding with CONTINUE.
---
src/obex.c | 71 ++++++++++++++---------------------------------------------
1 files changed, 17 insertions(+), 54 deletions(-)
diff --git a/src/obex.c b/src/obex.c
index eb91f4c..baa5904 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -574,33 +574,13 @@ static void transfer_complete(GObex *obex, GError *err, gpointer user_data)
}
}
-static void cmd_get_rsp(GObex *obex, GObexPacket *req, gpointer user_data)
-{
- struct obex_session *os = user_data;
-
- DBG("");
-
- print_event(G_OBEX_OP_GET, -1);
-
- if (os->size != OBJECT_SIZE_UNKNOWN && os->size < UINT32_MAX)
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_LENGTH, os->size,
- G_OBEX_HDR_INVALID);
- else
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_INVALID);
-
- print_event(G_OBEX_OP_GET, G_OBEX_RSP_CONTINUE);
-}
-
-static gssize driver_get_headers(struct obex_session *os)
+static int driver_get_headers(struct obex_session *os)
{
GObexPacket *rsp;
- gssize len, total = 0;
+ gssize len;
guint8 data[255];
guint8 id;
+ GObexHeader *hdr;
DBG("name=%s type=%s object=%p", os->name, os->type, os->object);
@@ -613,16 +593,13 @@ static gssize driver_get_headers(struct obex_session *os)
if (os->headers_sent)
return 0;
- if (os->driver->get_next_header == NULL) {
- os->headers_sent = TRUE;
- return 0;
- }
-
rsp = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, G_OBEX_HDR_INVALID);
+
+ if (os->driver->get_next_header == NULL)
+ goto done;
+
while ((len = os->driver->get_next_header(os->object, &data,
sizeof(data), &id))) {
- GObexHeader *hdr;
-
if (len < 0) {
error("get_next_header(): %s (%zd)", strerror(-len),
-len);
@@ -640,34 +617,22 @@ static gssize driver_get_headers(struct obex_session *os)
hdr = g_obex_header_new_bytes(id, data, len);
g_obex_packet_add_header(rsp, hdr);
- total += len;
}
- if (total != 0) {
- g_obex_send(os->obex, rsp, NULL);
- os->get_rsp = g_obex_add_request_function(os->obex,
- G_OBEX_OP_GET,
- cmd_get_rsp, os);
- goto done;
+done:
+ if (os->size != OBJECT_SIZE_UNKNOWN && os->size < UINT32_MAX) {
+ hdr = g_obex_header_new_uint32(G_OBEX_HDR_LENGTH, os->size);
+ g_obex_packet_add_header(rsp, hdr);
}
- g_obex_packet_free(rsp);
- if (os->size != OBJECT_SIZE_UNKNOWN && os->size < UINT32_MAX)
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_LENGTH, os->size,
- G_OBEX_HDR_INVALID);
- else
- g_obex_get_rsp(os->obex, send_data, transfer_complete,
- os, NULL,
- G_OBEX_HDR_INVALID);
+ g_obex_get_rsp_pkt(os->obex, rsp, send_data, transfer_complete, os,
+ NULL);
-done:
os->headers_sent = TRUE;
print_event(-1, G_OBEX_RSP_CONTINUE);
- return total;
+ return 0;
}
static gboolean handle_async_io(void *object, int flags, int err,
@@ -893,13 +858,11 @@ int obex_get_stream_start(struct obex_session *os, const char *filename)
os->size = size;
err = driver_get_headers(os);
- if (err == -EAGAIN) {
- g_obex_suspend(os->obex);
- os->driver->set_io_watch(os->object, handle_async_io, os);
- return 0;
- } else if (err < 0)
+ if (err != -EAGAIN)
return err;
+ g_obex_suspend(os->obex);
+ os->driver->set_io_watch(os->object, handle_async_io, os);
return 0;
}
--
1.7.7.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0
2012-01-11 13:22 [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 2/3] gobex: introduce g_obex_get_rsp_pkt Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 3/3] Fix not responding SUCCESS code to GET in some conditions Luiz Augusto von Dentz
@ 2012-01-11 13:55 ` Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2012-01-11 13:55 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
On Wed, Jan 11, 2012, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> When calling driver_get_headers it may not be ready but after the backend
> respond the result can still be 0 which indicades no headers need to
> added and we can start sending the body.
> ---
> src/obex.c | 40 ++++++++++++++++++----------------------
> 1 files changed, 18 insertions(+), 22 deletions(-)
All three patches have been pushed upstream. Thanks.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-01-11 13:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-11 13:22 [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 2/3] gobex: introduce g_obex_get_rsp_pkt Luiz Augusto von Dentz
2012-01-11 13:22 ` [PATCH obexd 3/3] Fix not responding SUCCESS code to GET in some conditions Luiz Augusto von Dentz
2012-01-11 13:55 ` [PATCH obexd 1/3] Fix not responding when driver_get_headers return 0 Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).