Re: [xSocket-develop] onData ?
Status: Inactive
Brought to you by:
grro
|
From: Rod M. <rod...@gm...> - 2008-05-07 14:33:48
|
That makes sense and is how I understood it; I had reread the tutorial and
wanted to make certain nothing ad changed. Thanks.
Rod
On Wed, May 7, 2008 at 12:49 AM, Gregor Roth <gre...@go...>
wrote:
> Hi Rod,
>
> read mark is not necessary if you perform only a single read operation
> within your onData method.
>
> Each read operation on a non blocking connection can cause a
> BufferUnderflowException. If you perform more than one read operation within
> your handling code it is not predicable, if a BufferUnderflowException will
> be thrown and when it will be thrown (by the 1. read operation, 2.te,...).
> This BufferUnderflowException will be swallowed by xSocket
>
> May be it becomes more clear by an example. The first read operation of the
> example code reads a byte. Implicit the byte will be removed from the
> internal xSocket read buffer. By calling the second read operation
> readString a BufferUnderflowException could be thrown.
> The onData method will be called again, if more data is received. By
> calling the onData method the readByte method will be called again. Because
> the byte has already be removed form the read buffer, the first byte of the
> string will be returned.
>
> This behaviour will not appear by using the read mark support.
>
> BadHandler implements IDataHandler {
>
> on Data(NonBlockingConnection nbc) {
>
> byte recordType = nbc.readByte();
>
> String version = nbc.readStringByDelimiter("\r\n");
> String signature = nbc.readStringByDelimiter("\r\n");
> int dataLength = nbc.readInt();
> ...
>
> }
> }
>
>
>
>
>
>
>
> 2008/5/7 Rod Magnuson <rod...@gm...>:
>
>> It looks like the docs have changed since I started using xSocket. My
>> onData implementation does
>>
>> // reset to read position (if former reads failed) and mark it
>> connection.resetToReadMark();
>> connection.markReadPosition();
>>
>> attempt to read datat that may or may not be thee
>>
>> connection.removeReadMark();
>>
>> process the data, only reached if a BufferUnderflowException
>> wasn't throw
>>
>> Is the mark manipulation still necessary?
>>
>> Thanks,
>> Rod
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
>> Don't miss this year's exciting event. There's still time to save $100.
>> Use priority code J8TL2D2.
>>
>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
>> _______________________________________________
>> xSocket-develop mailing list
>> xSo...@li...
>> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>>
>>
>
|