473,776 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when a c++ output stream operation fails

I'm running an application on an embedded device running Linux (2.6.21
kernel) . I've found that when the CPU load gets really high on the
device, output to a file stream sometimes fails.

When I turn on exceptions, the what() method from the exception that
gets thrown just tells me that there's a basic_ios::clea r error, and
I've verified that errno is 0.

Does anyone have any suggestions about what I can do?

I thought about retrying, since subsequent writes to that stream
apparently work. However, my concern is that I don't know the nature
of the failure. Say I attempted to do a write of 10 bytes from a
character buffer. Is there any way to tell if it failed and none of
the bytes got written out, 2 of the bytes, or 9?

The file system that my ofstream is writing out to is actually a
ramdisk partition (tmpfs file system).

I don't mind retrying, if necessary, but I need the output of the
stream to be correct, which means I need to know from where I should
be retrying.

Any ideas?
Jul 2 '08 #1
3 2382
"dont_spam_ me" <jo********@gma il.comwrite:
>
I'm running an application on an embedded device running Linux (2.6.21
kernel) . I've found that when the CPU load gets really high on the
device, output to a file stream sometimes fails.

When I turn on exceptions, the what() method from the exception that
gets thrown just tells me that there's a basic_ios::clea r error, and
I've verified that errno is 0.

Does anyone have any suggestions about what I can do?

I thought about retrying, since subsequent writes to that stream
apparently work. However, my concern is that I don't know the nature
of the failure. Say I attempted to do a write of 10 bytes from a
character buffer. Is there any way to tell if it failed and none of
the bytes got written out, 2 of the bytes, or 9?

The file system that my ofstream is writing out to is actually a
ramdisk partition (tmpfs file system).

I don't mind retrying, if necessary, but I need the output of the
stream to be correct, which means I need to know from where I should
be retrying.

Any ideas?
It seems to be either a memory low issue or a timeout issue.
As next I would try it with FILE*
and add a fflush(fp) immediately after the writing.
If the error still happens then even go one
level deeper and try it with _write(fd) ...
Then you can decide better...
BTW, don't forget to close the file first before trying the above things...

Jul 2 '08 #2
On Jul 1, 6:13*pm, "Adem24" <ade...@adem24a dem24.org.inval idwrote:
"dont_spam_ me" <joe.ano...@gma il.comwrite:


I'm running an application on an embedded device running Linux (2.6.21
kernel) . *I've found that when the CPU load gets really high on the
device, output to a file stream sometimes fails.
When I turn on exceptions, the what() method from the exception that
gets thrown just tells me that there's a basic_ios::clea r error, and
I've verified that errno is 0.
Does anyone have any suggestions about what I can do?
I thought about retrying, since subsequent writes to that stream
apparently work. *However, my concern is that I don't know the nature
of the failure. *Say I attempted to do a write of 10 bytes from a
character buffer. *Is there any way to tell if it failed and none of
the bytes got written out, 2 of the bytes, or 9?
The file system that my ofstream is writing out to is actually a
ramdisk partition (tmpfs file system).
I don't mind retrying, if necessary, but I need the output of the
stream to be correct, which means I need to know from where I should
be retrying.
Any ideas?

It seems to be either a memory low issue or a timeout issue.
As next I would try it with FILE*
and add a fflush(fp) immediately after the writing.
If the error still happens then even go one
level deeper and try it with _write(fd) ...
Then you can decide better...
BTW, don't forget to close the file first before trying the above things....- Hide quoted text -

- Show quoted text -
The problem though is that I'm not sure if any of the bytes from my
original ostream write actually wrote out. I can retry using any
call, but I need to know what to write out.

Is there a way to find this out? Or is it all or nothing? Unlike the
write() c function, which returns the number of bytes written, the
return value for ostream::write( ) is the this pointer.

Does this mean I simply can't use c++ streams for file output unless I
do it byte by byte?

Jul 2 '08 #3
On Jul 2, 2:18 am, dont_spam_me <joe.ano...@gma il.comwrote:
I'm running an application on an embedded device running Linux
(2.6.21 kernel) . I've found that when the CPU load gets
really high on the device, output to a file stream sometimes
fails.
When I turn on exceptions, the what() method from the
exception that gets thrown just tells me that there's a
basic_ios::clea r error, and I've verified that errno is 0.
Does anyone have any suggestions about what I can do?
Not many. This sounds very dependent on the implementation you
are using.
I thought about retrying, since subsequent writes to that stream
apparently work. However, my concern is that I don't know the nature
of the failure. Say I attempted to do a write of 10 bytes from a
character buffer. Is there any way to tell if it failed and none of
the bytes got written out, 2 of the bytes, or 9?
No. At the IO stream level, failure is generally considered
fatal; the philosophy is that the stream you were writing is no
longer usable.
The file system that my ofstream is writing out to is actually
a ramdisk partition (tmpfs file system).
I don't mind retrying, if necessary, but I need the output of
the stream to be correct, which means I need to know from
where I should be retrying.
Any ideas?
Only that you'll probably have to access some lower levels (e.g.
by writing your own streambuf). Supposing they support what you
want. (The Posix write function returns the number of bytes
actually written, which is what you seem to need. Most filebuf
will interpret any value other than the number they requested to
write as an error, but you could write something similar which
didn't.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6800
by: adolf garlic | last post by:
Im trying to return xml from sql. The xml is made up of different fragments, some using FOR XML ... syntax. The result is a valid xml doc. There is a working stored proc that returns the xml In .net i'm having problems loading this up. I've now tried installing sqlxml managed classes and the following appears to work when stepping through, but the result just disappears.
3
5075
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb). I changed the data type for the structure that contains the XML data from the default "String" to "xml.xmldocument" to enable easy filling of the data. my client code creates an XML document class, fills the data using standard xml dom...
5
5402
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in separate files for ease of maintainability. These schemas are all part of the same namespace. When defining a web service that access more than one of these entities, the wsdl file generated by BEA contains multiple schema elements with the same...
2
6322
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
4
2035
by: Helge Jensen | last post by:
In C# 2.0 System.IO.Stream is declared as: public class Stream: ..., IDisposable { ... public void Dispose(); public void Dispose(bool); IDisposable.Dispose(); } Which must be a design-blunder, if not a 100-year sleep. It prevents
12
7916
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug it, it works every time! I even set it to True, but did a .Flush just before the error, and the error won't happen. It only happens when response.buffer is True and no .response.flush is issued. The error is a string variable turns-up empty...
173
8186
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc. OTOH, if you're allocating a gigabyte for a large array, this might fail, so you should definitely check for a NULL return.
14
12831
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in case it's a question, i want to popup a messageBox or something, and bring back to the batch file the result (Yes\No question). I know how to excute the batch file and get all the Standard output at the end, but i don't know who can i read it line by...
24
6020
by: kindrain | last post by:
the code checks whether a.txt has exact the same lines, then write different lines into b.txt Here it is: (before that ,you should creat a.txt) ---------------------- #include<stdio.h> #include<string.h> void main(){ FILE *fp,*ftemp;
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8952
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.