From db79d01b57badbe014d15d0c636a1420fa853c2e Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 10 Apr 2013 16:37:43 +1000 Subject: [PATCH] Add written bytes tracking for @bergerkiller --- CraftBukkit-Patches/0026-Netty.patch | 35 +++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/CraftBukkit-Patches/0026-Netty.patch b/CraftBukkit-Patches/0026-Netty.patch index 56e06a00c2..d5ef21c983 100644 --- a/CraftBukkit-Patches/0026-Netty.patch +++ b/CraftBukkit-Patches/0026-Netty.patch @@ -1,4 +1,4 @@ -From 591d89bd222a5e52f2dab0bf93e7df8f861cee29 Mon Sep 17 00:00:00 2001 +From 4c6632fc189e01d8cf3ab5d519c78ae31c08c398 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 14 Feb 2013 17:32:20 +1100 Subject: [PATCH] Netty @@ -284,10 +284,10 @@ index 0000000..54928b4 +} diff --git a/src/main/java/org/spigotmc/netty/NettyNetworkManager.java b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java new file mode 100644 -index 0000000..f551bbe +index 0000000..340d65a --- /dev/null +++ b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java -@@ -0,0 +1,235 @@ +@@ -0,0 +1,244 @@ +package org.spigotmc.netty; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -351,6 +351,7 @@ index 0000000..f551bbe + private String dcReason; + private Object[] dcArgs; + private Socket socketAdaptor; ++ private long writtenBytes; + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { @@ -522,13 +523,21 @@ index 0000000..f551bbe + d(); + } + } ++ ++ public long getWrittenBytes() { ++ return writtenBytes; ++ } ++ ++ public void addWrittenBytes(int written) { ++ writtenBytes += written; ++ } +} diff --git a/src/main/java/org/spigotmc/netty/NettyServerConnection.java b/src/main/java/org/spigotmc/netty/NettyServerConnection.java new file mode 100644 -index 0000000..9803105 +index 0000000..790f325 --- /dev/null +++ b/src/main/java/org/spigotmc/netty/NettyServerConnection.java -@@ -0,0 +1,109 @@ +@@ -0,0 +1,110 @@ +package org.spigotmc.netty; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -578,11 +587,12 @@ index 0000000..9803105 + // IP_TOS is not supported (Windows XP / Windows Server 2003) + } + ++ NettyNetworkManager networkManager = new NettyNetworkManager(); + ch.pipeline() + .addLast("timer", new ReadTimeoutHandler(30)) + .addLast("decoder", new PacketDecoder()) -+ .addLast("encoder", new PacketEncoder()) -+ .addLast("manager", new NettyNetworkManager()); ++ .addLast("encoder", new PacketEncoder(networkManager)) ++ .addLast("manager", networkManager); + } + }).group(new NioEventLoopGroup(threads, new ThreadFactoryBuilder().setNameFormat("Netty IO Thread - %1$d").build())).localAddress(host, port).bind(); + MinecraftServer.getServer().getLogger().info("Using Netty NIO with " + threads + " threads for network connections."); @@ -964,10 +974,10 @@ index 0000000..65074d2 +} diff --git a/src/main/java/org/spigotmc/netty/PacketEncoder.java b/src/main/java/org/spigotmc/netty/PacketEncoder.java new file mode 100644 -index 0000000..e671a0d +index 0000000..c8832d6 --- /dev/null +++ b/src/main/java/org/spigotmc/netty/PacketEncoder.java -@@ -0,0 +1,43 @@ +@@ -0,0 +1,50 @@ +package org.spigotmc.netty; + +import io.netty.buffer.ByteBuf; @@ -985,6 +995,11 @@ index 0000000..e671a0d + + private ByteBuf outBuf; + private DataOutputStream dataOut; ++ private final NettyNetworkManager networkManager; ++ ++ public PacketEncoder(NettyNetworkManager networkManager) { ++ this.networkManager = networkManager; ++ } + + @Override + public void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) throws Exception { @@ -997,6 +1012,8 @@ index 0000000..e671a0d + + out.writeByte(msg.n()); + msg.a(dataOut); ++ ++ networkManager.addWrittenBytes(outBuf.readableBytes()); + out.writeBytes(outBuf); + out.discardSomeReadBytes(); + }