--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <!-- The configuration and platform will be used to determine which assemblies to include from solution and
+ project documentation sources -->
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{359995e0-bef3-42dd-800f-20368ff5fabb}</ProjectGuid>
+ <SHFBSchemaVersion>2015.6.5.0</SHFBSchemaVersion>
+ <!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual Studio adds them anyway -->
+ <AssemblyName>Documentation</AssemblyName>
+ <RootNamespace>Documentation</RootNamespace>
+ <Name>Documentation</Name>
+ <!-- SHFB properties -->
+ <FrameworkVersion>.NET Framework 4.5</FrameworkVersion>
+ <OutputPath>.\Help\</OutputPath>
+ <HtmlHelpName>Documentation</HtmlHelpName>
+ <Language>en-US</Language>
+ <SaveComponentCacheCapacity>100</SaveComponentCacheCapacity>
+ <BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
+ <HelpFileFormat>Website</HelpFileFormat>
+ <IndentHtml>False</IndentHtml>
+ <KeepLogFile>True</KeepLogFile>
+ <DisableCodeBlockComponent>False</DisableCodeBlockComponent>
+ <CleanIntermediates>True</CleanIntermediates>
+ <DocumentationSources>
+ <DocumentationSource sourceFile="bin\Release\Hazel.dll" />
+<DocumentationSource sourceFile="bin\Release\Hazel.XML" /></DocumentationSources>
+ <HelpFileVersion>1.0.0.0</HelpFileVersion>
+ <MaximumGroupParts>2</MaximumGroupParts>
+ <NamespaceGrouping>False</NamespaceGrouping>
+ <SyntaxFilters>Standard</SyntaxFilters>
+ <SdkLinkTarget>Blank</SdkLinkTarget>
+ <RootNamespaceContainer>False</RootNamespaceContainer>
+ <PresentationStyle>VS2013</PresentationStyle>
+ <Preliminary>False</Preliminary>
+ <NamingMethod>Guid</NamingMethod>
+ <HelpTitle>Hazel Networking</HelpTitle>
+ <ContentPlacement>AboveNamespaces</ContentPlacement>
+ </PropertyGroup>
+ <!-- There are no properties for these groups. AnyCPU needs to appear in order for Visual Studio to perform
+ the build. The others are optional common platform types that may appear. -->
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
+ </PropertyGroup>
+ <!-- Import the SHFB build targets -->
+ <Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
+ <!-- The pre-build and post-build event properties must appear *after* the targets file import in order to be
+ evaluated correctly. -->
+ <PropertyGroup>
+ <PreBuildEvent>
+ </PreBuildEvent>
+ <PostBuildEvent>
+ </PostBuildEvent>
+ <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
+ </PropertyGroup>
+ <ItemGroup>
+ <ProjectReference Include="Hazel.csproj">
+ <Name>Hazel</Name>
+ <Project>{02CFBD30-D77D-400F-94B2-700F60EFDD7F}</Project>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
\ No newline at end of file
/// On each resend this is doubled for that packet.
/// </remarks>
public int ResendTimeout { get { return resendTimeout; } set { resendTimeout = value; } }
- private int resendTimeout = 200; //TODO this based of average ping?
+ private volatile int resendTimeout = 200; //TODO this based of average ping?
/// <summary>
/// Holds the last ID allocated.
/// </summary>
volatile bool hasReceivedSomething = false;
+ /// <summary>
+ /// The maximum times a message should be retransmitted before marking the endpoint as disconnected.
+ /// </summary>
+ public int RetransmissionsBeforeDisconnect { get { return retransmissionsBeforeDisconnect; } set { retransmissionsBeforeDisconnect = value; } }
+ private volatile int retransmissionsBeforeDisconnect = 3;
+
/// <summary>
/// Class to hold packet data
/// </summary>
- class Packet : IRecyclable
+ class Packet : IRecyclable, IDisposable
{
/// <summary>
/// Object pool for this event.
public volatile int LastTimeout;
public Action AckCallback;
public volatile bool Acknowledged;
+ public volatile int Retransmissions;
Packet()
{
LastTimeout = timeout;
AckCallback = ackCallback;
Acknowledged = false;
+ Retransmissions = 0;
}
/// <summary>
/// </summary>
public void Recycle()
{
+ lock (Timer)
+ Timer.Dispose();
+
objectPool.PutObject(this);
}
+
+ /// <summary>
+ /// Disposes of this object.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ lock (Timer)
+ Timer.Dispose();
+ }
+ }
}
/// <summary>
lock (p.Timer)
{
if (!p.Acknowledged)
+ {
p.Timer.Change(p.LastTimeout *= 2, Timeout.Infinite); //TODO disconnect after x tries
+ if (++p.Retransmissions >= RetransmissionsBeforeDisconnect)
+ {
+ HandleDisconnect();
+ p.Recycle();
+ }
+ }
}
Trace.WriteLine("Resend.");
packet.Acknowledged = true;
- lock (packet.Timer)
- packet.Timer.Dispose();
-
if (packet.AckCallback != null)
packet.AckCallback.Invoke();