[Coldstuff] networking problem in parse()

Gau of the Veldt coldstuff@cold.org
Fri, 22 Feb 2002 15:04:53 -0700


I've been having trouble with network stream reading via the parse() method.

I'm trying to build a webserver that can handle forms (particularly
multipart/form-data since it can be used as a web interface to uploading
character images, etc).  I can transfer a normal page fine but end up with
an interesting problem when the operation is a post and expects a specific
number of bytes to occur after the client transmits the header (specified by
the content length header).

The problem appears as the web browser and the connection object stalling
when the parse_line state is waiting for parse to send it a fixed-length
buffer.  My implementation of parse() checks a getraw() function implemented
on the interface object for being >0 (>0 means parse_line wants that many
unterminated bytes on the next call [passed as a buffer]).  When enough
bytes pass through (buffer.length() >= interface.getraw()) a subbuffer is
generated with the requested bytes, lopped off the main buffer and passed to
parse_line (as a buffer rather than a string).

The problem appears as a stall on the web browser side.  In the code the
problem is a stall after parse_line on the interface obtains the headers
from the client and just completed setting rawflag so parse() will know the
number of expected form bytes on the next pass.  The next pass (another call
to parse()) doesn't happen.  As such the two sides end up helplessly
stalled.

Here's the real gotcha!  If I hit [STOP] in the browser the parse() function
immediately comes to life and the code executes and sends the required bytes
back to parse_line and I have the required data and am able to generate the
result page (only the browser is by now disconnected).  The killer thing is
that the data is THERE but I can't get parse() to see it without the other
side cutting the cord.

Is there some way I can make this work as I am expecting?  If anyone wants
to analyze the textdump I'd be happy to make it available by arrangement.  I
suspect (and, by netiquette, rightly so) that posting the textdump as an
attachment to the entire list is a real Bad Idea (TM.).

My email address is gau_veldt[4T]hotmail[D0T]com (substitue as necessary @
for [4T] and . for [D0T] - hopefully spambots aren't smart enough yet to
figure this trick out).