Multi-Threaded SendQueue

This commit is contained in:
MaxXor 2015-03-17 22:28:51 +01:00
parent d232ac8b86
commit 6bc4e9102d
2 changed files with 46 additions and 47 deletions

View File

@ -364,9 +364,7 @@ public void Disconnect()
}
}
catch
{
return;
}
{ }
}
}
@ -391,34 +389,34 @@ private void Send(byte[] data)
}
}
private void HandleSendQueue()
{
for (int i = 0; i < 5; i++)
new Thread(() =>
{
try
for (int i = 0; i < 5; i++)
{
if (_sendIndex >= _sendBuffer.Length)
try
{
_sendIndex = 0;
_sendBuffer = Header(_sendQueue.Dequeue());
if (_sendIndex >= _sendBuffer.Length)
{
_sendIndex = 0;
_sendBuffer = Header(_sendQueue.Dequeue());
}
int write = Math.Min(_sendBuffer.Length - _sendIndex, BufferSize);
_item[1].SetBuffer(_sendBuffer, _sendIndex, write);
if (!_handle.SendAsync(_item[1]))
Process(null, _item[1]);
return;
}
int write = Math.Min(_sendBuffer.Length - _sendIndex, BufferSize);
_item[1].SetBuffer(_sendBuffer, _sendIndex, write);
if (!_handle.SendAsync(_item[1]))
Process(null, _item[1]);
return;
catch
{ }
}
catch
{
continue;
}
}
Disconnect();
Disconnect();
}).Start();
}
private byte[] Header(byte[] data)

View File

@ -5,6 +5,7 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using ProtoBuf;
using ProtoBuf.Meta;
using xServer.Core.Compression;
@ -359,9 +360,7 @@ public void Disconnect()
}
}
catch
{
return;
}
{ }
}
}
@ -389,31 +388,33 @@ private void Send(byte[] data)
private void HandleSendQueue()
{
for (int i = 0; i < 5; i++)
new Thread(() =>
{
try
for (int i = 0; i < 5; i++)
{
if (_sendIndex >= _sendBuffer.Length)
try
{
if (_sendIndex >= _sendBuffer.Length)
{
_sendIndex = 0;
_sendBuffer = Header(_sendQueue.Dequeue());
}
int write = Math.Min(_sendBuffer.Length - _sendIndex, BufferSize);
_item[1].SetBuffer(_sendBuffer, _sendIndex, write);
if (!_handle.SendAsync(_item[1]))
Process(null, _item[1]);
return;
}
catch
{
_sendIndex = 0;
_sendBuffer = Header(_sendQueue.Dequeue());
}
int write = Math.Min(_sendBuffer.Length - _sendIndex, BufferSize);
_item[1].SetBuffer(_sendBuffer, _sendIndex, write);
if (!_handle.SendAsync(_item[1]))
Process(null, _item[1]);
return;
}
catch
{
continue;
}
}
Disconnect();
Disconnect();
}).Start();
}
private byte[] Header(byte[] data)