@@ -326,16 +326,18 @@ public void run(){
326326conn = (WebSocketImpl ) key .attachment ();
327327ByteBuffer buf = takeBuffer ();
328328try {
329- if ( SocketChannelIOHelper .read ( buf , conn , (ByteChannel ) conn .channel ) ){
330- assert ( buf .hasRemaining () );
331- conn .inQueue .put ( buf );
332- queue ( conn );
333- i .remove ();
334- if ( conn .channel instanceof WrappedByteChannel ){
335- if ( ( (WrappedByteChannel ) conn .channel ).isNeedRead () ){
336- iqueue .add ( conn );
329+ if ( SocketChannelIOHelper .read ( buf , conn , conn .channel ) ){
330+ if ( buf .hasRemaining () ){
331+ conn .inQueue .put ( buf );
332+ queue ( conn );
333+ i .remove ();
334+ if ( conn .channel instanceof WrappedByteChannel ){
335+ if ( ( (WrappedByteChannel ) conn .channel ).isNeedRead () ){
336+ iqueue .add ( conn );
337+ }
337338 }
338- }
339+ } else
340+ pushBuffer ( buf );
339341 } else {
340342pushBuffer ( buf );
341343 }
@@ -346,7 +348,7 @@ public void run(){
346348 }
347349if ( key .isWritable () ){
348350conn = (WebSocketImpl ) key .attachment ();
349- if ( SocketChannelIOHelper .batch ( conn , ( ByteChannel ) conn .channel ) ){
351+ if ( SocketChannelIOHelper .batch ( conn , conn .channel ) ){
350352if ( key .isValid () )
351353key .interestOps ( SelectionKey .OP_READ );
352354 }
@@ -359,9 +361,12 @@ public void run(){
359361try {
360362if ( SocketChannelIOHelper .readMore ( buf , conn , c ) )
361363iqueue .add ( conn );
362- assert ( buf .hasRemaining () );
363- conn .inQueue .put ( buf );
364- queue ( conn );
364+ if ( buf .hasRemaining () ){
365+ conn .inQueue .put ( buf );
366+ queue ( conn );
367+ } else {
368+ pushBuffer ( buf );
369+ }
365370 } catch ( IOException e ){
366371pushBuffer ( buf );
367372throw e ;
0 commit comments