@@ -56,6 +56,8 @@ public enum Role {
5656 public static final int READY_STATE_CLOSING = 2 ;
5757 public static final int READY_STATE_CLOSED = 3 ;
5858
59+ public static int BUFFERSIZE = 512 ;
60+
5961 /**
6062 * The default port of WebSockets, as defined in the spec. If the nullary
6163 * constructor is used, DEFAULT_PORT will be the port the WebSocketServer
@@ -91,13 +93,13 @@ public enum Role {
9193 * Queue of buffers that need to be sent to the client.
9294 */
9395 private BlockingQueue <ByteBuffer > bufferQueue ;
94-
96+
9597 /**
9698 * The amount of bytes still in queue to be sent, at every given time.
9799 * It's updated at every send/sent operation.
98100 */
99- private AtomicLong bufferQueueTotalAmount = new AtomicLong (0l );
100-
101+ private AtomicLong bufferQueueTotalAmount = new AtomicLong ( 0l );
102+
101103 private Draft draft = null ;
102104
103105 private Role role ;
@@ -143,7 +145,7 @@ public WebSocket( WebSocketListener listener , List<Draft> drafts , SocketChanne
143145 private void init ( WebSocketListener listener , Draft draft , SocketChannel socketchannel ) {
144146 this .sockchannel = socketchannel ;
145147 this .bufferQueue = new LinkedBlockingQueue <ByteBuffer >( 3 );
146- this .socketBuffer = ByteBuffer .allocate ( 65558 );
148+ this .socketBuffer = ByteBuffer .allocate ( BUFFERSIZE );
147149 socketBuffer .flip ();
148150 this .wsl = listener ;
149151 this .role = Role .CLIENT ;
@@ -516,7 +518,7 @@ public void flush() throws IOException {
516518 } else {
517519 // subtract this amount of data from the total queued (synchronized over this object)
518520 bufferQueueTotalAmount .addAndGet ( -written );
519-
521+
520522 this .bufferQueue .poll (); // Buffer finished. Remove it.
521523 buffer = this .bufferQueue .peek ();
522524 }
@@ -565,8 +567,8 @@ private void channelWrite( ByteBuffer buf ) throws InterruptedException {
565567 System .out .println ( "write(" + buf .remaining () + "): {" + ( buf .remaining () > 1000 ? "too big to display" : new String ( buf .array () ) ) + "}" );
566568
567569 // add up the number of bytes to the total queued (synchronized over this object)
568- bufferQueueTotalAmount .addAndGet (buf .remaining ());
569-
570+ bufferQueueTotalAmount .addAndGet ( buf .remaining () );
571+
570572 if ( !bufferQueue .offer ( buf ) ) {
571573 try {
572574 flush ();
0 commit comments