Fwd: Problem with scatter/gather IO

Randi Botse <[email protected]> Thu, 14 Jul 2011 13:33:40 +0700
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <CAA6iF_6Uamo_qFD=X3H1urO+1J3hM2A5Kri5o8652=Znq2Y6Ew@mail.gmail.com>
Ahh,, you are right Leon, each iov member need to be initialized
first, my bad. Everything is OK now. I also use sysconf(_SC_IOV_MAX)
to determine maximum iovs count.

Thanks,


On Wed, Jul 13, 2011 at 7:16 PM, Leon Romanovsky <[email protected]> wrote:
> On Wed, Jul 13, 2011 at 14:54, Randi Botse <[email protected]> wrote:
>>
>> Hi,
>>
>> I will read/write file with readv() and writev(), I have problem to
>> use that since the struct iovec will be a variable-length array, if i
>> have code.
>>
>> struct foo {
>>    unsigned char data[100];
>>    unsigned char another_data[28];
>> };
>> unsigned len;
>> ....
>>
>> /* calculate len */
>> /* use len as array's member size */
>> struct iovec iov[len];
>> printf("len is: %i\n", len);
>> readv(fd, iov, len);
>>
>> I got: BAD ADDRESS, and if I remove the printf() then I will get
>> INVALID ARGUMENT. What the possible problem with that?
>>
>> Thanks,
>> --
>
> Did you try "man readv" ?
> You didn't initialized iovec struct.
> http://pubs.opengroup.org/onlinepubs/009695399/functions/readv.html
>
> --
> Leon Romanovsky | Independent Linux Consultant
>         www.leon.nu | [email protected]
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html