Archiviert
13
0

Add written bytes tracking for @bergerkiller

Dieser Commit ist enthalten in:
md_5 2013-04-10 16:37:43 +10:00
Ursprung d9c76252eb
Commit db79d01b57

Datei anzeigen

@ -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 <md_5@live.com.au>
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();
+ }