Logo Search packages:      
Sourcecode: obexd version File versions  Download package

gboolean gw_obex_xfer_write ( GwObexXfer xfer,
const char *  buf,
gint  buf_size,
gint *  bytes_written,
gint *  error 
)

Supply more data to a transfer

Parameters:
xfer Pointer returned by gw_obex_put_async or gw_obex_get_async
buf Buffer containing the data
buf_size Size of the buffer
bytes_written Return value for the number of bytes that were written
error Place to store error code on failure (NULL if not interested)
Returns:
TRUE on success, FALSE on failure

Definition at line 209 of file obex-xfer.c.

References GW_OBEX_ERROR_INVALID_PARAMS.

                                                        {
    GwObex *ctx = xfer->ctx;
    gboolean ret = TRUE;
    gint free_space;

    debug("gw_obex_xfer_write(buf_size=%d): entered\n", buf_size);

    if (!ctx) {
        if (err)
            *err = GW_OBEX_ERROR_INVALID_PARAMS;
      return FALSE;
    }

    GW_OBEX_LOCK(ctx);

    if (ctx->obex_op != OBEX_CMD_PUT) {
        ret = FALSE;
        if (err)
            *err = GW_OBEX_ERROR_INVALID_PARAMS;
        goto out;
    }

    if (gw_obex_set_error(ctx)) {
        gw_obex_get_error(ctx, err);
        ret = FALSE;
        goto out;
    }

    free_space = xfer->buf_size - (xfer->data_start + xfer->data_length);

    *bytes_written = buf_size > free_space ? free_space : buf_size;

    memcpy(&xfer->buf[xfer->data_start + xfer->data_length], buf, *bytes_written);

    xfer->data_length += *bytes_written;
    free_space -= *bytes_written;

    if (xfer->object) {
        if (OBEX_Request(ctx->handle, xfer->object) < 0) {
            debug("OBEX_Request() failed\n");
            xfer->data_length -= *bytes_written;
            ret = FALSE;
            goto out;
        }

        xfer->object = NULL;

        /* Recalculate free space */
        free_space = xfer->buf_size - (xfer->data_start + xfer->data_length);
    }

    if (xfer->data_length >= ctx->tx_max || !free_space) {
        guint old_length = xfer->data_length;

        debug("OBEX_ResumeRequest at %s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
        OBEX_ResumeRequest(ctx->handle);

        if (!xfer->block)
            goto out;

        /* Call OBEX_HandleInput if the xfer is blocking and no data could be sent */
        while (old_length == xfer->data_length) {
            if (gw_obex_set_error(ctx)) {
                gw_obex_get_error(ctx, err);
                ret = FALSE;
                goto out;
            }

            if (!handle_input(ctx, err)) {
                ret = FALSE;
                goto out;
            }
        }
    }

out:
    if (xfer->cb && xfer->do_cb && xfer->idle_source == NULL) {
        xfer->idle_source = g_idle_source_new();
        g_source_set_callback(xfer->idle_source, (GSourceFunc)gw_obex_put_idle, xfer, NULL);
        (void) g_source_attach(xfer->idle_source, ctx->main_ctx);
        g_source_unref(xfer->idle_source);
    }

    GW_OBEX_UNLOCK(ctx);
    if (ret)
        debug("gw_obex_xfer_write(): returning, %d bytes written\n", *bytes_written);
    else
        debug("gw_obex_xfer_write(): returning, failed (%d)\n", err ? *err : 0);
    return ret;
}


Generated by  Doxygen 1.6.0   Back to index