* Problem with scatter/gather IO
@ 2011-07-13 11:54 Randi Botse
2011-07-13 12:16 ` Leon Romanovsky
0 siblings, 1 reply; 3+ messages in thread
From: Randi Botse @ 2011-07-13 11:54 UTC (permalink / raw)
To: linux-c-programming; +Cc: night decoder
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,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with scatter/gather IO
2011-07-13 11:54 Problem with scatter/gather IO Randi Botse
@ 2011-07-13 12:16 ` Leon Romanovsky
[not found] ` <CAA6iF_6CUa6ECMvnh9YehmxWYJzj23FEHZ4RJ5PtP-WdrrTr_A@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2011-07-13 12:16 UTC (permalink / raw)
To: Randi Botse; +Cc: linux-c-programming
On Wed, Jul 13, 2011 at 14:54, Randi Botse <nightdecoder@gmail.com> 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 | leon@leon.nu
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Fwd: Problem with scatter/gather IO
[not found] ` <CAA6iF_6CUa6ECMvnh9YehmxWYJzj23FEHZ4RJ5PtP-WdrrTr_A@mail.gmail.com>
@ 2011-07-14 6:33 ` Randi Botse
0 siblings, 0 replies; 3+ messages in thread
From: Randi Botse @ 2011-07-14 6:33 UTC (permalink / raw)
To: linux-c-programming
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 <leon@leon.nu> wrote:
> On Wed, Jul 13, 2011 at 14:54, Randi Botse <nightdecoder@gmail.com> 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 | leon@leon.nu
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-14 6:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-13 11:54 Problem with scatter/gather IO Randi Botse
2011-07-13 12:16 ` Leon Romanovsky
[not found] ` <CAA6iF_6CUa6ECMvnh9YehmxWYJzj23FEHZ4RJ5PtP-WdrrTr_A@mail.gmail.com>
2011-07-14 6:33 ` Fwd: " Randi Botse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).