From 63ddbd13f6110fb1ef4b8f04916a051f695113bd Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Fri, 4 Dec 2015 20:13:14 +0000 Subject: [PATCH] Reverting latest L2jServer MMOCore changes. Other minor MMOCore improvements. --- trunk/dist/game/config/MMO.ini | 5 +-- trunk/dist/login/config/MMO.ini | 5 +-- trunk/java/com/l2jserver/Config.java | 3 -- .../commons/mmocore/AbstractPacket.java | 2 +- .../commons/mmocore/MMOConnection.java | 12 +------ .../commons/mmocore/SelectorConfig.java | 10 ------ .../commons/mmocore/SelectorThread.java | 33 ++++++------------- .../commons/mmocore/SendablePacket.java | 6 ++-- .../com/l2jserver/gameserver/GameServer.java | 1 - 9 files changed, 16 insertions(+), 61 deletions(-) diff --git a/trunk/dist/game/config/MMO.ini b/trunk/dist/game/config/MMO.ini index 1882ae9021..1a2ee693eb 100644 --- a/trunk/dist/game/config/MMO.ini +++ b/trunk/dist/game/config/MMO.ini @@ -18,7 +18,4 @@ MaxReadPerPass = 12 # Each unfinished read/write need a TEMP storage Buffer # on large player amount we need more Buffers # if there are not enough buffers new ones are generated but not stored for future usage -HelperBufferCount = 20 - -# Setting this to True will lower your ping, at the cost of an increase in bandwidth consumption. -TcpNoDelay = False \ No newline at end of file +HelperBufferCount = 20 \ No newline at end of file diff --git a/trunk/dist/login/config/MMO.ini b/trunk/dist/login/config/MMO.ini index 1882ae9021..1a2ee693eb 100644 --- a/trunk/dist/login/config/MMO.ini +++ b/trunk/dist/login/config/MMO.ini @@ -18,7 +18,4 @@ MaxReadPerPass = 12 # Each unfinished read/write need a TEMP storage Buffer # on large player amount we need more Buffers # if there are not enough buffers new ones are generated but not stored for future usage -HelperBufferCount = 20 - -# Setting this to True will lower your ping, at the cost of an increase in bandwidth consumption. -TcpNoDelay = False \ No newline at end of file +HelperBufferCount = 20 \ No newline at end of file diff --git a/trunk/java/com/l2jserver/Config.java b/trunk/java/com/l2jserver/Config.java index 3354a69e2a..bfa9e893b0 100644 --- a/trunk/java/com/l2jserver/Config.java +++ b/trunk/java/com/l2jserver/Config.java @@ -1002,7 +1002,6 @@ public final class Config public static int MMO_MAX_SEND_PER_PASS; public static int MMO_MAX_READ_PER_PASS; public static int MMO_HELPER_BUFFER_COUNT; - public static boolean MMO_TCP_NODELAY; // -------------------------------------------------- // Vitality Settings @@ -1750,7 +1749,6 @@ public final class Config MMO_MAX_SEND_PER_PASS = mmoSettings.getInt("MaxSendPerPass", 12); MMO_MAX_READ_PER_PASS = mmoSettings.getInt("MaxReadPerPass", 12); MMO_HELPER_BUFFER_COUNT = mmoSettings.getInt("HelperBufferCount", 20); - MMO_TCP_NODELAY = mmoSettings.getBoolean("TcpNoDelay", false); // Load IdFactory L2Properties file (if exists) final PropertiesParser IdFactory = new PropertiesParser(ID_CONFIG_FILE); @@ -2958,7 +2956,6 @@ public final class Config MMO_MAX_SEND_PER_PASS = mmoSettings.getInt("MaxSendPerPass", 12); MMO_MAX_READ_PER_PASS = mmoSettings.getInt("MaxReadPerPass", 12); MMO_HELPER_BUFFER_COUNT = mmoSettings.getInt("HelperBufferCount", 20); - MMO_TCP_NODELAY = mmoSettings.getBoolean("TcpNoDelay", false); // Load Telnet L2Properties file (if exists) final PropertiesParser telnetSettings = new PropertiesParser(TELNET_FILE); diff --git a/trunk/java/com/l2jserver/commons/mmocore/AbstractPacket.java b/trunk/java/com/l2jserver/commons/mmocore/AbstractPacket.java index 1950407028..6c438f78d7 100644 --- a/trunk/java/com/l2jserver/commons/mmocore/AbstractPacket.java +++ b/trunk/java/com/l2jserver/commons/mmocore/AbstractPacket.java @@ -27,7 +27,7 @@ public abstract class AbstractPacket> { protected ByteBuffer _buf; - protected T _client; + T _client; public final T getClient() { diff --git a/trunk/java/com/l2jserver/commons/mmocore/MMOConnection.java b/trunk/java/com/l2jserver/commons/mmocore/MMOConnection.java index e40692b61d..31502e2a1b 100644 --- a/trunk/java/com/l2jserver/commons/mmocore/MMOConnection.java +++ b/trunk/java/com/l2jserver/commons/mmocore/MMOConnection.java @@ -20,7 +20,6 @@ package com.l2jserver.commons.mmocore; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; -import java.net.SocketException; import java.nio.ByteBuffer; import java.nio.channels.CancelledKeyException; import java.nio.channels.ReadableByteChannel; @@ -61,7 +60,7 @@ public class MMOConnection> private T _client; - public MMOConnection(final SelectorThread selectorThread, final Socket socket, final SelectionKey key, boolean tcpNoDelay) + public MMOConnection(final SelectorThread selectorThread, final Socket socket, final SelectionKey key) { _selectorThread = selectorThread; _socket = socket; @@ -72,15 +71,6 @@ public class MMOConnection> _selectionKey = key; _sendQueue = new NioNetStackList<>(); - - try - { - _socket.setTcpNoDelay(tcpNoDelay); - } - catch (SocketException e) - { - e.printStackTrace(); - } } final void setClient(final T client) diff --git a/trunk/java/com/l2jserver/commons/mmocore/SelectorConfig.java b/trunk/java/com/l2jserver/commons/mmocore/SelectorConfig.java index ce4acd5d25..5bc7ca4dd5 100644 --- a/trunk/java/com/l2jserver/commons/mmocore/SelectorConfig.java +++ b/trunk/java/com/l2jserver/commons/mmocore/SelectorConfig.java @@ -51,14 +51,4 @@ public final class SelectorConfig * 10-30 for an latency/troughput trade-off based on your needs.
*/ public int SLEEP_TIME = 10; - - /** - * Used to enable/disable TCP_NODELAY which disable/enable Nagle's algorithm.
- *
- * Nagle's algorithm try to conserve bandwidth by minimizing the number of segments that are sent. When applications wish to decrease network latency and increase performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). Data will be sent earlier, at the cost of an increase - * in bandwidth consumption. The Nagle's algorithm is described in RFC 896.
- *
- * Summary, data will be sent earlier, thus lowering the ping, at the cost of a small increase in bandwidth consumption. - */ - public boolean TCP_NODELAY = false; } diff --git a/trunk/java/com/l2jserver/commons/mmocore/SelectorThread.java b/trunk/java/com/l2jserver/commons/mmocore/SelectorThread.java index 6e6cb3ff0b..9a0c15a40d 100644 --- a/trunk/java/com/l2jserver/commons/mmocore/SelectorThread.java +++ b/trunk/java/com/l2jserver/commons/mmocore/SelectorThread.java @@ -28,8 +28,7 @@ import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.Iterator; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.LinkedList; /** * Parts of design based on network core from WoodenGil @@ -55,7 +54,6 @@ public final class SelectorThread> extends Thread private final int MAX_SEND_PER_PASS; private final int MAX_READ_PER_PASS; private final long SLEEP_TIME; - public boolean TCP_NODELAY; // Main Buffers private final ByteBuffer DIRECT_WRITE_BUFFER; private final ByteBuffer WRITE_BUFFER; @@ -63,7 +61,7 @@ public final class SelectorThread> extends Thread // String Buffer private final NioNetStringBuffer STRING_BUFFER; // ByteBuffers General Purpose Pool - private final Queue _bufferPool; + private final LinkedList _bufferPool; // Pending Close private final NioNetStackList> _pendingClose; @@ -78,7 +76,6 @@ public final class SelectorThread> extends Thread MAX_SEND_PER_PASS = sc.MAX_SEND_PER_PASS; MAX_READ_PER_PASS = sc.MAX_READ_PER_PASS; SLEEP_TIME = sc.SLEEP_TIME; - TCP_NODELAY = sc.TCP_NODELAY; DIRECT_WRITE_BUFFER = ByteBuffer.allocateDirect(sc.WRITE_BUFFER_SIZE).order(BYTE_ORDER); WRITE_BUFFER = ByteBuffer.wrap(new byte[sc.WRITE_BUFFER_SIZE]).order(BYTE_ORDER); @@ -87,11 +84,11 @@ public final class SelectorThread> extends Thread STRING_BUFFER = new NioNetStringBuffer(64 * 1024); _pendingClose = new NioNetStackList<>(); - _bufferPool = new ConcurrentLinkedQueue<>(); + _bufferPool = new LinkedList<>(); for (int i = 0; i < HELPER_BUFFER_COUNT; i++) { - _bufferPool.add(ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER)); + _bufferPool.addLast(ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER)); } _acceptFilter = acceptFilter; @@ -127,7 +124,7 @@ public final class SelectorThread> extends Thread return ByteBuffer.wrap(new byte[HELPER_BUFFER_SIZE]).order(BYTE_ORDER); } - return _bufferPool.remove(); + return _bufferPool.removeFirst(); } final void recycleBuffer(ByteBuffer buf) @@ -135,7 +132,7 @@ public final class SelectorThread> extends Thread if (_bufferPool.size() < HELPER_BUFFER_COUNT) { buf.clear(); - _bufferPool.add(buf); + _bufferPool.addLast(buf); } } @@ -201,16 +198,9 @@ public final class SelectorThread> extends Thread { while (!_pendingClose.isEmpty()) { - try - { - con = _pendingClose.removeFirst(); - writeClosePacket(con); - closeConnectionImpl(con.getSelectionKey(), con); - } - catch (Exception e) - { - e.printStackTrace(); - } + con = _pendingClose.removeFirst(); + writeClosePacket(con); + closeConnectionImpl(con.getSelectionKey(), con); } } @@ -259,7 +249,7 @@ public final class SelectorThread> extends Thread { sc.configureBlocking(false); SelectionKey clientKey = sc.register(_selector, SelectionKey.OP_READ); - con = new MMOConnection<>(this, sc.socket(), clientKey, TCP_NODELAY); + con = new MMOConnection<>(this, sc.socket(), clientKey); con.setClient(_clientFactory.create(con)); clientKey.attach(con); } @@ -408,7 +398,6 @@ public final class SelectorThread> extends Thread } return true; } - // we don`t have enough bytes for the dataPacket so we need // to read key.interestOps(key.interestOps() | SelectionKey.OP_READ); @@ -615,8 +604,6 @@ public final class SelectorThread> extends Thread // set the write buffer sp._buf = WRITE_BUFFER; - // set the client. - sp._client = client; // write content to buffer sp.write(); // delete the write buffer diff --git a/trunk/java/com/l2jserver/commons/mmocore/SendablePacket.java b/trunk/java/com/l2jserver/commons/mmocore/SendablePacket.java index 2c27fe146f..398b26a4a6 100644 --- a/trunk/java/com/l2jserver/commons/mmocore/SendablePacket.java +++ b/trunk/java/com/l2jserver/commons/mmocore/SendablePacket.java @@ -45,8 +45,7 @@ public abstract class SendablePacket> extends AbstractPac */ protected final void writeC(final boolean data) { - int value = data ? 0x01 : 0x00; - _buf.put((byte) value); + _buf.put((byte) (data ? 0x01 : 0x00)); } /** @@ -96,8 +95,7 @@ public abstract class SendablePacket> extends AbstractPac */ protected final void writeD(final boolean value) { - int val = value ? 0x01 : 0x00; - _buf.putInt(val); + _buf.putInt(value ? 0x01 : 0x00); } /** diff --git a/trunk/java/com/l2jserver/gameserver/GameServer.java b/trunk/java/com/l2jserver/gameserver/GameServer.java index 7a2b271054..422b2c0208 100644 --- a/trunk/java/com/l2jserver/gameserver/GameServer.java +++ b/trunk/java/com/l2jserver/gameserver/GameServer.java @@ -428,7 +428,6 @@ public final class GameServer sc.MAX_SEND_PER_PASS = Config.MMO_MAX_SEND_PER_PASS; sc.SLEEP_TIME = Config.MMO_SELECTOR_SLEEP_TIME; sc.HELPER_BUFFER_COUNT = Config.MMO_HELPER_BUFFER_COUNT; - sc.TCP_NODELAY = Config.MMO_TCP_NODELAY; _gamePacketHandler = new L2GamePacketHandler(); _selectorThread = new SelectorThread<>(sc, _gamePacketHandler, _gamePacketHandler, _gamePacketHandler, new IPv4Filter());