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)
|
||||
{
|
||||
_handle.Shutdown(SocketShutdown.Both);
|
||||
_handle.Close();
|
||||
_readOffset = 0;
|
||||
_writeOffset = 0;
|
||||
|
|
|
@ -311,29 +311,37 @@ private void Process(object s, SocketAsyncEventArgs e)
|
|||
{
|
||||
try
|
||||
{
|
||||
if (e.SocketError == SocketError.Success)
|
||||
do
|
||||
{
|
||||
Client client = new Client(this, e.AcceptSocket, PacketTypes.ToArray());
|
||||
|
||||
lock (_clientsLock)
|
||||
switch (e.SocketError)
|
||||
{
|
||||
_clients.Add(client);
|
||||
client.ClientState += OnClientState;
|
||||
client.ClientRead += OnClientRead;
|
||||
client.ClientWrite += OnClientWrite;
|
||||
case SocketError.Success:
|
||||
if (BufferManager.BuffersAvailable == 0)
|
||||
BufferManager.IncreaseBufferCount(1);
|
||||
|
||||
if (BufferManager.BuffersAvailable == 0)
|
||||
BufferManager.IncreaseBufferCount(1);
|
||||
Client client = new Client(this, e.AcceptSocket, PacketTypes.ToArray());
|
||||
|
||||
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;
|
||||
if (!_handle.AcceptAsync(e))
|
||||
Process(null, e);
|
||||
}
|
||||
else
|
||||
Disconnect();
|
||||
e.AcceptSocket = null; // enable reuse
|
||||
} while (!_handle.AcceptAsync(e));
|
||||
}
|
||||
catch (ObjectDisposedException ex)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -383,7 +391,10 @@ public void Disconnect()
|
|||
Processing = true;
|
||||
|
||||
if (_handle != null)
|
||||
{
|
||||
_handle.Shutdown(SocketShutdown.Both);
|
||||
_handle.Close();
|
||||
}
|
||||
|
||||
lock (_clientsLock)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue