Esempio n. 1
0
static void
test_rread (void)
{
    Npfcall *fc, *fc2;
    u8 buf[128];

    memset (buf, 0xf0, sizeof(buf));

    if (!(fc = np_create_rread (sizeof (buf), buf)))
        msg_exit ("out of memory in %s", __FUNCTION__); 
    np_set_rread_count (fc, sizeof (buf));
    fc2 = _rcv_buf (fc, P9_RREAD, __FUNCTION__);

    assert (fc->u.rread.count == fc2->u.rread.count);
    assert (memcmp (fc->u.rread.data, fc2->u.rread.data, fc->u.rread.count) == 0);

    free (fc);
    free (fc2);
}
/* Read from remote client */
static Npfcall* openssl_remote_read(Npfid *afid, u64 offset, u32 count) {
    struct openssl_session_auth_context* ctx;
    int read_length;
    u8* data;
    Npfcall* rc;

    ctx = (struct openssl_session_auth_context*)afid->aux;
    if ( ctx == NULL )
        return np_create_rerror("No session context",EINVAL,1);

    /* We do not support offsets in our protocol */
    if ( offset != 0 )
        return np_create_rerror("No offset supported",EINVAL,1);

    data = malloc(count);
    if ( !data )
        return np_create_rerror("No mem",ENOMEM,1);

    read_from_buffer(&ctx->output_buffer, count, (char*)data, &read_length);

    rc = np_create_rread(read_length, data);
    free(data);
    return rc;
}