mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-03 09:14:01 +00:00
perf[proxy]: don't send any packet when the tunnel buffer is full
This commit is contained in:
1 parent
1cfe5ab433
commit
e690d3f224
3 files changed
+24
-11
No files matched your search
@@ -67,16 +67,12 @@ public class TunnelProtocolServer2Client {
|
||||
|
||||
|
||||
public void write(ByteBuf out) {
|
||||
try {
|
||||
out.ensureWritable(22);
|
||||
out.writerIndex(PacketService.PACKET_HEAD_LENGTH);
|
||||
ByteBufUtils.writeLong(out, sid);
|
||||
ByteBufUtils.writeLong(out, uid);
|
||||
out.writeBytes(retainedByteBuf);
|
||||
NetContext.getPacketService().writeHeaderBefore(out);
|
||||
} finally {
|
||||
ReferenceCountUtil.release(retainedByteBuf);
|
||||
}
|
||||
out.ensureWritable(22);
|
||||
out.writerIndex(PacketService.PACKET_HEAD_LENGTH);
|
||||
ByteBufUtils.writeLong(out, sid);
|
||||
ByteBufUtils.writeLong(out, uid);
|
||||
out.writeBytes(retainedByteBuf);
|
||||
NetContext.getPacketService().writeHeaderBefore(out);
|
||||
}
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageCodec;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,6 +36,8 @@ import java.util.List;
|
||||
*/
|
||||
public class ProxyCodecHandler extends ByteToMessageCodec<TunnelProtocolServer2Client> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProxyCodecHandler.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
||||
@@ -57,11 +61,20 @@ public class ProxyCodecHandler extends ByteToMessageCodec<TunnelProtocolServer2C
|
||||
|
||||
if (CollectionUtils.isEmpty(TunnelServer.tunnels)) {
|
||||
in.readSlice(length);
|
||||
logger.warn("Tunnel server has no tunnels");
|
||||
return;
|
||||
}
|
||||
|
||||
var tunnel = RandomUtils.randomEle(TunnelServer.tunnels);
|
||||
if (!SessionUtils.isActive(tunnel)) {
|
||||
in.readSlice(length);
|
||||
logger.warn("Tunnel server has no active tunnels");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tunnel.isWritable()) {
|
||||
in.readSlice(length);
|
||||
logger.warn("Tunnel server has no writable tunnels");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,11 @@ public class TunnelServerCodecHandler extends ByteToMessageCodec<TunnelProtocolS
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, TunnelProtocolServer2Client tunnelProtocol, ByteBuf out) {
|
||||
tunnelProtocol.write(out);
|
||||
try {
|
||||
tunnelProtocol.write(out);
|
||||
} finally {
|
||||
ReferenceCountUtil.release(tunnelProtocol.getRetainedByteBuf());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user