@@ -326,16 +326,18 @@ public void run() {
326326 conn = (WebSocketImpl ) key .attachment ();
327327 ByteBuffer buf = takeBuffer ();
328328 try {
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 {
340342 pushBuffer ( buf );
341343 }
@@ -346,7 +348,7 @@ public void run() {
346348 }
347349 if ( key .isWritable () ) {
348350 conn = (WebSocketImpl ) key .attachment ();
349- if ( SocketChannelIOHelper .batch ( conn , ( ByteChannel ) conn .channel ) ) {
351+ if ( SocketChannelIOHelper .batch ( conn , conn .channel ) ) {
350352 if ( key .isValid () )
351353 key .interestOps ( SelectionKey .OP_READ );
352354 }
@@ -359,9 +361,12 @@ public void run() {
359361 try {
360362 if ( SocketChannelIOHelper .readMore ( buf , conn , c ) )
361363 iqueue .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 ) {
366371 pushBuffer ( buf );
367372 throw e ;
0 commit comments