jsr340-experts@servlet-spec.java.net

[jsr340-experts] Re: [servlet-spec users] async IO and flush?

From: Rémy Maucherat <rmaucher_at_redhat.com>
Date: Thu, 23 May 2013 10:56:43 +0200

On 05/23/2013 02:26 AM, Greg Wilkins wrote:
>
> How is flush() meant to work with async IO?
>
>
> Currently I'm still implementing an aggregating buffer with asyncIO,
> so that if you do:
>
> write(one_byte);
>
> it is just copied into the aggregate buffer, no IO is actually done
> and isReady() will return true.
> IO is only actually done when the buffer fills up and only then might
> isReady() return false.
>
> So should flush() block until all content is written? or should it
> also work in async mode so that you can call isReady() after a flush()
> and if isReady returns false then onWritePossible() will be called
> once the flush is complete?
>
> Also when can flush() be called? can it be called if isReady() has
> returned false an OWP has not been called? can it be called before a
> call to isReady()?
>
>
> I think flush() should be treated exactly like a write, because making
> it blocking has all the problems of autoblocking.
>
I think everything looks good in your description.

Yes, there is a still the socket buffer, and internal flushes occur all
the time, so the only option is that the explicit flush is the same. So
flush is like a write and will never block in async mode (the container,
as with a write, should take care of the buffer contents; if everything
cannot be written immediately, the ready flag will change and isReady()
would return false).

Rémy