This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch/RFC] Fix libstdc++/9533


Nathan Myers wrote:

On Thu, Mar 13, 2003 at 01:54:48PM +0100, Paolo Carlini wrote:


the below fixes the problem by implementing a non-trivial showmanyc(),
as discussed thoroughly on the list during the last weeks.

In particular, I would appreciate by reassured that the new
__basic_file<>::showmanyc_helper deals correctly with the various
possibilities.


This patch needs some cleanup.  I apologize for the delay in replying;
I was sick as a dog all of last week.

Too bad. Anyway, thanks for your comments: I will try to prepare an updated version during
this week (while Benjamin is working on the 27_io testsuite).


First, the above code can only reveal information about sockets, and not, unfortunately, pipes. (On a pipe it reports failure.) So, the comment is not right. Still, sockets are important enough to merit the special treatment.

Ok.

Second, passing zeroes to the recv() arguments isn't portable. I find
that, on Linux, (1) we must actually provide a buffer for it to copy the characters into, and (2) it won't return a value larger than the indicated buffer size (even with MSG_TRUNC). This means you can't avoid having it copy the characters. (Drat.) The buffer used might as well be the actual stream buffer. This is still less expensive than an actual underflow, potentially, because we don't have to run the codecvt operation afterward. Further, we haven't actually messed with the socket state.


I see. This is really unfortunate, that we have to actually read the data :(
How much data we must be prepared to? Even gigabytes, I'm afraid! Just to know with MSG_PEEK
how much data we'll actually extract later on (maybe, only maybe!).
Where do you suggest we store such data?


I would prefer to express the above as


+#ifdef _GLIBCPP_S_ISREG_OR_S_IFREG
+ // Regular files.
+ struct stat __buffer;
+ int __ret = fstat(this->fd(), &__buffer);
+ if (!__ret && _GLIBCPP_S_ISREG_OR_S_IFREG(__buffer.st_mode))
+ if (__stdio)
+ return __buffer.st_size - ftell(_M_cfile);
+ else
+ return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
+#endif



with a corresponding definition for _GLIBCPP_S_ISREG_OR_S_IFREG constructed in configure.


Yes, this is much more clean. I have to learn a bit more about the configury machinery in order to
do that, but I will try...


+
+ streamsize
+ showmanyc_helper(bool __stdio);


As in several other patches that have come through, I believe this member name must be uglified. I don't mind if they're all fixed up
in a separate patch.


Ok. To be honest, I didn't follow your exchanges with Gaby about this and the conclusions you
arrived to. We'll deal with the issue in separate patch, as you say.


Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]