(@NotNull Protocol<?> p)
| 518 | } |
| 519 | |
| 520 | public boolean SendShared(@NotNull Protocol<?> p) { |
| 521 | if (ENABLE_PROTOCOL_LOG && canLogProtocol(p.getTypeId())) |
| 522 | log("SEND", getSessionId(), p); |
| 523 | |
| 524 | var result = submitAction(() -> { // 进selector线程调用 |
| 525 | var bb = p.encodeShared(); |
| 526 | var bytes = bb.Bytes; |
| 527 | var offset = bb.ReadIndex; |
| 528 | var length = bb.size(); |
| 529 | |
| 530 | var newSize = (long)outputBufferSizeHandle.getAndAdd(this, (long)length) + length; |
| 531 | if (!getService().checkOverflow(this, newSize, bytes, offset, length)) { |
| 532 | outputBufferSizeHandle.getAndAdd(this, (long)-length); |
| 533 | return; |
| 534 | } |
| 535 | var codec = outputCodecChain; |
| 536 | if (codec != null) { |
| 537 | sendRawSize += length; |
| 538 | // 压缩加密等 codec 链操作。 |
| 539 | int oldSize = outputBuffer.size(); |
| 540 | codec.update(bytes, offset, length); |
| 541 | int deltaLen = outputBuffer.size() - oldSize - length; |
| 542 | if (deltaLen != 0) |
| 543 | outputBufferSizeHandle.getAndAdd(this, (long)deltaLen); |
| 544 | } else |
| 545 | outputBuffer.put(bytes, offset, length); |
| 546 | if (ZezeCounter.instance != null) |
| 547 | ZezeCounter.instance.addSendSize(bytes, offset, length); |
| 548 | }); |
| 549 | if (result) |
| 550 | setActiveSendTime(); |
| 551 | return result; |
| 552 | } |
| 553 | |
| 554 | private void processReceive(@NotNull SocketChannel sc) throws Exception { // 只在selector线程调用 |
| 555 | recvCount++; |
nothing calls this directly
no test coverage detected