1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-18 08:06:33 +09:00

Lots of xml comments added. Documentation updated.

Removed extension methods to be able to compile for .net framework 2.0
This commit is contained in:
lidgren
2010-10-20 20:03:39 +00:00
parent aa72849830
commit 8029d725d1
22 changed files with 156 additions and 67 deletions

Binary file not shown.

View File

@@ -14,11 +14,11 @@
<RootNamespace>Documentation</RootNamespace>
<Name>Documentation</Name>
<!-- SHFB properties -->
<OutputPath>.\Help\</OutputPath>
<OutputPath>.\</OutputPath>
<HtmlHelpName>Documentation</HtmlHelpName>
<Language>en-US</Language>
<DocumentationSources>
<DocumentationSource sourceFile="..\Lidgren.Network\Lidgren.Network.csproj" />
<DocumentationSource sourceFile="..\Lidgren.Network\Lidgren.Network.csproj" configuration="Release" />
</DocumentationSources>
<HelpTitle>Lidgren Network Library documentation</HelpTitle>
<BuildLogFile>

View File

@@ -38,18 +38,13 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Lidgren.Network.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

View File

@@ -78,8 +78,6 @@ namespace Lidgren.Network
cur |= firstBit << lastIndex;
m_data[lenMinusOne] = cur;
throw new NetException("TODO: update m_numBitsSet");
}
public int GetFirstSetIndex()
@@ -149,6 +147,7 @@ namespace Lidgren.Network
{
Array.Clear(m_data, 0, m_data.Length);
m_numBitsSet = 0;
NetException.Assert(this.IsEmpty());
}
/// <summary>

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lidgren.Network

View File

@@ -9,6 +9,9 @@ namespace Lidgren.Network
private float m_averageRoundtripTime;
private float m_timeoutDeadline = float.MaxValue;
/// <summary>
/// Gets the current average roundtrip time in seconds
/// </summary>
public float AverageRoundtripTime { get { return m_averageRoundtripTime; } }
internal void SendPing()

View File

@@ -266,7 +266,7 @@ namespace Lidgren.Network
private NetSenderChannelBase CreateSenderChannel(NetMessageType tp)
{
NetSenderChannelBase chan;
NetDeliveryMethod method = tp.GetDeliveryMethod();
NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp);
int sequenceChannel = (int)tp - (int)method;
switch (method)
{
@@ -357,7 +357,7 @@ namespace Lidgren.Network
// create receiver channel
NetReceiverChannelBase chan;
NetDeliveryMethod method = tp.GetDeliveryMethod();
NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp);
switch (method)
{
case NetDeliveryMethod.Unreliable:

View File

@@ -25,6 +25,9 @@ namespace Lidgren.Network
/// </summary>
public enum NetConnectionStatus
{
/// <summary>
/// No connection, or attempt, in place
/// </summary>
None,
/// <summary>

View File

@@ -23,21 +23,21 @@ namespace Lidgren.Network
/// <summary>
/// All the constants used when compiling the library
/// </summary>
public static class NetConstants
internal static class NetConstants
{
public const int NumTotalChannels = 99;
internal const int NumTotalChannels = 99;
public const int NetChannelsPerDeliveryMethod = 32;
internal const int NetChannelsPerDeliveryMethod = 32;
public const int NumSequenceNumbers = 1024;
internal const int NumSequenceNumbers = 1024;
public const int HeaderByteSize = 5;
internal const int HeaderByteSize = 5;
public const int UnreliableWindowSize = 128;
public const int ReliableOrderedWindowSize = 64;
public const int ReliableSequencedWindowSize = 64;
internal const int UnreliableWindowSize = 128;
internal const int ReliableOrderedWindowSize = 64;
internal const int ReliableSequencedWindowSize = 64;
public const int MaxFragmentationGroups = ushort.MaxValue - 1;
internal const int MaxFragmentationGroups = ushort.MaxValue - 1;
/// <summary>
/// Number of channels which needs a sequence number to work

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lidgren.Network
@@ -13,11 +12,35 @@ namespace Lidgren.Network
//
// Actually a publicly visible subset of NetMessageType
//
/// <summary>
/// Indicates an error
/// </summary>
Unknown = 0,
/// <summary>
/// Unreliable, unordered delivery
/// </summary>
Unreliable = 1,
/// <summary>
/// Unreliable delivery, but automatically dropping late messages
/// </summary>
UnreliableSequenced = 2,
/// <summary>
/// Reliable delivery, but unordered
/// </summary>
ReliableUnordered = 34,
/// <summary>
/// Reliable delivery, except for late messages which are dropped
/// </summary>
ReliableSequenced = 35,
/// <summary>
/// Reliable, ordered delivery
/// </summary>
ReliableOrdered = 67,
}
}

View File

@@ -28,6 +28,9 @@ namespace Lidgren.Network
//
// 1 bit
//
/// <summary>
/// Reads a 1-bit Boolean without advancing the read pointer
/// </summary>
public bool PeekBoolean()
{
NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
@@ -38,6 +41,9 @@ namespace Lidgren.Network
//
// 8 bit
//
/// <summary>
/// Reads a Byte without advancing the read pointer
/// </summary>
public byte PeekByte()
{
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
@@ -45,6 +51,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Reads an SByte without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public sbyte PeekSByte()
{
@@ -53,12 +62,18 @@ namespace Lidgren.Network
return (sbyte)retval;
}
/// <summary>
/// Reads the specified number of bits into a Byte without advancing the read pointer
/// </summary>
public byte PeekByte(int numberOfBits)
{
byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);
return retval;
}
/// <summary>
/// Reads the specified number of bytes without advancing the read pointer
/// </summary>
public byte[] PeekBytes(int numberOfBytes)
{
NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError);
@@ -68,6 +83,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Reads the specified number of bytes without advancing the read pointer
/// </summary>
public void PeekBytes(byte[] into, int offset, int numberOfBytes)
{
NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError);
@@ -80,6 +98,9 @@ namespace Lidgren.Network
//
// 16 bit
//
/// <summary>
/// Reads an Int16 without advancing the read pointer
/// </summary>
public Int16 PeekInt16()
{
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
@@ -87,6 +108,9 @@ namespace Lidgren.Network
return (short)retval;
}
/// <summary>
/// Reads a UInt16 without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public UInt16 PeekUInt16()
{
@@ -98,6 +122,9 @@ namespace Lidgren.Network
//
// 32 bit
//
/// <summary>
/// Reads an Int32 without advancing the read pointer
/// </summary>
public Int32 PeekInt32()
{
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
@@ -105,6 +132,9 @@ namespace Lidgren.Network
return (Int32)retval;
}
/// <summary>
/// Reads the specified number of bits into an Int32 without advancing the read pointer
/// </summary>
public Int32 PeekInt32(int numberOfBits)
{
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadInt() can only read between 1 and 32 bits");
@@ -128,6 +158,9 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Reads a UInt32 without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public UInt32 PeekUInt32()
{
@@ -136,6 +169,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Reads the specified number of bits into a UInt32 without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public UInt32 PeekUInt32(int numberOfBits)
{
@@ -149,6 +185,9 @@ namespace Lidgren.Network
//
// 64 bit
//
/// <summary>
/// Reads a UInt64 without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public UInt64 PeekUInt64()
{
@@ -162,6 +201,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Reads an Int32 without advancing the read pointer
/// </summary>
public Int64 PeekInt64()
{
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
@@ -173,6 +215,9 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Reads the specified number of bits into an UInt64 without advancing the read pointer
/// </summary>
[CLSCompliant(false)]
public UInt64 PeekUInt64(int numberOfBits)
{
@@ -192,6 +237,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Reads the specified number of bits into an Int64 without advancing the read pointer
/// </summary>
public Int64 PeekInt64(int numberOfBits)
{
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 65)), "ReadInt64(bits) can only read between 1 and 64 bits");
@@ -201,11 +249,17 @@ namespace Lidgren.Network
//
// Floating point
//
/// <summary>
/// Reads a 32-bit Single without advancing the read pointer
/// </summary>
public float PeekFloat()
{
return PeekSingle();
}
/// <summary>
/// Reads a 32-bit Single without advancing the read pointer
/// </summary>
public float PeekSingle()
{
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
@@ -221,6 +275,9 @@ namespace Lidgren.Network
return BitConverter.ToSingle(bytes, 0); // endianness is handled inside BitConverter.ToSingle
}
/// <summary>
/// Reads a 64-bit Double without advancing the read pointer
/// </summary>
public double PeekDouble()
{
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
@@ -237,7 +294,7 @@ namespace Lidgren.Network
}
/// <summary>
/// Reads a string
/// Reads a string without advancing the read pointer
/// </summary>
public string PeekString()
{

View File

@@ -45,12 +45,12 @@ namespace Lidgren.Network
/// <summary>
/// Gets the delivery method this message was sent with (if user data)
/// </summary>
public NetDeliveryMethod DeliveryMethod { get { return m_receivedMessageType.GetDeliveryMethod(); } }
public NetDeliveryMethod DeliveryMethod { get { return NetUtility.GetDeliveryMethod(m_receivedMessageType); } }
/// <summary>
/// Gets the sequence channel this message was sent with (if user data)
/// </summary>
public int SequenceChannel { get { return (int)m_receivedMessageType - (int)m_receivedMessageType.GetDeliveryMethod(); } }
public int SequenceChannel { get { return (int)m_receivedMessageType - (int)NetUtility.GetDeliveryMethod(m_receivedMessageType); } }
/// <summary>
/// IPEndPoint of sender, if any

View File

@@ -170,25 +170,4 @@ namespace Lidgren.Network
NatPunchMessage = 138, // send between peers
NatIntroduction = 139, // send to master server
}
internal static class NetMessageTypeExtensions
{
internal static bool IsLibrary(this NetMessageType tp)
{
return tp >= NetMessageType.LibraryError;
}
internal static NetDeliveryMethod GetDeliveryMethod(this NetMessageType mtp)
{
if (mtp >= NetMessageType.UserReliableOrdered1)
return NetDeliveryMethod.ReliableOrdered;
else if (mtp >= NetMessageType.UserReliableSequenced1)
return NetDeliveryMethod.ReliableSequenced;
else if (mtp >= NetMessageType.UserReliableUnordered)
return NetDeliveryMethod.ReliableUnordered;
else if (mtp >= NetMessageType.UserSequenced1)
return NetDeliveryMethod.UnreliableSequenced;
return NetDeliveryMethod.Unreliable;
}
}
}

View File

@@ -161,7 +161,7 @@ namespace Lidgren.Network
msg.m_data = null;
// message fragments cannot be recycled
// TODO: find a way to recycle large message after all fragments has been acknowledged
// TODO: find a way to recycle large message after all fragments has been acknowledged; or? possibly better just to garbage collect them
if (msg.m_fragmentGroup == 0)
Recycle(storage);

View File

@@ -31,8 +31,15 @@ namespace Lidgren.Network
throw new ArgumentNullException("msg");
if (recipient == null)
throw new ArgumentNullException("recipient");
if (method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered)
NetException.Assert(sequenceChannel == 0, "Delivery method " + method + " cannot use sequence channels other than 0!");
NetException.Assert(
((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) ||
((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)),
"Delivery method " + method + " cannot use sequence channels other than 0!"
);
NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!");
if (msg.m_isSent)
throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");
@@ -106,7 +113,7 @@ namespace Lidgren.Network
msg.m_messageType = NetMessageType.Unconnected;
// TODO: Interlocked.Add(ref msg.m_recyclingCount, recipients.Count); ?
Interlocked.Increment(ref msg.m_recyclingCount);
m_unsentUnconnectedMessages.Enqueue(new NetTuple<IPEndPoint, NetOutgoingMessage>(new IPEndPoint(adr, port), msg));
}
@@ -126,7 +133,7 @@ namespace Lidgren.Network
msg.m_messageType = NetMessageType.Unconnected;
// TODO: Interlocked.Add(ref msg.m_recyclingCount, recipients.Count); ?
Interlocked.Increment(ref msg.m_recyclingCount);
m_unsentUnconnectedMessages.Enqueue(new NetTuple<IPEndPoint, NetOutgoingMessage>(recipient, msg));
}

View File

@@ -20,7 +20,7 @@ namespace Lidgren.Network
private string m_shutdownReason;
/// <summary>
/// Gets the status of the NetPeer
/// Gets the NetPeerStatus of the NetPeer
/// </summary>
public NetPeerStatus Status { get { return m_status; } }
@@ -33,12 +33,12 @@ namespace Lidgren.Network
public AutoResetEvent MessageReceivedEvent { get { return m_messageReceivedEvent; } }
/// <summary>
/// Gets a unique identifier for this NetPeer based on Mac address and ip/port. Note! Not available until Start has been called!
/// Gets a unique identifier for this NetPeer based on Mac address and ip/port. Note! Not available until Start() has been called!
/// </summary>
public long UniqueIdentifier { get { return m_uniqueIdentifier; } }
/// <summary>
/// Gets the port number this NetPeer is listening and sending on
/// Gets the port number this NetPeer is listening and sending on, if Start() has been called
/// </summary>
public int Port { get { return m_listenPort; } }
@@ -55,7 +55,7 @@ namespace Lidgren.Network
}
/// <summary>
/// Returns the number of active connections
/// Gets the number of active connections
/// </summary>
public int ConnectionsCount
{
@@ -71,7 +71,7 @@ namespace Lidgren.Network
}
/// <summary>
/// Gets the configuration of the netpeer
/// Gets the configuration used to instanciate this NetPeer
/// </summary>
public NetPeerConfiguration Configuration { get { return m_configuration; } }
@@ -90,7 +90,7 @@ namespace Lidgren.Network
}
/// <summary>
/// Binds to socket and spawns networking thread
/// Binds to socket and spawns the networking thread
/// </summary>
public void Start()
{

View File

@@ -339,6 +339,9 @@ namespace Lidgren.Network
}
#endif
/// <summary>
/// Creates a memberwise shallow clone of this configuration
/// </summary>
public NetPeerConfiguration Clone()
{
NetPeerConfiguration retval = this.MemberwiseClone() as NetPeerConfiguration;

View File

@@ -94,7 +94,7 @@ namespace Lidgren.Network
/// <summary>
/// Gets the number of bytes allocated (and possibly garbage collected) for message storage
/// </summary>
public long BytesAllocated { get { return m_bytesAllocated; } }
public long StorageBytesAllocated { get { return m_bytesAllocated; } }
/// <summary>
/// Gets the number of bytes in the recycled pool
@@ -126,7 +126,7 @@ namespace Lidgren.Network
bdr.AppendLine(m_peer.ConnectionsCount.ToString() + " connections");
bdr.AppendLine("Sent " + m_sentBytes + " bytes in " + m_sentMessages + " messages in " + m_sentPackets + " packets");
bdr.AppendLine("Received " + m_receivedBytes + " bytes in " + m_receivedMessages + " messages in " + m_receivedPackets + " packets");
bdr.AppendLine("Allocated " + m_bytesAllocated + " bytes");
bdr.AppendLine("Storage allocated " + m_bytesAllocated + " bytes");
bdr.AppendLine("Recycled pool " + m_peer.m_storagePoolBytes + " bytes");
return bdr.ToString();
}

View File

@@ -52,11 +52,13 @@ namespace Lidgren.Network
/// </summary>
public int Count { get { return m_size; } }
/// <summary>
/// Gets the current capacity for the queue
/// </summary>
public int Capacity { get { return m_items.Length; } }
public NetQueue(int initialCapacity)
{
System.Collections.Generic.Queue<int> a;
m_lock = new object();
m_items = new T[initialCapacity];
}

View File

@@ -37,6 +37,9 @@ namespace Lidgren.Network
/// FastRandom are in use or if being used in a multi-threaded environment.
public class NetRandom
{
/// <summary>
/// Gets a global NetRandom instance
/// </summary>
public static readonly NetRandom Instance = new NetRandom();
// The +1 ensures NextDouble doesn't generate 1.0

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lidgren.Network

View File

@@ -220,8 +220,7 @@ namespace Lidgren.Network
return (numBits + 7) / 8;
}
[CLSCompliant(false)]
public static UInt32 SwapByteOrder(UInt32 value)
internal static UInt32 SwapByteOrder(UInt32 value)
{
return
((value & 0xff000000) >> 24) |
@@ -230,8 +229,7 @@ namespace Lidgren.Network
((value & 0x000000ff) << 24);
}
[CLSCompliant(false)]
public static UInt64 SwapByteOrder(UInt64 value)
internal static UInt64 SwapByteOrder(UInt64 value)
{
return
((value & 0xff00000000000000L) >> 56) |
@@ -244,7 +242,7 @@ namespace Lidgren.Network
((value & 0x00000000000000ffL) << 56);
}
public static bool CompareElements(byte[] one, byte[] two)
internal static bool CompareElements(byte[] one, byte[] two)
{
if (one.Length != two.Length)
return false;
@@ -254,6 +252,9 @@ namespace Lidgren.Network
return true;
}
/// <summary>
/// Convert a hexadecimal string to a byte array
/// </summary>
public static byte[] ToByteArray(String hexString)
{
byte[] retval = new byte[hexString.Length / 2];
@@ -262,6 +263,9 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Converts a number of bytes to a shorter, more readable string representation
/// </summary>
public static string ToHumanReadable(long bytes)
{
if (bytes < 4000) // 1-4 kb is printed in bytes
@@ -317,5 +321,18 @@ namespace Lidgren.Network
h /= 3;
}
}
internal static NetDeliveryMethod GetDeliveryMethod(NetMessageType mtp)
{
if (mtp >= NetMessageType.UserReliableOrdered1)
return NetDeliveryMethod.ReliableOrdered;
else if (mtp >= NetMessageType.UserReliableSequenced1)
return NetDeliveryMethod.ReliableSequenced;
else if (mtp >= NetMessageType.UserReliableUnordered)
return NetDeliveryMethod.ReliableUnordered;
else if (mtp >= NetMessageType.UserSequenced1)
return NetDeliveryMethod.UnreliableSequenced;
return NetDeliveryMethod.Unreliable;
}
}
}