tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: Comet API and InputStream.available()
Date Wed, 24 Jan 2007 19:08:17 GMT
In most cases, almost all cases there will be data to be read when a 
READ event occurs.
An example where there is none, is when we recieve a request, and there 
is no data in the body yet.
as we parse the GET request, we invoke READ so that you can read any 
client data, if any.
And that is the case when it returns 0, a fully valid use case.

Filip

Christophe Pierret wrote:
> OK, I understand your rationale.
> It is a tough job to retrofit asynchronous IOs in a synchronous framework like the "servlet
specification" and you did great given the constraints !
> Continue the good job...
>   Christophe
>
>
> -----Message d'origine-----
> De : Remy Maucherat [mailto:remm@apache.org] 
> Envoyé : mercredi 24 janvier 2007 14:48
> À : Tomcat Developers List
> Objet : Re: Comet API and InputStream.available()
>
> Christophe Pierret wrote:
>   
>> Here is what I understood:
>>
>> Assumption #1: ================ When you receive a 
>> CometEvent.EventType.READ event, you can always read() at least one 
>> byte from the request's InputStream without blocking.
>>
>> Is this correct ? If not correct, then this mail goes directly to 
>> trash (and sorry for the inconvenience...)
>>     
>
> It's not 100% correct: you may do one blocking read without waiting for client input
(as the poller signaled data was available). However, the InputStream that is given to you
in the Servlet is a buffered stream that has no relation with the socket. I don't like the
idea of returning "1", which is a hack. The only non hack way of doing it is to do the read
somewhere (in CometAdapter.event) to fill the buffer of the input stream before calling the
Servlet.
>
> At the moment, I use this read method (which is compatible with both behaviors of available())
in the chat servlet from the examples:
>          do {
>              int n = is.read(buf);
>              if (n > 0) {
>                  log("Read " + n + " bytes: " + new String(buf, 0, n)
>                          + " for session: " + request.getSession(true).getId());
>              } else if (n < 0) {
>                  // Error: do cleanup
>                  event.close();
>                  return;
>              }
>          } while (is.available() > 0);
>
> Rémy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail:
dev-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message