(int reservation, boolean block)
| 251 | |
| 252 | |
| 253 | final int reserveWindowSize(int reservation, boolean block) throws IOException { |
| 254 | windowAllocationLock.lock(); |
| 255 | try { |
| 256 | long windowSize = getWindowSize(); |
| 257 | while (windowSize < 1) { |
| 258 | if (!canWrite()) { |
| 259 | throw new CloseNowException(sm.getString("stream.notWritable", getConnectionId(), getIdAsString())); |
| 260 | } |
| 261 | if (block) { |
| 262 | try { |
| 263 | long writeTimeout = handler.getProtocol().getStreamWriteTimeout(); |
| 264 | allocationManager.waitForStream(writeTimeout); |
| 265 | windowSize = getWindowSize(); |
| 266 | if (windowSize == 0) { |
| 267 | doStreamCancel(sm.getString("stream.writeTimeout"), Http2Error.ENHANCE_YOUR_CALM); |
| 268 | } |
| 269 | } catch (InterruptedException e) { |
| 270 | // Possible shutdown / rst or similar. Use an IOException to |
| 271 | // signal to the client that further I/O isn't possible for this |
| 272 | // Stream. |
| 273 | throw new IOException(e); |
| 274 | } |
| 275 | } else { |
| 276 | allocationManager.waitForStreamNonBlocking(); |
| 277 | return 0; |
| 278 | } |
| 279 | } |
| 280 | int allocation; |
| 281 | if (windowSize < reservation) { |
| 282 | allocation = (int) windowSize; |
| 283 | } else { |
| 284 | allocation = reservation; |
| 285 | } |
| 286 | decrementWindowSize(allocation); |
| 287 | return allocation; |
| 288 | } finally { |
| 289 | windowAllocationLock.unlock(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
| 294 | void doStreamCancel(String msg, Http2Error error) throws CloseNowException { |
no test coverage detected