Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: L2GameClient.java
- ===================================================================
- --- L2GameClient.java (revision 895)
- +++ L2GameClient.java (working copy)
- @@ -20,6 +20,8 @@
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- +import java.util.LinkedHashSet;
- +import java.util.Set;
- import java.util.concurrent.ArrayBlockingQueue;
- import java.util.concurrent.Future;
- import java.util.concurrent.RejectedExecutionException;
- @@ -116,6 +118,8 @@
- private final ArrayBlockingQueue<ReceivablePacket<L2GameClient>> _packetQueue;
- private final ReentrantLock _queueLock = new ReentrantLock();
- + protected final Set<ServerPacketSendThread> _serverPacketQueue;
- + protected final ReentrantLock _serverPacketQueueLock = new ReentrantLock();
- private int[][] trace;
- @@ -128,6 +132,7 @@
- _stats = new ClientStats();
- _packetQueue = new ArrayBlockingQueue<>(Config.CLIENT_PACKET_QUEUE_SIZE);
- + _serverPacketQueue = new LinkedHashSet<>();
- try
- {
- @@ -277,6 +282,11 @@
- return;
- }
- + if (gsp.waitForOtherPackets() > 0)
- + {
- + new ServerPacketSendThread(gsp).run();
- + }
- +
- getConnection().sendPacket(gsp);
- gsp.runImpl();
- }
- @@ -855,6 +865,56 @@
- }
- }
- + protected class ServerPacketSendThread extends Thread
- + {
- + L2GameServerPacket _packet;
- + protected ServerPacketSendThread(L2GameServerPacket packet)
- + {
- + _packet = packet;
- + }
- +
- + @Override
- + public void run()
- + {
- + try
- + {
- + _serverPacketQueueLock.lock();
- +
- + if (_serverPacketQueue.add(this))
- + {
- + // Unlock because the thread is going to sleep, we dont want the lock to sleep too :P
- + _serverPacketQueueLock.unlock();
- +
- + try
- + {
- + sleep(_packet.waitForOtherPackets());
- + }
- + catch (InterruptedException e)
- + {
- + _log.log(Level.WARNING, "Packet send interrupted while waiting: ", e);
- + }
- +
- + getConnection().sendPacket(_packet);
- + _packet.runImpl();
- +
- + // Lock again to make sure we properly remove this
- + _serverPacketQueueLock.lock();
- + _serverPacketQueue.remove(this);
- + }
- + }
- + finally
- + {
- + _serverPacketQueueLock.unlock();
- + }
- + }
- +
- + @Override
- + public boolean equals(Object obj)
- + {
- + return _packet.equals(obj);
- + }
- + }
- +
- protected class CleanupTask implements Runnable
- {
- @Override
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement