mirror of https://github.com/quasar/Quasar.git
Fixed situations which could break the server
This commit is contained in:
parent
5fb9905d05
commit
6d75eac831
|
@ -426,6 +426,7 @@ public void Disconnect()
|
||||||
|
|
||||||
if (_handle != null)
|
if (_handle != null)
|
||||||
{
|
{
|
||||||
|
_handle.Shutdown(SocketShutdown.Both);
|
||||||
_handle.Close();
|
_handle.Close();
|
||||||
_readOffset = 0;
|
_readOffset = 0;
|
||||||
_writeOffset = 0;
|
_writeOffset = 0;
|
||||||
|
|
|
@ -311,29 +311,37 @@ private void Process(object s, SocketAsyncEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e.SocketError == SocketError.Success)
|
do
|
||||||
{
|
{
|
||||||
Client client = new Client(this, e.AcceptSocket, PacketTypes.ToArray());
|
switch (e.SocketError)
|
||||||
|
|
||||||
lock (_clientsLock)
|
|
||||||
{
|
{
|
||||||
_clients.Add(client);
|
case SocketError.Success:
|
||||||
client.ClientState += OnClientState;
|
if (BufferManager.BuffersAvailable == 0)
|
||||||
client.ClientRead += OnClientRead;
|
BufferManager.IncreaseBufferCount(1);
|
||||||
client.ClientWrite += OnClientWrite;
|
|
||||||
|
|
||||||
if (BufferManager.BuffersAvailable == 0)
|
Client client = new Client(this, e.AcceptSocket, PacketTypes.ToArray());
|
||||||
BufferManager.IncreaseBufferCount(1);
|
|
||||||
|
|
||||||
OnClientState(client, true);
|
lock (_clientsLock)
|
||||||
|
{
|
||||||
|
_clients.Add(client);
|
||||||
|
client.ClientState += OnClientState;
|
||||||
|
client.ClientRead += OnClientRead;
|
||||||
|
client.ClientWrite += OnClientWrite;
|
||||||
|
|
||||||
|
OnClientState(client, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SocketError.ConnectionReset:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new SocketException();
|
||||||
}
|
}
|
||||||
|
|
||||||
e.AcceptSocket = null;
|
e.AcceptSocket = null; // enable reuse
|
||||||
if (!_handle.AcceptAsync(e))
|
} while (!_handle.AcceptAsync(e));
|
||||||
Process(null, e);
|
}
|
||||||
}
|
catch (ObjectDisposedException ex)
|
||||||
else
|
{
|
||||||
Disconnect();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -383,7 +391,10 @@ public void Disconnect()
|
||||||
Processing = true;
|
Processing = true;
|
||||||
|
|
||||||
if (_handle != null)
|
if (_handle != null)
|
||||||
|
{
|
||||||
|
_handle.Shutdown(SocketShutdown.Both);
|
||||||
_handle.Close();
|
_handle.Close();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_clientsLock)
|
lock (_clientsLock)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue