Trustin Lee <[EMAIL PROTECTED]> writes:

> Could you let me know where did you find such a problem so I can fix
> it?

I think it was the httpserver example, in the HttpRequestDecoder.¹ The
code doesn't look exactly as I remember it, but note the
messageComplete() method, called by decodable(). It does a lot of
parsing to make sure that the entire POST entity has been
received. It's not necessary for the whole message to have been
received for decodable() to arrive at its answer, the answer to the
question, "Can you handle this kind of message?" Also, all this
parsing will be repeated on each subsequent call to decodable(), as no
state is maintained to keep track of what was already parsed
successfully.

The decode() function can also do incremental consumption, returning
NEED_DATA when not enough data is present to finish its job. It looks
like decodable()/messsageComplete() was written at one time, and
decode()/decodeBody() at some other time, maybe by someone else, in
that they don't wind up sharing much between them.

I'm being picky because I've been writing my own HTTP client, and was
initially confused by the decodable()/decode() split, until I realized
that that was specific to /Messages/ rather than the more general
Protocol codec interfaces.


Footnotes: 
¹ 
http://svn.apache.org/viewvc/mina/trunk/example/src/main/java/org/apache/mina/example/httpserver/codec/HttpRequestDecoder.java?view=markup

-- 
Steven E. Harris

Reply via email to