State = ConnectionState.Connecting;
+ //Calculate local end point
+ EndPoint localEndPoint;
+ if (nep.EndPoint is IPEndPoint)
+ localEndPoint = new IPEndPoint(((IPEndPoint)nep.EndPoint).Address, 0);
+ else if (nep.EndPoint is IPEndPoint)
+ localEndPoint = new DnsEndPoint(((DnsEndPoint)nep.EndPoint).Host, 0);
+ else
+ throw new ArgumentException("Can only connect using an IPEndPoint or DnsEndpoint");
+
//Begin listening
try
{
- //TODO should that really be IPAddress.Any?
- socket.Bind(new IPEndPoint(IPAddress.Any, 0));
+ socket.Bind(localEndPoint);
}
catch (SocketException e)
{
byte[] buffer = HandleReceive(dataBuffer, bytesReceived);
SendOption sendOption = (SendOption)dataBuffer[0];
- //TODO may possibly get better performance with above/below swapped and block copy added
+ //TODO may get better performance with Handle receive after and block copy call added
//Begin receiving again
try
namespace Hazel
{
partial class UdpConnection
- {//TODO recycle dataevents and things?
+ {
+ //TODO recycle dataevents and things?
+
/// <summary>
/// The starting timeout, in miliseconds, at which data will be resent.
/// </summary>
/// </summary>
volatile ushort lastIDAllocated;
- /// <summary>
- /// The number of items to remember we have received before overwriting.
- /// </summary>
- private readonly int receiveCapacity = 4096;
-
/// <summary>
/// The packets of data that have been transmitted reliably and not acknowledged.
/// </summary>
//Handle reliableness!
lock (reliableDataPacketsMissing)
{
+ //TODO Looping of IDs
+ // Currently when ID loops all packets will be discarded as ID will be less than reliableReceiveLast
+ // And wont be in reliableDataPacketsMissing.
+
//If the ID <= reliableReceiveLast it might be something we're missing
//HasReceivedSomething handles the edge case of reliableReceiveLast = 0 & ID = 0
- //TODO Looping of IDs
if (id <= reliableReceiveLast && hasReceivedSomething)
{
//See if we're missing it, else this packet is a duplicate
Buffer.BlockCopy(data, 0, bytes, bytes.Length - data.Length, data.Length);
//Inform keepalive not to send for a while
- ResetKeepAliveTimer(); //TODO keepalive tests
+ ResetKeepAliveTimer();
//Write to connection
WriteBytesToConnection(bytes);
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
-//TODO complete trawl through for thread safety, everywhere
+
/*
* Copyright (C) Jamie Read - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
--- /dev/null
+<VSPerformanceSession Version="1.00">
+ <Options>
+ <CollectionMethod>Sampling</CollectionMethod>
+ <AllocationMethod>None</AllocationMethod>
+ <AddReport>true</AddReport>
+ <UniqueReport>Timestamp</UniqueReport>
+ <SamplingMethod>Cycles</SamplingMethod>
+ <CycleCount>10000000</CycleCount>
+ <PageFaultCount>10</PageFaultCount>
+ <SysCallCount>10</SysCallCount>
+ <SamplingCounter PlatformID="00000000" CounterID="0000000000000000" ReloadValue="000000000000000a" />
+ <RelocateBinaries>false</RelocateBinaries>
+ <HardwareCounters EnableHWCounters="false" />
+ </Options>
+ <PreinstrumentEvent>
+ <InstrEventExclude>false</InstrEventExclude>
+ </PreinstrumentEvent>
+ <PostinstrumentEvent>
+ <InstrEventExclude>false</InstrEventExclude>
+ </PostinstrumentEvent>
+</VSPerformanceSession>