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

gboolean gw_obex_xfer_read ( GwObexXfer xfer,
char *  buf,
gint  buf_size,
gint *  bytes_read,
gint *  error 
)

Read data from a transfer

The function will report EOF by returning success with zero bytes read.

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

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

References GW_OBEX_ERROR_INVALID_PARAMS, and GW_OBEX_ERROR_NO_DATA.

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

    debug("gw_obex_xfer_read(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_GET) {
        ret = FALSE;
        if (err)
            *err = GW_OBEX_ERROR_INVALID_PARAMS;
        goto out;
    }

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

        if (xfer->data_length)
            break;

        if (ctx->done) {
            *bytes_read = 0;
            goto out;
        }

        if (xfer->block) {
            if (!handle_input(ctx, err)) {
                ret = FALSE;
                goto out;
            }
        }
        else {
            ret = FALSE;
            if (err)
                *err = GW_OBEX_ERROR_NO_DATA;
            goto out;
        }
    }

    data_length = xfer->data_length;
    *bytes_read = buf_size < data_length ? buf_size : data_length;

    memcpy(buf, &xfer->buf[xfer->data_start], *bytes_read);

    xfer->data_length -= *bytes_read;

    if (xfer->data_length)
        xfer->data_start += *bytes_read;
    else {
        xfer->data_start = 0;
        debug("OBEX_ResumeRequest at %s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
        OBEX_ResumeRequest(ctx->handle);
    }

out:
    GW_OBEX_UNLOCK(ctx);
    if (ret)
        debug("gw_obex_xfer_read(): returning, %d bytes read\n", *bytes_read);
    else
        debug("gw_obex_xfer_read(): returning, failed (%d)\n", err ? *err : 0);
    return ret;
}


Generated by  Doxygen 1.6.0   Back to index