File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
java/libraries/net/src/processing/net Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 4545 * @see_external LIB_net/clientEvent
4646 */
4747public class Client implements Runnable {
48+
49+ protected static final int MAX_BUFFER_SIZE = 2 << 27 ; // 128 MB
50+
4851 PApplet parent ;
4952 Method clientEventMethod ;
5053 Method disconnectEventMethod ;
@@ -234,8 +237,6 @@ public void run() {
234237 }
235238
236239 synchronized (bufferLock ) {
237- // todo: at some point buffer should stop increasing in size,
238- // otherwise it could use up all the memory.
239240 int freeBack = buffer .length - bufferLast ;
240241 if (readCount > freeBack ) {
241242 // not enough space at the back
@@ -245,6 +246,13 @@ public void run() {
245246 // can't fit even after compacting, resize the buffer
246247 // find the next power of two which can fit everything in
247248 int newSize = Integer .highestOneBit (bufferLength + readCount - 1 ) << 1 ;
249+ if (newSize > MAX_BUFFER_SIZE ) {
250+ // buffer is full because client is not reading (fast enough)
251+ System .err .println ("Client: can't receive more data, buffer is full. " +
252+ "Make sure you read the data from the client." );
253+ stop ();
254+ return ;
255+ }
248256 targetBuffer = new byte [newSize ];
249257 }
250258 // compact the buffer (either in-place or into the new bigger buffer)
You can’t perform that action at this time.
0 commit comments