--- include/openobex/obex_const.h | 1 + lib/obex.c | 1 + lib/obex_main.c | 22 ++++++++++++++++------ lib/obex_transport.c | 19 +++++++++++++++++-- 4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/include/openobex/obex_const.h b/include/openobex/obex_const.h index b4bad7f..8276aae 100644 --- a/include/openobex/obex_const.h +++ b/include/openobex/obex_const.h @@ -167,6 +167,7 @@ typedef union { #define OBEX_FL_FILTERHINT (1 << 2) /* Filter devices based on hint bit */ #define OBEX_FL_FILTERIAS (1 << 3) /* Filter devices based on IAS entry */ #define OBEX_FL_CLOEXEC (1 << 4) /* Set CLOEXEC flag on file descriptors */ +#define OBEX_FL_NONBLOCK (1 << 5) /* Set the NONBLOCK flag on file descriptors */ /* For OBEX_ObjectAddHeader */ #define OBEX_FL_FIT_ONE_PACKET 0x01 /* This header must fit in one packet */ diff --git a/lib/obex.c b/lib/obex.c index 3aa6bac..49de8cd 100644 --- a/lib/obex.c +++ b/lib/obex.c @@ -82,6 +82,7 @@ - #OBEX_FL_FILTERHINT : Filter target devices based on Obex hint bit - #OBEX_FL_FILTERIAS : Filter target devices based on IAS entry - #OBEX_FL_CLOEXEC : Open all sockets with SO_CLOEXEC set + - #OBEX_FL_NONBLOCK : Open all sockets non-blocking \return an OBEX handle or NULL on error. */ LIB_SYMBOL diff --git a/lib/obex_main.c b/lib/obex_main.c index b3a8a45..cc24735 100644 --- a/lib/obex_main.c +++ b/lib/obex_main.c @@ -67,6 +67,7 @@ socket_t obex_create_socket(obex_t *self, int domain) { socket_t fd; int type = SOCK_STREAM, proto = 0; + long status; DEBUG(4, "\n"); @@ -80,6 +81,12 @@ socket_t obex_create_socket(obex_t *self, int domain) else fd = socket(domain, type, proto); + if (self->init_flags & OBEX_FL_NONBLOCK) { + status = fcntl(fd, F_GETFL); + status |= O_NONBLOCK; + fcntl(fd, F_SETFL, status); + } + return fd; } @@ -211,7 +218,11 @@ void obex_response_request(obex_t *self, uint8_t opcode) msg = buf_reuse(self->tx_msg); obex_data_request_prepare(self, msg, opcode | OBEX_FINAL); - obex_data_request(self, msg); + do { + int status = obex_data_request(self, msg); + if (status < 0) + break; + } while (!buf_empty(msg)); } /* @@ -249,11 +260,10 @@ int obex_data_request(obex_t *self, buf_t *msg) DEBUG(1, "len = %lu bytes\n", (unsigned long) msg->data_size); - do { - status = obex_transport_write(self, msg); - if (status > 0) - buf_remove_begin(msg, status); - } while (status >= 0 && !buf_empty(msg)); + status = obex_transport_write(self, msg); + if (status > 0) + buf_remove_begin(msg, status); + return status; } diff --git a/lib/obex_transport.c b/lib/obex_transport.c index 6207279..2ca461e 100644 --- a/lib/obex_transport.c +++ b/lib/obex_transport.c @@ -366,6 +366,7 @@ int obex_transport_do_send (obex_t *self, buf_t *msg) struct obex_transport *trans = &self->trans; int fd = trans->fd; size_t size = msg->data_size; + int status; if (size == 0) return 0; @@ -388,7 +389,14 @@ int obex_transport_do_send (obex_t *self, buf_t *msg) } /* call send() if no error */ - return send(fd, msg->data, size, 0); + status = send(fd, msg->data, size, 0); + + /* The following are not really transport errors. */ + if (status == -1 && + (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) + status = 0; + + return status; } /* @@ -408,7 +416,14 @@ int obex_transport_write(obex_t *self, buf_t *msg) int obex_transport_do_recv (obex_t *self, void *buf, int buflen) { struct obex_transport *trans = &self->trans; - return recv(trans->fd, buf, buflen, 0); + int status = recv(trans->fd, buf, buflen, 0); + + /* The following are not really transport errors. */ + if (status == -1 && + (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) + status = 0; + + 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