Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how does aio_write() work

Reply
Thread Tools

how does aio_write() work

 
 
nass
Guest
Posts: n/a
 
      02-15-2007
hello everyone i am looking into asynchronous file writing
(appending).
what the program is doing:
i am running a loop and when the condition is met (basically a timer)
a buffer gets appended to a file. every so often (another timer) the
filename is changed so the next write must create a new file and start
appending into that. it is really a timed Binary log.

i have managed to do that 'saving' with stream to file operations
(where file
is of type fstream), and i have also managed to do it with fopen().
but it is a requirement that the execution is not halted so i looked
into threads... and then i came across asynchronous write.

now looking into aio_write and the struct aiocb that it takes as input
argument, i see that i must provide a file descriptor instead of ther
usual FILE *, that fopen returns.

and i am wondering if i should be opening the file prior to
aio_write(), or just opening the file once for evey new filename (*ie
when the file doesnt exist), getting the file descriptor, and closing
the file, so that when the time for aio_write() comes , aio_write()
will open, write and close the file on its own.

any ideas?

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      02-15-2007
nass wrote:

(with subject: how does aio_write() work)

> hello everyone i am looking into asynchronous file writing
> (appending).


aio_write isn't a standard C function at all (fx:man) -- it
seems to be POSIX, so you should get informed & topical answers
in comp.unix.programmer.

--
Chris "electric hedgehog" Dollin
A rock is not a fact. A rock is a rock.

 
Reply With Quote
 
 
 
 
Kenny McCormack
Guest
Posts: n/a
 
      02-15-2007
In article <er1ne0$i5b$>,
Chris Dollin <> wrote:
>nass wrote:
>
>(with subject: how does aio_write() work)
>
>> hello everyone i am looking into asynchronous file writing
>> (appending).

>
>aio_write isn't a standard C function at all (fx:man) -- it
>seems to be POSIX, so you should get informed & topical answers
>in comp.unix.programmer.


IOW:

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      02-17-2007
"nass" <> wrote in message
news: ups.com...
> hello everyone i am looking into asynchronous file writing
> (appending).


All OT for clc. Try comp.unix.programmer.

> what the program is doing:
> i am running a loop and when the condition is met (basically a timer)
> a buffer gets appended to a file. every so often (another timer) the
> filename is changed so the next write must create a new file and start
> appending into that. it is really a timed Binary log.
>
> i have managed to do that 'saving' with stream to file operations
> (where file is of type fstream), and i have also managed to do it with
> fopen(). but it is a requirement that the execution is not halted so i
> looked into threads... and then i came across asynchronous write.
>
> now looking into aio_write and the struct aiocb that it takes as input
> argument, i see that i must provide a file descriptor instead of ther
> usual FILE *, that fopen returns.


Once you start playing in the POSIX world, it's best to stay there. i.e.
use open() instead of fopen(). Of course, that puts you completely
off-topic for here.

> and i am wondering if i should be opening the file prior to
> aio_write(), or just opening the file once for evey new filename (*ie
> when the file doesnt exist), getting the file descriptor, and closing
> the file, so that when the time for aio_write() comes , aio_write()
> will open, write and close the file on its own.


No, it won't. aio_write() works just like write(), except it may be
asynchronous. Once you close a fd, it becomes invalid; you can't just keep
writing to it.

I don't think you want AIO here at all. Just create a standard FILE*, stuff
it in a global variable, and fwrite() to it from the first timer's function.
The second timer's function would fopen() the next file, change the global
to the new file, and fclose() the old file. There's probably a race
condition or reentrancy issue in there somewhere, though, which is why you
need to talk to folks who work with threads on a regular basis (i.e. not on
clc).

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      02-17-2007
Stephen Sprunk wrote:
> "nass" <> wrote in message
> news: ups.com...
> > hello everyone i am looking into asynchronous file writing
> > (appending).

>
> All OT for clc. Try comp.unix.programmer.


<snip>

> I don't think you want AIO here at all. Just create a standard FILE*, stuff
> it in a global variable, and fwrite() to it from the first timer's function.
> The second timer's function would fopen() the next file, change the global
> to the new file, and fclose() the old file. There's probably a race
> condition or reentrancy issue in there somewhere, though, which is why you
> need to talk to folks who work with threads on a regular basis (i.e. not on
> clc).


One possibility is comp.programming.threads

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
MS work around on text wrapping in a datagrid does not work TB ASP .Net 2 02-22-2006 10:34 PM
Loop Does'nt Work, Hard code does Nick L C++ 10 08-31-2004 08:49 PM
int('2.1') does not work while int(float('2.1')) does Vineet Jain Python 9 04-16-2004 10:12 AM
what does the native keyword do actually ? and how does it work ?when we can use it ? Alek Nazarian Java 7 10-22-2003 04:33 PM



Advertisments