---
 lib/fdobex.c |   58 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/lib/fdobex.c b/lib/fdobex.c
index fa2d64a..cdbc26a 100644
--- a/lib/fdobex.c
+++ b/lib/fdobex.c
@@ -68,6 +68,9 @@ static int fdobex_write(obex_t *self, buf_t *msg)
        struct obex_transport *trans = &self->trans;
        int fd = trans->data.fd.writefd;
        size_t size = msg->data_size;
+       int status;
+       fd_set fdset;
+       struct timeval time = {trans->timeout, 0};
 
        if (size == 0)
                return 0;
@@ -76,35 +79,60 @@ static int fdobex_write(obex_t *self, buf_t *msg)
                size = trans->mtu;
        DEBUG(1, "sending %zu bytes\n", size);
 
-       if (trans->timeout >= 0) {
-               /* setup everything to check for blocking writes */
-               fd_set fdset;
-               struct timeval time = {trans->timeout, 0};
-               int status;
-
-               FD_ZERO(&fdset);
-               FD_SET(fd, &fdset);
+       FD_ZERO(&fdset);
+       FD_SET(fd, &fdset);
+       if (trans->timeout >= 0)
                status = select((int)fd+1, NULL, &fdset, NULL, &time);
-               if (status == 0)
-                       return 0;
-       }
+       else
+               status = select((int)fd+1, NULL, &fdset, NULL, NULL);
+
+       if (status == 0)
+               return 0;
 
 #ifdef _WIN32
-       return _write(fd, msg->data, size);
+       status = _write(fd, msg->data, size);
 #else
-       return write(fd, msg->data, size);
+       status = write(fd, msg->data, size);
 #endif
+
+       /* The following are not really transport errors. */
+       if (status == -1 &&
+           (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
+               status = 0;
+
+       return status;
 }
 
 static int fdobex_read(obex_t *self, void *buf, int buflen)
 {
        struct obex_transport *trans = &self->trans;
+       int fd = trans->fd;
+       int status;
+       fd_set fdset;
+       struct timeval time = {trans->timeout, 0};
+
+       FD_ZERO(&fdset);
+       FD_SET(fd, &fdset);
+       if (trans->timeout >= 0)
+               status = select((int)fd+1, NULL, &fdset, NULL, &time);
+       else
+               status = select((int)fd+1, NULL, &fdset, NULL, NULL);
+
+       if (status == 0)
+               return 0;
 
 #ifdef _WIN32
-       return  _read(trans->fd, buf, buflen);
+       status = _read(fd, buf, buflen);
 #else
-       return read(trans->fd, buf, buflen);
+       status = read(fd, buf, buflen);
 #endif
+
+       /* The following are not really transport errors */
+       if (status == -1 &&
+           (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
+               status = 0;
+
+       return status;
 }
 
 void fdobex_get_ops(struct obex_transport_ops* ops)
-- 
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

Reply via email to