可能直接加到发送缓冲区,返回true则bytes不能再修改了。
(byte @NotNull [] bytes, int offset, int length)
| 483 | * 可能直接加到发送缓冲区,返回true则bytes不能再修改了。 |
| 484 | */ |
| 485 | @Override |
| 486 | public boolean Send(byte @NotNull [] bytes, int offset, int length) { |
| 487 | ByteBuffer.VerifyArrayIndex(bytes, offset, length); |
| 488 | |
| 489 | var newSize = (long)outputBufferSizeHandle.getAndAdd(this, (long)length) + length; |
| 490 | try { |
| 491 | if (!getService().checkOverflow(this, newSize, bytes, offset, length)) { |
| 492 | outputBufferSizeHandle.getAndAdd(this, (long)-length); |
| 493 | return false; |
| 494 | } |
| 495 | if (submitAction(() -> { // 进selector线程调用 |
| 496 | var codec = outputCodecChain; |
| 497 | if (codec != null) { |
| 498 | sendRawSize += length; |
| 499 | // 压缩加密等 codec 链操作。 |
| 500 | int oldSize = outputBuffer.size(); |
| 501 | codec.update(bytes, offset, length); |
| 502 | int deltaLen = outputBuffer.size() - oldSize - length; |
| 503 | if (deltaLen != 0) |
| 504 | outputBufferSizeHandle.getAndAdd(this, (long)deltaLen); |
| 505 | } else |
| 506 | outputBuffer.put(bytes, offset, length); |
| 507 | if (ZezeCounter.instance != null) |
| 508 | ZezeCounter.instance.addSendSize(bytes, offset, length); |
| 509 | })) { |
| 510 | setActiveSendTime(); |
| 511 | return true; |
| 512 | } |
| 513 | } catch (Exception ex) { |
| 514 | outputBufferSizeHandle.getAndAdd(this, (long)-length); |
| 515 | close(ex); |
| 516 | } |
| 517 | return false; |
| 518 | } |
| 519 | |
| 520 | public boolean SendShared(@NotNull Protocol<?> p) { |
| 521 | if (ENABLE_PROTOCOL_LOG && canLogProtocol(p.getTypeId())) |
nothing calls this directly
no test coverage detected