how does aio_write() work
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > how does aio_write() work




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    how does aio_write() work  
nass


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-07 06:19 PM

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?






[ Post a follow-up to this message ]



    Re: how does aio_write() work  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-07 06: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





[ Post a follow-up to this message ]



    Re: how does aio_write() work  
nass


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-07 06:19 PM

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 ?






[ Post a follow-up to this message ]



    Re: how does aio_write() work  
Spoon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-07 06:19 PM

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





[ Post a follow-up to this message ]



    Re: how does aio_write() work  
nass


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-07 06:19 PM

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






[ Post a follow-up to this message ]



    Re: how does aio_write() work  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-16-07 06: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
bUPBg2kMFb
Ue1u3hU8qYXb1xDfv!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 ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:07 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register