If non-blocking file descriptors or sockets are used, it can happen that incomplete message get sent. --- lib/databuffer.c | 7 +++++++ lib/databuffer.h | 1 + lib/obex_main.c | 2 +- 3 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/lib/databuffer.c b/lib/databuffer.c index 1c43324..72bd4ca 100644 --- a/lib/databuffer.c +++ b/lib/databuffer.c @@ -113,6 +113,13 @@ size_t buf_total_size(const buf_t *p) return p->head_avail + p->data_avail + p->tail_avail + p->data_size; } +int buf_empty(const buf_t *p) +{ + if (!p) + return 1; + return (p->data_size == 0); +} + void buf_resize(buf_t *p, size_t new_size) { uint8_t *tmp; diff --git a/lib/databuffer.h b/lib/databuffer.h index f55a056..2ef8204 100644 --- a/lib/databuffer.h +++ b/lib/databuffer.h @@ -47,6 +47,7 @@ typedef struct databuffer buf_t; buf_t *buf_new(size_t default_size); size_t buf_total_size(const buf_t *p); +int buf_empty(const buf_t *p); void buf_resize(buf_t *p, size_t new_size); buf_t *buf_reuse(buf_t *p); void *buf_reserve_begin(buf_t *p, size_t data_size); diff --git a/lib/obex_main.c b/lib/obex_main.c index 387f271..14a5263 100644 --- a/lib/obex_main.c +++ b/lib/obex_main.c @@ -221,7 +221,7 @@ int obex_data_request(obex_t *self, buf_t *msg, int opcode) status = obex_transport_write(self, msg); if (status > 0) buf_remove_begin(msg, status); - } while (status >= 0 && obex_get_buffer_status(msg)); + } while (status >= 0 && !buf_empty(msg)); return status; } -- 1.7.5.4 ------------------------------------------------------------------------------ AppSumo Presents a FREE Video for the SourceForge Community by Eric Ries, the creator of the Lean Startup Methodology on "Lean Startup Secrets Revealed." This video shows you how to validate your ideas, optimize your ideas and identify your business strategy. http://p.sf.net/sfu/appsumosfdev2dev _______________________________________________ Openobex-users mailing list Openobex-users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/openobex-users