Skip to content

Commit

Permalink
Merge pull request #100 from Eastrall/refacto/optimizations
Browse files Browse the repository at this point in the history
Remove useless code
  • Loading branch information
Filipe GP authored May 19, 2018
2 parents a67caf8 + 9bd24ea commit 6d6dc02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/Ether.Network/Client/NetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,10 @@ private void ProcessReceiveQueue()

if (buffer == null)
continue;

byte[] packetData = this.PacketProcessor.IncludeHeader
? this.Token.HeaderData.Concat(buffer).ToArray()
: buffer;
this.Token.HeaderData = null;


Task.Run(() =>
{
using (INetPacketStream packet = this.PacketProcessor.CreatePacket(packetData))
using (INetPacketStream packet = this.PacketProcessor.CreatePacket(buffer))
this.HandleMessage(packet);
}, this._cancelToken);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Ether.Network/Server/NetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ public void Stop()
/// <inheritdoc />
public void DisconnectClient(Guid clientId)
{
if (!this._clients.ContainsKey(clientId))
return;

if (!this._clients.TryRemove(clientId, out T removedClient))
return;

Expand All @@ -143,7 +140,7 @@ public void SendTo(IEnumerable<INetUser> users, INetPacketStream packet)
public void SendToAll(INetPacketStream packet) => this.SendTo(this.Clients, packet);

/// <inheritdoc />
public INetUser GetUser(Guid id) => this._clients.ContainsKey(id) ? this._clients[id] : null;
public INetUser GetUser(Guid id) => this._clients.TryGetValue(id, out T user) ? user : null;

/// <summary>
/// Initialize the server resourrces.
Expand Down Expand Up @@ -262,8 +259,9 @@ private void ProcessSendQueue()
if (message.User != null && message.Message != null)
this.SendMessage(message);
}
catch
catch (Exception e)
{
this.OnError(e);
if (this._sendQueueCancelToken.IsCancellationRequested)
break;
}
Expand Down

0 comments on commit 6d6dc02

Please sign in to comment.