www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - wierd behavior with din.readLine()

reply Justin Greenwood <jgreenwood37 insightbb.com> writes:
Hi,
I've been working on a CGI web framework and ran into some unexpected 
behavior from din.readLine when looping through a data stream coming in 
from a multipart form web request. It seems that it is adding an extra 
blank line after each expected line. This could be due to bad code 
splitting the line at the CR and then again at the LF instead of seeing 
that as one EOL sequence. According to the docs, this doesn't seem like 
the correct behavior. when I output the data reading in character by 
character, everything looks correct. Here is the code:

while (!din.eof)
{
     line = din.readLine();
     ...
}

I am running the DMD compiler on fedora core linux using Phobos. Any 
ideas? Is this how it's supposed to work or is there something I'm doing 
wrong?

Thanks much for any help,
-Justin
Nov 23 2007
parent CyaNox <mark cyanox.nl> writes:
Justin Greenwood wrote:
 Hi,
 I've been working on a CGI web framework and ran into some unexpected 
 behavior from din.readLine when looping through a data stream coming in 
 from a multipart form web request. It seems that it is adding an extra 
 blank line after each expected line. This could be due to bad code 
 splitting the line at the CR and then again at the LF instead of seeing 
 that as one EOL sequence. According to the docs, this doesn't seem like 
 the correct behavior. when I output the data reading in character by 
 character, everything looks correct. Here is the code:
 
 while (!din.eof)
 {
     line = din.readLine();
     ...
 }
 
 I am running the DMD compiler on fedora core linux using Phobos. Any 
 ideas? Is this how it's supposed to work or is there something I'm doing 
 wrong?
 
 Thanks much for any help,
 -Justin
I'm not sure about your specific problem but I do know that when you read stdin in CGI you should never rely on the EOF marker. Instead use the specified environment variable CONTENT_LENGTH and read nothing more or less from stdin. Greetings, Mark Sanders.
Dec 05 2007