Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] WebSocket + Async Read/Write

Hi Hiram !

On Mon, Feb 13, 2012 at 22:44, Hiram Chirino <hiram@xxxxxxxxxxxxxxxx> wrote:
>
> Hi Jesse,
>
> I don't see in that example where either socket reading is suspended or socket writing is non-blocking.  How about this question, which apis should I use to:
>
> * suspend socket reads
> * resume read
> * do a non-blocking write and how do I know when the write completes (so I can resume doing more writes).

The current API for WebSocket offers blocking writes only. While under
the covers Jetty will do non-blocking writes, the application thread
will be blocked until the application data is fully written.
We may consider a non-blocking API for applications though (of course
a blocking API is way simpler for web applications, but *your* kind of
application is not common, I guess ;).

As for suspend/resume reads I am not sure what you mean. Can you
sketch what you would like to do ?

The 2 most used interfaces for reading are WebSocket.OnTextMessage and
WebSocket.OnBinaryMessage. Both will coalesce websocket frames until a
final frame is received, then invoke the application.
In order to avoid infinite data, the max text/binary message size can
be configured.

If you want to go deeper, you can implement WebSocket.OnFrame.

TCP backpressure can be done only via slow readers (implementations of
the interfaces above): we do not offer an API to disable reads. The
parser will aggressively try to read as much as it can and notify the
application, so if the application does nothing the parser will read
more (no way to tell the parser to not read from the socket).

As I said, the API was designed for simple usage, targeted to servlet
developers that want to dive into WebSocket.

If you have a different use case (which I can imagine - but better if
you explain it rather than me guessing), we'd love to hear.

Cheers,

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz


Back to the top