@@ -346,37 +346,32 @@ protected void readComplete0(byte op, int res, int flags, short data, int outsta |
346 | 346 | final ChannelPipeline pipeline = pipeline(); |
347 | 347 | ByteBuf byteBuf = this.readBuffer; |
348 | 348 | assert byteBuf != null; |
| 349 | + MsgHdrMemory hdr = recvmsgHdrs.hdr(data); |
| 350 | + // Reset the id as this read was completed and so don't need to be cancelled later. |
| 351 | + recvmsgHdrs.setId(data, MsgHdrMemoryArray.NO_ID); |
| 352 | + |
349 | 353 | try { |
350 | | - recvmsgComplete(pipeline, allocHandle, byteBuf, res, flags, data, outstanding); |
| 354 | + if (res < 0) { |
| 355 | + if (res != Native.ERRNO_ECANCELED_NEGATIVE) { |
| 356 | + // If res is negative we should pass it to ioResult(...) which will either throw |
| 357 | + // or convert it to 0 if we could not read because the socket was not readable. |
| 358 | + allocHandle.lastBytesRead(ioResult("io_uring recvmsg", res)); |
| 359 | + } |
| 360 | + } else { |
| 361 | + allocHandle.lastBytesRead(res); |
| 362 | + if (hdr.hasPort(IoUringDatagramChannel.this)) { |
| 363 | + allocHandle.incMessagesRead(1); |
| 364 | + DatagramPacket packet = hdr.get( |
| 365 | + IoUringDatagramChannel.this, registration().attachment(), byteBuf, res); |
| 366 | + pipeline.fireChannelRead(packet); |
| 367 | + } |
| 368 | + } |
351 | 369 | } catch (Throwable t) { |
352 | 370 | Throwable e = (connected && t instanceof NativeIoException) ? |
353 | 371 | translateForConnected((NativeIoException) t) : t; |
354 | 372 | pipeline.fireExceptionCaught(e); |
355 | 373 | } |
356 | | - } |
357 | 374 |
|
358 | | - private void recvmsgComplete(ChannelPipeline pipeline, IoUringRecvByteAllocatorHandle allocHandle, |
359 | | - ByteBuf byteBuf, int res, int flags, int idx, int outstanding) |
360 | | - throws IOException { |
361 | | - MsgHdrMemory hdr = recvmsgHdrs.hdr(idx); |
362 | | - if (res < 0) { |
363 | | - if (res != Native.ERRNO_ECANCELED_NEGATIVE) { |
364 | | - // If res is negative we should pass it to ioResult(...) which will either throw |
365 | | - // or convert it to 0 if we could not read because the socket was not readable. |
366 | | - allocHandle.lastBytesRead(ioResult("io_uring recvmsg", res)); |
367 | | - } |
368 | | - } else { |
369 | | - allocHandle.lastBytesRead(res); |
370 | | - if (hdr.hasPort(IoUringDatagramChannel.this)) { |
371 | | - allocHandle.incMessagesRead(1); |
372 | | - DatagramPacket packet = hdr.get( |
373 | | - IoUringDatagramChannel.this, registration().attachment(), byteBuf, res); |
374 | | - pipeline.fireChannelRead(packet); |
375 | | - } |
376 | | - } |
377 | | - |
378 | | - // Reset the id as this read was completed and so don't need to be cancelled later. |
379 | | - recvmsgHdrs.setId(idx, MsgHdrMemoryArray.NO_ID); |
380 | 375 | if (outstanding == 0) { |
381 | 376 | // There are no outstanding completion events, release the readBuffer and see if we need to schedule |
382 | 377 | // another one or if the user will do it. |
@@ -580,6 +575,7 @@ protected void unregistered() { |
580 | 575 | super.unregistered(); |
581 | 576 | sendmsgHdrs.release(); |
582 | 577 | recvmsgHdrs.release(); |
| 578 | + assert readBuffer == null; |
583 | 579 | } |
584 | 580 |
|
585 | 581 | private static IOException translateForConnected(NativeIoException e) { |
|