[xSocket-develop] Processing large data blocks: comment and question.
Status: Inactive
Brought to you by:
grro
|
From: Simon W. <si...@tr...> - 2008-01-10 12:06:21
|
Hi,
I have just started experimenting with xSocket and I have managed to
create a rudimentary pub/sub system in two days so it is looking good so
far. However, I did have one comment and one question.
Firstly, I worked out how to handle the case where a large data block
has not arrived yet. I think this could be a bit clearer in the
documentation though because initially I though that I should make the
IDataHandler onData method wait and loop until more data was in the
buffer if I got a buffer underflow. However, I found that the buffer
never got any more data presumably due to your internal locking. I did
eventually work out that the StreamUtils.validate... method actually
works by throwing the BufferUnderflowException that causes that call to
onData to abort; then onData is called again when more data arrives, and
this repeats until the whole block of data has arrived and it can be
processed normally.
My question is: what happens if a large data block is followed by a
small data block? I presume that the sender will buffer the data so
that the small data block arrives immediately after the large data
block, so the two blocks arrive as a continuous stream. My handler will
keep attempting to read the large data block until it has arrive.
However, in the last call to onData, which can finally real the large
data block, the buffer may also contain the entire small data block
too? I assume that onData will only be called when more data arrives at
the socket. Therefore, if the small data block has already arrived,
onData will not be called again? Do I need to check for more data in
the buffer with getNumberOfAvailableBytes() and then have onData
recursively call itself, or will your framework automatically call
onData again if my handler returns with unread data in the buffer?
Regards,
Simon.
|