Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ See the patches list below.
[FalchusSpigot-????] Fix MC-87 map scaling/cloning issues
[FalchusSpigot-????] Fix view distance lookup
[FalchusSpigot-????] Only send Dragon/Wither Death sounds to same world
[FalchusSpigot-????] Improve NetworkManager

[DashSpigot-0033] Fix SPIGOT-1746: Tile entities may not always tick
[DashSpigot-0011] Fix MC-94186: Dragon egg falling in lazy chunks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.net.SocketAddress;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {

private final EnumProtocolDirection h;
private final Queue<NetworkManager.QueuedPacket> i = Queues.newConcurrentLinkedQueue();
private final ReentrantReadWriteLock j = new ReentrantReadWriteLock();
public Channel channel;
// Spigot Start // PAIL
public SocketAddress l;
Expand Down Expand Up @@ -235,13 +233,8 @@ public void handle(Packet packet) {
// WindSpigot end
this.dispatchPacket(packet, null, Boolean.TRUE);
} else {
this.j.writeLock().lock();

try {
this.i.add(new NetworkManager.QueuedPacket(packet));
} finally {
this.j.writeLock().unlock();
}
// FalchusSpigot - remove unnecessary locks for packets (the packet queue is already thread safe)
this.i.add(new NetworkManager.QueuedPacket(packet));
}

}
Expand All @@ -253,13 +246,8 @@ public void a(Packet packet, GenericFutureListener<? extends Future<? super Void
this.sendPacketQueue();
this.dispatchPacket(packet, ArrayUtils.insert(0, listeners, listener), Boolean.TRUE);
} else {
this.j.writeLock().lock();

try {
this.i.add(new NetworkManager.QueuedPacket(packet, ArrayUtils.insert(0, listeners, listener)));
} finally {
this.j.writeLock().unlock();
}
// FalchusSpigot - remove unnecessary locks for packets (the packet queue is already thread safe)
this.i.add(new NetworkManager.QueuedPacket(packet, ArrayUtils.insert(0, listeners, listener)));
}

}
Expand Down Expand Up @@ -308,8 +296,7 @@ public void dispatchPacket(final Packet<?> packet,
this.setProtocol(enumprotocol);
}
try {
ChannelFuture channelfuture1 = (flush) ? this.channel.writeAndFlush(packet)
: this.channel.write(packet); // Tuinity - add flush parameter
ChannelFuture channelfuture1 = this.channel.writeAndFlush(packet); // Tuinity - add flush parameter
if (listeners != null) {
channelfuture1.addListeners(listeners);
}
Expand Down Expand Up @@ -357,25 +344,21 @@ private void sendPacketQueue() {
if (this.i.isEmpty()) {
return; // [Nacho-0019] :: Avoid lock every packet send
}
if (this.channel != null && this.channel.isOpen()) {
this.j.readLock().lock();
if (this.channel != null && this.channel.isActive()) {
// FalchusSpigot - remove unnecessary locks for packets (the packet queue is already thread safe)
boolean needsFlush = this.canFlush;
boolean hasWrotePacket = false;
try {
Iterator<QueuedPacket> iterator = this.i.iterator();
while (iterator.hasNext()) {
QueuedPacket queued = iterator.next();
Packet packet = queued.a;
if (hasWrotePacket && (needsFlush || this.canFlush)) {
flush();
}
iterator.remove();
this.dispatchPacket(packet, queued.b,
(!iterator.hasNext() && (needsFlush || this.canFlush)) ? Boolean.TRUE : Boolean.FALSE);
hasWrotePacket = true;
Iterator<QueuedPacket> iterator = this.i.iterator();
while (iterator.hasNext()) {
QueuedPacket queued = iterator.next();
Packet packet = queued.a;
if (hasWrotePacket && (needsFlush || this.canFlush)) {
flush();
}
} finally {
this.j.readLock().unlock();
iterator.remove();
this.dispatchPacket(packet, queued.b,
(!iterator.hasNext() && (needsFlush || this.canFlush)) ? Boolean.TRUE : Boolean.FALSE);
hasWrotePacket = true;
}
}
}
Expand Down
Loading