|
Home > Archive > Unix Programming > February 2007 > how does aio_write() work
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how does aio_write() work
|
|
|
| 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?
| |
| Rainer Temme 2007-02-15, 1:19 pm |
| nass wrote:
> 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.
aio_write() expects the filedescriptor (passed down to it
in the aiocb structure) to be opened. Therefore, you
shouldn't call close() unless you have either cancelled
your requests with aio_cancel(), or you are sure
that your aio_write() has finished (by calling aio_return()).
aio_write() will not open and close itself.
Rainer
| |
|
| On Feb 15, 5:15 pm, Rainer Temme <Rainer.Te...@NoSpam.Siemens.Com>
wrote:
> nass wrote:
>
> aio_write() expects the filedescriptor (passed down to it
> in the aiocb structure) to be opened. Therefore, you
> shouldn't call close() unless you have either cancelled
> your requests with aio_cancel(), or you are sure
> that your aio_write() has finished (by calling aio_return()).
>
> aio_write() will not open and close itself.
>
> Rainer
thank you very much for clarifing that.
may i go ahead and ask why do i get a linker error 'undefined
reference to aio_write'
since i have #include <aio.h> in my class's header file ?
| |
|
| nass wrote:
> may i go ahead and ask why do i get a linker error 'undefined
> reference to aio_write'
> since i have #include <aio.h> in my class's header file ?
#include directives are for the preprocessor and compiler.
You need to tell your linker where to find aio_write.
http://sourceware.org/cgi-bin/cvswe.../?cvsroot=glibc
Add -lrt
| |
|
| On Feb 15, 5:59 pm, Spoon <devn...@localhost.com> wrote:
> nass wrote:
>
> #include directives are for the preprocessor and compiler.
>
> You need to tell your linker where to find aio_write.
>
> http://sourceware.org/cgi-bin/cvswe.../?cvsroot=glibc
>
> Add -lrt
thank you for the pointer.
the thing is i located aio.h under /usr/include and i figured that it
is in the standard path.
could you tell me where this rt library is located? and how can i know
when a header file needs additional flags in its compiler/linker?
thank you once again, the code finally compiles and links! now time to
debug
nass
| |
| Barry Margolin 2007-02-16, 1:19 am |
| User-Agent: MT-NewsWatcher/3.5.2 (PPC Mac OS X)
X-Copies-To: never
Date: Thu, 15 Feb 2007 21:14:14 -0500
Message-ID: <barmar-756DE7.21141415022007@comcast.dca.giganews.com>
Lines: 35
NNTP-Posting-Host: 24.34.108.171
X-Trace: sv3- tQebf5OirsXNau2RcnlWl0PgiK0CFnl2ubLIYTuD
f2MM3e+hdqJTKXuEu7+fc6/tkek0c7zGCYJn5tp!HBVP2Ecg/ cLBx7Gm+hrYdSC162PGpiP2v3rxbun0Nk0ry59Sh
bUPBg2kMFbUe1u3hU8qYXb1xDfv!l/YtgZWDtqIah27lWT5CtDpDBUL2/hPKjw==
X-Complaints-To: abuse@comcast.net
X-DMCA-Complaints-To: dmca@comcast.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: number1.nntp.dca.giganews.com comp.unix.programmer:175518
In article <1171558676.030654.185810@h3g2000cwc.googlegroups.com>,
"nass" <athanasios.silis@gmail.com> wrote:
> On Feb 15, 5:59 pm, Spoon <devn...@localhost.com> wrote:
>
> thank you for the pointer.
> the thing is i located aio.h under /usr/include and i figured that it
> is in the standard path.
> could you tell me where this rt library is located?
It should be in /usr/lib, like all the other system libraries.
> and how can i know
> when a header file needs additional flags in its compiler/linker?
The man page tells you what header files to include and what linker
flags to use.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|