Minor std.stdio.File.ByLine rant

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Feb 27 07:04:47 PST 2014


On Thu, Feb 27, 2014 at 07:55:59AM -0500, Steven Schveighoffer wrote:
> On Wed, 26 Feb 2014 18:44:10 -0500, H. S. Teoh
> <hsteoh at quickfur.ath.cx> wrote:
> 
> >First of all, the way ByLine works is kinda tricky, even in the
> >previous releases. The underlying cause is that at least on Posix,
> >the underlying C feof() call doesn't actually tell you whether you're
> >really at EOF until you try to read something from the file
> >descriptor.
> 
> This is not a posix problem, it's a general stream problem.
> 
> A stream is not at EOF until the write end is closed. Until then,
> you cannot know whether it's empty until you read and don't get
> anything back. Even if a primitive existed that allowed you to tell
> whether the write end was closed, you can race this against the
> other process closing it's write end.
> 
> I think the correct solution is to block on the first front call. We
> may be able to do this without storing an additional variable.
[...]

Unfortunately, you can't. Since Phobos can't know whether the file
(which may be a network socket, say) is at EOF without first blocking on
read, it won't be able to return the correct value from .empty, and
according to the range API, it's invalid to access .front unless .empty
returns false. So this solution doesn't work. :-(


T

-- 
All men are mortal. Socrates is mortal. Therefore all men are Socrates.


More information about the Digitalmars-d mailing list