Project

General

Profile

NIOSslSocket-no-more-indefinite-loops.diff

Galya B, 03/02/2023 09:29 AM

Download (1.33 KB)

View differences:

src/com/goldencode/p2j/net/NIOSslSocket.java 2023-03-02 14:27:54 +0000
85 85
   /** Logger */
86 86
   protected static final CentralLogger LOG = CentralLogger.get(NIOSslSocket.class.getName());
87 87

  
88
   protected static final AtomicInteger THREAD_COUNT = new AtomicInteger(0); 
88
   protected static final AtomicInteger THREAD_COUNT = new AtomicInteger(0);
89

  
90
   /** Max retries of reading next data chunk from the channel. Corresponds to seconds. */
91
   private static final int MAX_READ_ATTEMPTS = 90;
92
   
89 93
   /** SSLEngine */
90 94
   protected final SSLEngine engine;
91 95
   
......
256 260
   protected byte[] readFully() throws IOException, EOFException
257 261
   {
258 262
      byte[] b = null;
259
      while(b == null)
263
      int attempt = 0;
264
      while(b == null && attempt < MAX_READ_ATTEMPTS)
260 265
      {
261 266
         if (!channel.isOpen())
262 267
         {
......
269 274
         catch (InterruptedException ignore)
270 275
         {
271 276
         }
277
         attempt++;
278
      }
279
      if (attempt >= MAX_READ_ATTEMPTS)
280
      {
281
         throw new IOException("Couldn't read next data chunk from the channel after " + attempt + " " +
282
                                  "attempts.");
272 283
      }
273 284
      if (b.length == 0)
274 285
      {