<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugClient|AnyCPU'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>bin\DebugClient\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <DebugType>full</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
using System.Net;
using System.Net.Sockets;
using System.Text;
+using System.Threading;
namespace Hazel.Tcp
{
try
{
- socket.BeginSend(fullBytes, 0, fullBytes.Length, SocketFlags.None, null, null);
+ this.sem.WaitOne();
+ socket.BeginSend(fullBytes, 0, fullBytes.Length, SocketFlags.None, FinishSend, null);
}
catch (Exception e)
{
+ try { this.sem.Set(); } catch (ObjectDisposedException) { }
Disconnect("Could not send data as an occured: " + e.Message);
}
try
{
- socket.BeginSend(fullBytes, 0, fullBytes.Length, SocketFlags.None, null, null);
+ this.sem.WaitOne();
+ socket.BeginSend(fullBytes, 0, fullBytes.Length, SocketFlags.None, FinishSend, null);
}
catch (Exception e)
{
+ try { this.sem.Set(); } catch (ObjectDisposedException) { }
Disconnect("Could not send data as an occured: " + e.Message);
}
Statistics.LogFragmentedSend(bytes.Length, fullBytes.Length);
}
-
+
+ private AutoResetEvent sem = new AutoResetEvent(true);
+ private void FinishSend(IAsyncResult ar)
+ {
+ try
+ {
+ this.socket.EndSend(ar);
+ }
+ catch { }
+ finally
+ {
+ try { this.sem.Set(); } catch (ObjectDisposedException) { }
+ }
+ }
+
/// <summary>
/// Starts waiting for a first handshake packet to be received.
/// </summary>
Statistics.LogFragmentedReceive(bytesRead, 0);
- if (msg.Position < bytesRead)
+ if (msg.Position < msg.Length)
{
ListenForData(msg, callback);
}
else
{
- msg.Position = 0;
try
{
+ msg.Position = 0;
callback(msg);
}
catch { }
{
if (disposing)
{
+ try
+ {
+ if (this.sem != null)
+ {
+ this.sem.Dispose();
+ this.sem = null;
+ }
+ }
+ catch { }
+
lock (this)
{
State = ConnectionState.NotConnected;
{
if (connection.reliableDataPacketsSent.TryRemove(this.Id, out Packet self))
{
- connection.Disconnect($"Reliable packet {self.Id} was not ack'd after {lifetime}ms ({self.Retransmissions} resends)");
+ connection.Disconnect($"Reliable packet {self.Id} (size={this.Length}) was not ack'd after {lifetime}ms ({self.Retransmissions} resends)");
self.Recycle();
}
{
if (connection.reliableDataPacketsSent.TryRemove(this.Id, out Packet self))
{
- connection.Disconnect($"Reliable packet {self.Id} was not ack'd after {self.Retransmissions} resends ({lifetime}ms)");
+ connection.Disconnect($"Reliable packet {self.Id} (size={this.Length}) was not ack'd after {self.Retransmissions} resends ({lifetime}ms)");
self.Recycle();
}