/** Feed OBEX with data when using a custom transport. \param self OBEX handle \param inputbuf Pointer to custom data \param actual Length of buffer \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_CustomDataFeed(obex_t *self, uint8_t *inputbuf, int actual) { DEBUG(3, "\n"); obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail(inputbuf != NULL, -1); return obex_data_indication(self, inputbuf, actual); }
/* * Function obex_transport_handle_input(self, timeout) * * Used when working in synchronous mode. * */ int obex_transport_handle_input(obex_t *self, int timeout) { int ret; if (self->trans.type == OBEX_TRANS_CUSTOM) { if (self->ctrans.handleinput) ret = self->ctrans.handleinput(self, self->ctrans.customdata, timeout); else { DEBUG(4, "No handleinput-callback exist!\n"); ret = -1; } } else if (self->trans.type == OBEX_TRANS_USB && self->fd == INVALID_SOCKET) ret = obex_data_indication(self, NULL, 0); else { struct timeval time; fd_set fdset; socket_t highestfd = 0; DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); /* Check of we have any fd's to do select on. */ if (self->fd == INVALID_SOCKET && self->serverfd == INVALID_SOCKET) { DEBUG(0, "No valid socket is open\n"); return -1; } time.tv_sec = timeout; time.tv_usec = 0; /* Add the fd's to the set. */ FD_ZERO(&fdset); if (self->fd != INVALID_SOCKET) { FD_SET(self->fd, &fdset); if (self->fd > highestfd) highestfd = self->fd; } if (self->serverfd != INVALID_SOCKET) { FD_SET(self->serverfd, &fdset); if (self->serverfd > highestfd) highestfd = self->serverfd; } /* Wait for input */ if (timeout >= 0) { ret = select((int)highestfd+1, &fdset, NULL, NULL, &time); } else { ret = select((int)highestfd+1, &fdset, NULL, NULL, NULL); } /* Check if this is a timeout (0) or error (-1) */ if (ret < 1) return ret; if (self->fd != INVALID_SOCKET && FD_ISSET(self->fd, &fdset)) { DEBUG(4, "Data available on client socket\n"); ret = obex_data_indication(self, NULL, 0); } else if (self->serverfd != INVALID_SOCKET && FD_ISSET(self->serverfd, &fdset)) { DEBUG(4, "Data available on server socket\n"); /* Accept : create the connected socket */ ret = obex_transport_accept(self); /* Tell the app to perform the OBEX_Accept() */ if (self->keepserver) obex_deliver_event(self, OBEX_EV_ACCEPTHINT, 0, 0, FALSE); /* Otherwise, just disconnect the server */ if (ret >= 0 && !self->keepserver) obex_transport_disconnect_server(self); } else ret = -1; } return ret; }