how does aio_write() work

Discussion in 'C Programming' started by nass, Feb 15, 2007.

  1. nass

    nass Guest

    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?
     
    nass, Feb 15, 2007
    #1
    1. Advertising

  2. nass

    Chris Dollin Guest

    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.
     
    Chris Dollin, Feb 15, 2007
    #2
    1. Advertising

  3. 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
     
    Kenny McCormack, Feb 15, 2007
    #3
  4. "nass" <> wrote in message
    news:...
    > 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
     
    Stephen Sprunk, Feb 17, 2007
    #4
  5. nass

    santosh Guest

    Stephen Sprunk wrote:
    > "nass" <> wrote in message
    > news:...
    > > 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
     
    santosh, Feb 17, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TB
    Replies:
    2
    Views:
    3,789
  2. Alek Nazarian
    Replies:
    7
    Views:
    3,280
    Alek Nazarian
    Oct 22, 2003
  3. Nick L
    Replies:
    10
    Views:
    619
    Jerry Coffin
    Aug 31, 2004
  4. Vineet Jain
    Replies:
    9
    Views:
    469
    Fredrik Lundh
    Apr 16, 2004
  5. nass
    Replies:
    2
    Views:
    343
    Larry Smith
    Feb 15, 2007
Loading...

Share This Page