* Forcing fsync() using an ouput stream in C++
@ 2005-03-03 6:38 Hareesh Nagarajan
2005-03-03 8:15 ` Steve Graegert
0 siblings, 1 reply; 2+ messages in thread
From: Hareesh Nagarajan @ 2005-03-03 6:38 UTC (permalink / raw)
To: linux-c-programming
Hi,
I am aware this is a C-programming mailing list. I just thought I
might get some useful inputs from this ML.
My problem is that I haven't figured out how I must fsync an output
stream (in C++) even after reading the contents of this link:
http://gcc.gnu.org/ml/gcc-help/2004-02/msg00285.html
How must I modify this method (this method doesn't work; it prints the
error message and exits!) ?
void logRecovery::syncToDisk(fstream& f)
{
unix_filebuf_t* buf;
buf = dynamic_cast<unix_filebuf_t*>(f.rdbuf());
if (buf == NULL) {
cerr << "Fatal: Don't know fd of stream" << endl;
exit(-1);
}
fsync(buf->fd());
}
I am using GCC 3.3.4.
Thanks,
Hareesh
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Forcing fsync() using an ouput stream in C++
2005-03-03 6:38 Forcing fsync() using an ouput stream in C++ Hareesh Nagarajan
@ 2005-03-03 8:15 ` Steve Graegert
0 siblings, 0 replies; 2+ messages in thread
From: Steve Graegert @ 2005-03-03 8:15 UTC (permalink / raw)
To: linux-c-programming; +Cc: Hareesh Nagarajan
On Thu, 3 Mar 2005 00:38:10 -0600, Hareesh Nagarajan
<hareesh.nagarajan@gmail.com> wrote:
> Hi,
>
> I am aware this is a C-programming mailing list. I just thought I
> might get some useful inputs from this ML.
>
> My problem is that I haven't figured out how I must fsync an output
> stream (in C++) even after reading the contents of this link:
> http://gcc.gnu.org/ml/gcc-help/2004-02/msg00285.html
>
> How must I modify this method (this method doesn't work; it prints the
> error message and exits!) ?
>
> void logRecovery::syncToDisk(fstream& f)
> {
> unix_filebuf_t* buf;
> buf = dynamic_cast<unix_filebuf_t*>(f.rdbuf());
> if (buf == NULL) {
> cerr << "Fatal: Don't know fd of stream" << endl;
> exit(-1);
> }
>
> fsync(buf->fd());
> }
>
> I am using GCC 3.3.4.
>
> Thanks,
>
> Hareesh
> -
> 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
>
I have actually now idea why you are using unix_filebuf_t. Why not
simply call f.flush()? If you need to obtain a reference to the
streambuf object associated with a stream you can call f.readbuf() and
then do a sync, like this:
streambuf *buf;
buf = f.readbuf();
buf->sync();
May be I get you wrong, but hope this helps.
--
Kind Regards
\Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-03-03 8:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-03 6:38 Forcing fsync() using an ouput stream in C++ Hareesh Nagarajan
2005-03-03 8:15 ` Steve Graegert
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).