The substates create situations where this function name doesn't fit anymore. To avoid confusion, it is renamed to OBEX_Work(). The timeout argument is now in milliseconds, the previous argument was in seconds which may be not fine enough. --- include/openobex/obex.h | 3 ++- lib/fdobex.c | 10 ++++++++-- lib/obex.c | 4 ++-- lib/obex_main.c | 2 +- lib/obex_main.h | 2 +- lib/obex_transport.c | 12 +++++++++--- lib/obex_transport.h | 4 ++-- lib/usb1obex.c | 6 +++--- lib/usbobex.c | 6 +++--- 9 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/include/openobex/obex.h b/include/openobex/obex.h index 315601d..1f7c916 100644 --- a/include/openobex/obex.h +++ b/include/openobex/obex.h @@ -84,6 +84,7 @@ OPENOBEX_SYMBOL(void) OBEX_SetUserCallBack(obex_t *self, void * data); OPENOBEX_SYMBOL(obex_t *) OBEX_ServerAccept(obex_t *server, obex_event_t eventcb, void * data); +#define OBEX_HandleInput(self, timeout) OBEX_Work((self), ((timeout)*1000)) /* * OBEX API @@ -116,7 +117,7 @@ OPENOBEX_SYMBOL(void *) OBEX_GetCustomData(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_TransportConnect(obex_t *self, struct sockaddr *saddr, int addlen); OPENOBEX_SYMBOL(int) OBEX_TransportDisconnect(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_CustomDataFeed(obex_t *self, uint8_t *inputbuf, int actual); -OPENOBEX_SYMBOL(int) OBEX_HandleInput(obex_t *self, int timeout); +OPENOBEX_SYMBOL(int) OBEX_Work(obex_t *self, long timeout); OPENOBEX_SYMBOL(int) OBEX_ServerRegister(obex_t *self, struct sockaddr *saddr, int addrlen); OPENOBEX_SYMBOL(obex_t *) OBEX_Accept(obex_t *server); diff --git a/lib/fdobex.c b/lib/fdobex.c index cdbc26a..0131fc3 100644 --- a/lib/fdobex.c +++ b/lib/fdobex.c @@ -70,7 +70,10 @@ static int fdobex_write(obex_t *self, buf_t *msg) size_t size = msg->data_size; int status; fd_set fdset; - struct timeval time = {trans->timeout, 0}; + struct timeval time = { + trans->timeout / 1000, + (trans->timeout % 1000) * 1000 + }; if (size == 0) return 0; @@ -109,7 +112,10 @@ static int fdobex_read(obex_t *self, void *buf, int buflen) int fd = trans->fd; int status; fd_set fdset; - struct timeval time = {trans->timeout, 0}; + struct timeval time = { + trans->timeout / 1000, + (trans->timeout % 1000) * 1000 + }; FD_ZERO(&fdset); FD_SET(fd, &fdset); diff --git a/lib/obex.c b/lib/obex.c index 0522bef..9cffea2 100644 --- a/lib/obex.c +++ b/lib/obex.c @@ -427,7 +427,7 @@ out_err: /** Let the OBEX parser do some work. \param self OBEX handle - \param timeout Maximum time to wait in seconds (-1 for infinite) + \param timeout Maximum time to wait in milliseconds (-1 for infinite) \return -1 on error, 0 on timeout, positive on success Let the OBEX parser read and process incoming data. If no data @@ -441,7 +441,7 @@ out_err: positive on success. */ LIB_SYMBOL -int CALLAPI OBEX_HandleInput(obex_t *self, int timeout) +int CALLAPI OBEX_Work(obex_t *self, long timeout) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); diff --git a/lib/obex_main.c b/lib/obex_main.c index a009275..733e190 100644 --- a/lib/obex_main.c +++ b/lib/obex_main.c @@ -348,7 +348,7 @@ static int obex_mode(obex_t *self) * Do some work on the current transferred object. * */ -int obex_work(obex_t *self, int timeout) +int obex_work(obex_t *self, long timeout) { int ret; diff --git a/lib/obex_main.h b/lib/obex_main.h index 82fea37..55eca62 100644 --- a/lib/obex_main.h +++ b/lib/obex_main.h @@ -70,7 +70,7 @@ socket_t obex_create_packet_socket(obex_t *self, int domain); int obex_delete_socket(struct obex *self, socket_t fd); void obex_deliver_event(struct obex *self, int event, int cmd, int rsp, int del); -int obex_work(struct obex *self, int timeout); +int obex_work(struct obex *self, long timeout); int obex_get_buffer_status(buf_t *msg); int obex_data_indication(struct obex *self); buf_t* obex_data_receive(obex_t *self); diff --git a/lib/obex_transport.c b/lib/obex_transport.c index 2ca461e..277a8a7 100644 --- a/lib/obex_transport.c +++ b/lib/obex_transport.c @@ -207,7 +207,10 @@ int obex_transport_standard_handle_input(obex_t *self) /* Wait for input */ if (trans->timeout >= 0) { - struct timeval time = { trans->timeout, 0 }; + struct timeval time = { + trans->timeout / 1000, + (trans->timeout % 1000) * 1000 + }; ret = select((int) highestfd + 1, &fdset, NULL, NULL, &time); } else { ret = select((int) highestfd + 1, &fdset, NULL, NULL, NULL); @@ -245,7 +248,7 @@ int obex_transport_standard_handle_input(obex_t *self) * Used when working in synchronous mode. * */ -int obex_transport_handle_input(obex_t *self, int timeout) +int obex_transport_handle_input(obex_t *self, long timeout) { DEBUG(4, "\n"); self->trans.timeout = timeout; @@ -378,7 +381,10 @@ int obex_transport_do_send (obex_t *self, buf_t *msg) if (trans->timeout >= 0) { /* setup everything to check for blocking writes */ fd_set fdset; - struct timeval time = {trans->timeout, 0}; + struct timeval time = { + trans->timeout / 1000, + (trans->timeout % 1000) * 1000 + }; int status; FD_ZERO(&fdset); diff --git a/lib/obex_transport.h b/lib/obex_transport.h index b7a4423..8c3d7cb 100644 --- a/lib/obex_transport.h +++ b/lib/obex_transport.h @@ -110,7 +110,7 @@ typedef struct obex_transport { socket_t fd; /* Socket descriptor */ socket_t serverfd; - int timeout; /* set timeout */ + long timeout; /* timeout in milliseconds */ int connected; /* Link connection state */ unsigned int mtu; /* Tx MTU of the link */ @@ -122,7 +122,7 @@ void obex_transport_cleanup(obex_t *self); void obex_transport_clone(obex_t *self, obex_t *old); void obex_transport_split(obex_t *self, obex_t *server); -int obex_transport_handle_input(struct obex *self, int timeout); +int obex_transport_handle_input(struct obex *self, long timeout); int obex_transport_connect_request(struct obex *self); void obex_transport_disconnect_request(struct obex *self); int obex_transport_listen(struct obex *self); diff --git a/lib/usb1obex.c b/lib/usb1obex.c index c00b55a..26f0c41 100644 --- a/lib/usb1obex.c +++ b/lib/usb1obex.c @@ -479,17 +479,17 @@ static int usbobex_disconnect_request(obex_t *self) return 1; } -static unsigned int usbobex_get_timeout(int timeout) +static unsigned int usbobex_get_timeout(long timeout) { /* uses closest to zero, 0 itself means infinite */ if (timeout == 0) { return 1; } else if (timeout > 0) { - if ((unsigned int)timeout > UINT_MAX/1000) + if ((unsigned int)timeout > UINT_MAX) return UINT_MAX; else - return timeout * 1000; + return timeout; } return 0; diff --git a/lib/usbobex.c b/lib/usbobex.c index 2ed26e1..a5f63f0 100644 --- a/lib/usbobex.c +++ b/lib/usbobex.c @@ -448,15 +448,15 @@ static int usbobex_disconnect_request(obex_t *self) return ret; } -static int usbobex_get_timeout(int timeout) +static int usbobex_get_timeout(long timeout) { - if (timeout < 0 || timeout > INT_MAX/1000) { + if (timeout < 0 || timeout > INT_MAX) { /* libusb-0.x doesn't know about waiting infinitely * so we try with the largest value possible */ return INT_MAX; } - return timeout*1000; + return timeout; } static int usbobex_write(obex_t *self, buf_t *msg) -- 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