├── .gitignore ├── LICENSE ├── NuGet-Install.bat ├── Package.proj ├── README.md ├── ReceiveFile ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── ReceiveFile.csproj └── app.config ├── SendFile ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SendFile.csproj └── app.config ├── UdtProtocol-Test ├── Ack2PacketTest.cs ├── CongestionPacketTest.cs ├── DataPacketTest.cs ├── ErrorPacketTest.cs ├── KeepAlivePacketTest.cs ├── MessageTest.cs ├── NetworkStreamTest.cs ├── Properties │ └── AssemblyInfo.cs ├── ShutdownPacketTest.cs ├── SocketPollerTest.cs ├── SocketTest.cs ├── StdFileStreamTest.cs ├── UdtProtocol-Test.csproj └── packages.config ├── UdtProtocol.sln ├── UdtProtocol ├── Ack2Packet.cpp ├── Ack2Packet.h ├── AssemblyInfo.cpp ├── CCCWrapper.cpp ├── CCCWrapper.h ├── CCCWrapperFactory.cpp ├── CCCWrapperFactory.h ├── CongestionControl.cpp ├── CongestionControl.h ├── CongestionControlFactory.cpp ├── CongestionControlFactory.h ├── CongestionPacket.cpp ├── CongestionPacket.h ├── ControlPacket.cpp ├── ControlPacket.h ├── DataPacket.cpp ├── DataPacket.h ├── ErrorPacket.cpp ├── ErrorPacket.h ├── ICongestionControlFactory.cpp ├── ICongestionControlFactory.h ├── KeepAlivePacket.cpp ├── KeepAlivePacket.h ├── LocalTraceInfo.cpp ├── LocalTraceInfo.h ├── Message.cpp ├── Message.h ├── MessageBoundary.h ├── NativeIntArray.cpp ├── NativeIntArray.h ├── NetworkStream.cpp ├── NetworkStream.h ├── Packet.cpp ├── Packet.h ├── ProbeTraceInfo.cpp ├── ProbeTraceInfo.h ├── ShutdownPacket.cpp ├── ShutdownPacket.h ├── Socket.cpp ├── Socket.h ├── SocketError.h ├── SocketEvents.h ├── SocketException.cpp ├── SocketException.h ├── SocketOptionName.h ├── SocketPoller.cpp ├── SocketPoller.h ├── SocketState.h ├── StdFileStream.cpp ├── StdFileStream.h ├── Stdafx.cpp ├── Stdafx.h ├── TotalTraceInfo.cpp ├── TotalTraceInfo.h ├── TraceInfo.cpp ├── TraceInfo.h ├── UdtProtocol.rc ├── UdtProtocol.vcxproj ├── UdtProtocol.vcxproj.filters └── resource.h └── packages └── repositories.config /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | *.ncb 3 | *.sdf 4 | *.suo 5 | obj/ 6 | bin/ 7 | *.opensdf 8 | packages/*/** 9 | ipch/ 10 | *.aps 11 | TestResult.xml 12 | UdtProtocol/UdtProtocol.snk 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 2 | 3 | Copyright (c) 2015, Cory Thomas 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | * Neither the name of the nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /NuGet-Install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not defined NuGetExe set NuGetExe=NuGet.exe 4 | 5 | %NuGetExe% install UdtProtocol-Test\packages.config -o Packages 6 | -------------------------------------------------------------------------------- /Package.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | 16 | 19 | 20 | 21 | 22 | C:\Program Files (x86)\NUnit 2.5.10 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 66 | 67 | 71 | 72 | 73 | 77 | 78 | 79 | 80 | 81 | 82 | 86 | 87 | 90 | 91 | 95 | 98 | 99 | 103 | 104 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Notice** It appears the underlying native udt library is no longer being maintained. There have been no new releases since Feb 2013. This library is simply a wrapper around the native library. This library has very little functionality on it's own. While I can make minor fixes to this wrapper library, I can not fix any issues discovered in the underlying native udt library, where most of the functionality resides. 2 | 3 | # Overview 4 | 5 | UDT is a reliable UDP based application level data transport protocol for 6 | distributed data intensive applications over wide area high-speed networks. 7 | UDT uses UDP to transfer bulk data with its own reliability control and 8 | congestion control mechanisms. The new protocol can transfer data at a much 9 | higher speed than TCP does. UDT is also a highly configurable framework that 10 | can accommodate various congestion control algorithms. 11 | 12 | [Release Notes](//github.com/dump247/udt-net/wiki/Release-Notes) 13 | 14 | # Features 15 | 16 | * .Net API on top of the native UDT API 17 | * Support for custom congestion control algorithms written in managed code 18 | 19 | # Usage 20 | 21 | The code is in the Udt namespace and Udt.Socket is the interface to the native 22 | UDT socket library. The Udt.Socket API matches closely with the 23 | [System.Net.Sockets.Socket](http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx) 24 | API. 25 | 26 | [Example: Send Receive File](https://github.com/dump247/udt-net/wiki/Example:-Send-Receive-File) 27 | 28 | [Socket Performance Info](https://github.com/dump247/udt-net/wiki/Socket-Performance-Info) 29 | 30 | # TODO 31 | 32 | * Missing some properties in Packet (from CPacket) 33 | * CongestionControl.SendCustomMessage (CCC::sendCustomMsg) 34 | * CongestionControl.SetUserParameter (CCC::setUserParam) 35 | * Something similar to [TcpClient](http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx) and [TcpListener](http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx) 36 | * Asynchronous API 37 | * More Documentation 38 | 39 | # Requirements 40 | 41 | ## Dependencies 42 | * Microsoft .NET 4.0 43 | * Visual C++ Redistributable Package (if you don't have Visual C++ installed) 44 | * This package contains the VS2010 C Runtime and is required to run applications developed with Visual C++ 2010 45 | * http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5555 46 | 47 | ## Supported Platforms 48 | * Microsoft Windows (Win32 and x64) 49 | 50 | ## Developers 51 | 52 | This project is implemented in Managed C++ and requires Microsoft Visual C++ 53 | 2010. Building the demo apps and unit tests requires C# compiler. 54 | 55 | [Build Project](//github.com/dump247/udt-net/wiki/Setup-Development-Environment) 56 | 57 | # License 58 | 59 | BSD LICENSE Copyright (c) 2015 Cory Thomas 60 | 61 | See [LICENSE](LICENSE) 62 | -------------------------------------------------------------------------------- /ReceiveFile/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Net.Sockets; 6 | using System.Net; 7 | 8 | namespace ReceiveFile 9 | { 10 | class Program 11 | { 12 | static int Main(string[] args) 13 | { 14 | if ((args.Length != 4) || (0 == int.Parse(args[1]))) 15 | { 16 | Console.WriteLine("Usage: ReceiveFile server_ip server_port remote_filename local_filename"); 17 | return 1; 18 | } 19 | 20 | try 21 | { 22 | using (Udt.Socket client = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) 23 | { 24 | client.Connect(IPAddress.Parse(args[0]), int.Parse(args[1])); 25 | 26 | // Send name information of the requested file 27 | string name = args[2]; 28 | byte[] nameBytes = Encoding.UTF8.GetBytes(name); 29 | 30 | client.Send(BitConverter.GetBytes(nameBytes.Length), 0, sizeof(int)); 31 | client.Send(nameBytes); 32 | 33 | // Get size information 34 | long size; 35 | byte[] file = new byte[1024]; 36 | 37 | client.Receive(file, 0, sizeof(long)); 38 | size = BitConverter.ToInt64(file, 0); 39 | 40 | // Receive the file 41 | string localName = args[3]; 42 | client.ReceiveFile(localName, size); 43 | 44 | client.Close(); 45 | } 46 | 47 | Console.ReadKey(true); 48 | return 0; 49 | } 50 | catch (Exception ex) 51 | { 52 | Console.Error.WriteLine("Error receiving file: {0}", ex.Message); 53 | Console.ReadKey(true); 54 | return 2; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ReceiveFile/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ReceiveFile")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ReceiveFile")] 13 | [assembly: AssemblyCopyright("Copyright © 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("672d203c-e7c3-4209-802c-425d3447616d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | -------------------------------------------------------------------------------- /ReceiveFile/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SendFile/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Net.Sockets; 6 | using System.Net; 7 | using System.IO; 8 | using System.Reflection; 9 | using System.Threading; 10 | 11 | namespace SendFile 12 | { 13 | class Program 14 | { 15 | static int Main(string[] args) 16 | { 17 | if ((1 < args.Length) || ((1 == args.Length) && (0 == int.Parse(args[0])))) 18 | { 19 | Console.WriteLine("Usage: SendFile [ServerPort]"); 20 | return 1; 21 | } 22 | 23 | try 24 | { 25 | using (Udt.Socket server = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) 26 | { 27 | int port = 9000; 28 | if (1 == args.Length) 29 | port = int.Parse(args[0]); 30 | 31 | server.Bind(IPAddress.Any, port); 32 | Console.WriteLine("Server is ready at port: {0}", port); 33 | server.Listen(1); 34 | 35 | using (Udt.Socket client = server.Accept()) 36 | { 37 | server.Close(); 38 | 39 | // Receive file name from client 40 | byte[] file = new byte[1024]; 41 | int length; 42 | string name; 43 | 44 | client.Receive(file, 0, sizeof(int)); 45 | length = BitConverter.ToInt32(file, 0); 46 | 47 | client.Receive(file, 0, length); 48 | name = Encoding.UTF8.GetString(file, 0, length); 49 | 50 | // Send file size information 51 | client.Send(BitConverter.GetBytes(new FileInfo(name).Length), 0, sizeof(long)); 52 | 53 | Udt.TraceInfo trace = client.GetPerformanceInfo(); 54 | 55 | // Send the file 56 | client.SendFile(name); 57 | 58 | trace = client.GetPerformanceInfo(); 59 | 60 | PrintProps("Total", trace.Total); 61 | PrintProps("Local", trace.Local); 62 | PrintProps("Probe", trace.Probe); 63 | 64 | client.Close(); 65 | } 66 | } 67 | 68 | Console.ReadKey(true); 69 | return 0; 70 | } 71 | catch (Exception ex) 72 | { 73 | Console.Error.WriteLine("Error sending file: {0}", ex.Message); 74 | Console.ReadKey(true); 75 | return 2; 76 | } 77 | } 78 | 79 | static void PrintProps(string name, object obj) 80 | { 81 | Console.WriteLine("---- {0} ----", name); 82 | foreach (PropertyInfo prop in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) 83 | { 84 | Console.WriteLine("{0} = {1}", prop.Name, prop.GetValue(obj, null)); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /SendFile/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SendFile")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SendFile")] 13 | [assembly: AssemblyCopyright("Copyright © 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a4c9c55c-0fe5-4606-8b31-48fe7d1c9256")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | -------------------------------------------------------------------------------- /SendFile/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UdtProtocol-Test/Ack2PacketTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using Udt; 7 | 8 | namespace UdtProtocol_Test 9 | { 10 | /// 11 | /// Test fixture for . 12 | /// 13 | [TestFixture] 14 | public class Ack2PacketTest 15 | { 16 | [Test] 17 | public void Create_and_dispose() 18 | { 19 | Ack2Packet packet = new Ack2Packet(); 20 | 21 | Assert.AreEqual(0, packet.DestinationId); 22 | Assert.AreEqual(0, packet.SequenceNumber); 23 | Assert.IsFalse(packet.IsDisposed); 24 | Assert.IsTrue(packet.IsEditable); 25 | Assert.AreEqual(TimeSpan.Zero, packet.TimeStamp); 26 | 27 | packet.Dispose(); 28 | 29 | Assert.Throws(() => { var x = packet.DestinationId; }); 30 | Assert.Throws(() => { var x = packet.SequenceNumber; }); 31 | Assert.IsTrue(packet.IsDisposed); 32 | Assert.IsFalse(packet.IsEditable); 33 | Assert.Throws(() => { var x = packet.TimeStamp; }); 34 | } 35 | 36 | [Test] 37 | public void ErrorCode() 38 | { 39 | Ack2Packet packet = new Ack2Packet(); 40 | 41 | foreach (int value in new[] { 1, Int32.MaxValue, -1, Int32.MinValue, 0 }) 42 | { 43 | packet.SequenceNumber = value; 44 | Assert.AreEqual(value, packet.SequenceNumber); 45 | } 46 | 47 | packet.Dispose(); 48 | } 49 | 50 | [Test] 51 | public void Set_ErrorCode_after_disposed() 52 | { 53 | Ack2Packet packet = new Ack2Packet(); 54 | packet.Dispose(); 55 | 56 | Assert.Throws(() => packet.SequenceNumber = 1); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /UdtProtocol-Test/CongestionPacketTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using Udt; 7 | 8 | namespace UdtProtocol_Test 9 | { 10 | /// 11 | /// Test fixture for . 12 | /// 13 | [TestFixture] 14 | public class CongestionPacketTest 15 | { 16 | [Test] 17 | public void Create_and_dispose() 18 | { 19 | CongestionPacket packet = new CongestionPacket(); 20 | 21 | Assert.AreEqual(0, packet.DestinationId); 22 | Assert.IsFalse(packet.IsDisposed); 23 | Assert.IsTrue(packet.IsEditable); 24 | Assert.AreEqual(TimeSpan.Zero, packet.TimeStamp); 25 | 26 | packet.Dispose(); 27 | 28 | Assert.Throws(() => { var x = packet.DestinationId; }); 29 | Assert.IsTrue(packet.IsDisposed); 30 | Assert.IsFalse(packet.IsEditable); 31 | Assert.Throws(() => { var x = packet.TimeStamp; }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UdtProtocol-Test/ErrorPacketTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using Udt; 7 | 8 | namespace UdtProtocol_Test 9 | { 10 | /// 11 | /// Test fixture for . 12 | /// 13 | [TestFixture] 14 | public class ErrorPacketTest 15 | { 16 | [Test] 17 | public void Create_and_dispose() 18 | { 19 | ErrorPacket packet = new ErrorPacket(); 20 | 21 | Assert.AreEqual(0, packet.DestinationId); 22 | Assert.AreEqual(0, packet.ErrorCode); 23 | Assert.IsFalse(packet.IsDisposed); 24 | Assert.IsTrue(packet.IsEditable); 25 | Assert.AreEqual(TimeSpan.Zero, packet.TimeStamp); 26 | 27 | packet.Dispose(); 28 | 29 | Assert.Throws(() => { var x = packet.DestinationId; }); 30 | Assert.Throws(() => { var x = packet.ErrorCode; }); 31 | Assert.IsTrue(packet.IsDisposed); 32 | Assert.IsFalse(packet.IsEditable); 33 | Assert.Throws(() => { var x = packet.TimeStamp; }); 34 | } 35 | 36 | [Test] 37 | public void ErrorCode_constructor() 38 | { 39 | foreach (int value in new[] { 1, Int32.MaxValue, -1, Int32.MinValue, 0 }) 40 | { 41 | ErrorPacket packet = new ErrorPacket(value); 42 | Assert.AreEqual(value, packet.ErrorCode); 43 | packet.Dispose(); 44 | } 45 | } 46 | 47 | [Test] 48 | public void ErrorCode() 49 | { 50 | ErrorPacket packet = new ErrorPacket(); 51 | 52 | foreach (int value in new[] { 1, Int32.MaxValue, -1, Int32.MinValue, 0 }) 53 | { 54 | packet.ErrorCode = value; 55 | Assert.AreEqual(value, packet.ErrorCode); 56 | } 57 | 58 | packet.Dispose(); 59 | } 60 | 61 | [Test] 62 | public void Set_ErrorCode_after_disposed() 63 | { 64 | ErrorPacket packet = new ErrorPacket(); 65 | packet.Dispose(); 66 | 67 | Assert.Throws(() => packet.ErrorCode = 1); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /UdtProtocol-Test/KeepAlivePacketTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using Udt; 7 | 8 | namespace UdtProtocol_Test 9 | { 10 | /// 11 | /// Test fixture for . 12 | /// 13 | [TestFixture] 14 | public class KeepAlivePacketTest 15 | { 16 | [Test] 17 | public void Create_and_dispose() 18 | { 19 | KeepAlivePacket packet = new KeepAlivePacket(); 20 | 21 | Assert.AreEqual(0, packet.DestinationId); 22 | Assert.IsFalse(packet.IsDisposed); 23 | Assert.IsTrue(packet.IsEditable); 24 | Assert.AreEqual(TimeSpan.Zero, packet.TimeStamp); 25 | 26 | packet.Dispose(); 27 | 28 | Assert.Throws(() => { var x = packet.DestinationId; }); 29 | Assert.IsTrue(packet.IsDisposed); 30 | Assert.IsFalse(packet.IsEditable); 31 | Assert.Throws(() => { var x = packet.TimeStamp; }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UdtProtocol-Test/NetworkStreamTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using NUnit.Framework; 7 | using System.Net.Sockets; 8 | using System.IO; 9 | 10 | namespace UdtProtocol_Test 11 | { 12 | /// 13 | /// Test fixture for . 14 | /// 15 | [TestFixture] 16 | public class NetworkStreamTest 17 | { 18 | /// 19 | /// Test for , , 20 | /// and . 21 | /// 22 | [Test] 23 | public void CanRead_CanWrite_CanSeek() 24 | { 25 | Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); 26 | Udt.NetworkStream ns = new Udt.NetworkStream(socket, FileAccess.Read, false); 27 | Assert.IsTrue(ns.CanRead); 28 | Assert.IsFalse(ns.CanSeek); 29 | Assert.IsFalse(ns.CanWrite); 30 | 31 | ns = new Udt.NetworkStream(socket, FileAccess.Write, false); 32 | Assert.IsFalse(ns.CanRead); 33 | Assert.IsFalse(ns.CanSeek); 34 | Assert.IsTrue(ns.CanWrite); 35 | 36 | ns = new Udt.NetworkStream(socket, FileAccess.ReadWrite, false); 37 | Assert.IsTrue(ns.CanRead); 38 | Assert.IsFalse(ns.CanSeek); 39 | Assert.IsTrue(ns.CanWrite); 40 | 41 | ns.Dispose(); 42 | Assert.IsFalse(ns.CanRead); 43 | Assert.IsFalse(ns.CanSeek); 44 | Assert.IsFalse(ns.CanWrite); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /UdtProtocol-Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UdtProtocol-Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("UdtProtocol-Test")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fa7966bf-bbf6-4b53-b08d-ff8eeabb6ddd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.1.0.0")] 36 | [assembly: AssemblyFileVersion("0.1.0.0")] 37 | -------------------------------------------------------------------------------- /UdtProtocol-Test/ShutdownPacketTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using Udt; 7 | 8 | namespace UdtProtocol_Test 9 | { 10 | /// 11 | /// Test fixture for . 12 | /// 13 | [TestFixture] 14 | public class ShutdownPacketTest 15 | { 16 | [Test] 17 | public void Create_and_dispose() 18 | { 19 | ShutdownPacket packet = new ShutdownPacket(); 20 | 21 | Assert.AreEqual(0, packet.DestinationId); 22 | Assert.IsFalse(packet.IsDisposed); 23 | Assert.IsTrue(packet.IsEditable); 24 | Assert.AreEqual(TimeSpan.Zero, packet.TimeStamp); 25 | 26 | packet.Dispose(); 27 | 28 | Assert.Throws(() => { var x = packet.DestinationId; }); 29 | Assert.IsTrue(packet.IsDisposed); 30 | Assert.IsFalse(packet.IsEditable); 31 | Assert.Throws(() => { var x = packet.TimeStamp; }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UdtProtocol-Test/SocketPollerTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Net.Sockets; 6 | 7 | using NUnit.Framework; 8 | using System.Net; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace UdtProtocol_Test 13 | { 14 | [TestFixture] 15 | public class SocketPollerTest 16 | { 17 | [Test] 18 | public void Constructor() 19 | { 20 | Udt.SocketPoller poller = new Udt.SocketPoller(); 21 | CollectionAssert.IsEmpty(poller.ReadSockets); 22 | CollectionAssert.IsEmpty(poller.WriteSockets); 23 | poller.Dispose(); 24 | CollectionAssert.IsEmpty(poller.ReadSockets); 25 | CollectionAssert.IsEmpty(poller.WriteSockets); 26 | } 27 | 28 | [Test] 29 | public void Add_closed_socket() 30 | { 31 | using (Udt.SocketPoller poller = new Udt.SocketPoller()) 32 | { 33 | Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); 34 | socket.Dispose(); 35 | Assert.Throws(() => poller.AddSocket(socket)); 36 | } 37 | } 38 | 39 | [Test] 40 | public void Remove_closed_socket() 41 | { 42 | using (Udt.SocketPoller poller = new Udt.SocketPoller()) 43 | { 44 | Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); 45 | poller.AddSocket(socket); 46 | socket.Dispose(); 47 | poller.RemoveSocket(socket); 48 | } 49 | } 50 | 51 | [Test] 52 | public void Add_socket_to_disposed_poller() 53 | { 54 | Udt.SocketPoller poller = new Udt.SocketPoller(); 55 | poller.Dispose(); 56 | Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream); 57 | Assert.Throws(() => poller.AddSocket(socket)); 58 | socket.Dispose(); 59 | } 60 | 61 | [Test] 62 | public void Wait_with_no_sockets() 63 | { 64 | using (Udt.SocketPoller poller = new Udt.SocketPoller()) 65 | { 66 | Assert.Throws(() => poller.Wait()); 67 | } 68 | } 69 | 70 | [Test] 71 | public void Wait_when_disposed() 72 | { 73 | Udt.SocketPoller poller = new Udt.SocketPoller(); 74 | poller.Dispose(); 75 | Assert.Throws(() => poller.Wait()); 76 | } 77 | 78 | [Test] 79 | public void Wait_for_accept() 80 | { 81 | using (Udt.SocketPoller poller = new Udt.SocketPoller()) 82 | using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) 83 | { 84 | socket.Bind(IPAddress.Loopback, 0); 85 | socket.Listen(100); 86 | ManualResetEvent doneEvent = new ManualResetEvent(false); 87 | 88 | poller.AddSocket(socket); 89 | 90 | Task.Factory.StartNew(() => 91 | { 92 | using (Udt.Socket client = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) 93 | { 94 | client.Connect(IPAddress.Loopback, socket.LocalEndPoint.Port); 95 | doneEvent.WaitOne(1000); 96 | } 97 | }); 98 | 99 | Assert.IsTrue(poller.Wait(TimeSpan.FromSeconds(1))); 100 | CollectionAssert.AreEqual(new[] { socket }, poller.WriteSockets); 101 | CollectionAssert.AreEqual(new[] { socket }, poller.ReadSockets); 102 | 103 | Udt.Socket acceptedSocket = socket.Accept(); 104 | acceptedSocket.Dispose(); 105 | doneEvent.Set(); 106 | 107 | Assert.IsTrue(poller.Wait(TimeSpan.Zero)); 108 | CollectionAssert.AreEqual(new[] { socket }, poller.WriteSockets); 109 | CollectionAssert.IsEmpty(poller.ReadSockets); 110 | } 111 | } 112 | 113 | [Test] 114 | public void Remove_socket() 115 | { 116 | using (Udt.SocketPoller poller = new Udt.SocketPoller()) 117 | using (Udt.Socket socket = new Udt.Socket(AddressFamily.InterNetwork, SocketType.Stream)) 118 | { 119 | socket.Bind(IPAddress.Loopback, 0); 120 | socket.Listen(100); 121 | ManualResetEvent doneEvent = new ManualResetEvent(false); 122 | 123 | poller.AddSocket(socket); 124 | Assert.IsFalse(poller.Wait(TimeSpan.Zero)); 125 | poller.RemoveSocket(socket); 126 | 127 | Assert.Throws(() => poller.Wait(TimeSpan.Zero)); 128 | } 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /UdtProtocol-Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /UdtProtocol.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UdtProtocol", "UdtProtocol\UdtProtocol.vcxproj", "{CFA7453B-8B9B-4112-AF04-F72C3D431100}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C} = {D84D100A-7C21-4CCB-B16E-0FB37137C16C} 7 | EndProjectSection 8 | EndProject 9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendFile", "SendFile\SendFile.csproj", "{1C83D005-06B3-4FC5-8A26-032A0B328838}" 10 | EndProject 11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReceiveFile", "ReceiveFile\ReceiveFile.csproj", "{DAC18D1F-F3F2-454A-B386-365D9CF53470}" 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UdtProtocol-Test", "UdtProtocol-Test\UdtProtocol-Test.csproj", "{CF9918BA-989A-463B-BC64-02593041C9DD}" 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udt", "..\udt.sdk.4.11\udt4\win\udt.vcxproj", "{D84D100A-7C21-4CCB-B16E-0FB37137C16C}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Win32 = Debug|Win32 20 | Debug|x64 = Debug|x64 21 | Release - Signed|Win32 = Release - Signed|Win32 22 | Release - Signed|x64 = Release - Signed|x64 23 | Release|Win32 = Release|Win32 24 | Release|x64 = Release|x64 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Debug|Win32.Build.0 = Debug|Win32 29 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Debug|x64.ActiveCfg = Debug|x64 30 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Debug|x64.Build.0 = Debug|x64 31 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release - Signed|Win32.ActiveCfg = Release - Signed|Win32 32 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release - Signed|Win32.Build.0 = Release - Signed|Win32 33 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release - Signed|x64.ActiveCfg = Release - Signed|x64 34 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release - Signed|x64.Build.0 = Release - Signed|x64 35 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release|Win32.ActiveCfg = Release|Win32 36 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release|Win32.Build.0 = Release|Win32 37 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release|x64.ActiveCfg = Release|x64 38 | {CFA7453B-8B9B-4112-AF04-F72C3D431100}.Release|x64.Build.0 = Release|x64 39 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Debug|Win32.ActiveCfg = Debug|x86 40 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Debug|Win32.Build.0 = Debug|x86 41 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Debug|x64.ActiveCfg = Debug|x64 42 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Debug|x64.Build.0 = Debug|x64 43 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release - Signed|Win32.ActiveCfg = Release - Signed|Any CPU 44 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release - Signed|Win32.Build.0 = Release - Signed|x86 45 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release - Signed|x64.ActiveCfg = Release - Signed|x64 46 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release - Signed|x64.Build.0 = Release - Signed|x64 47 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release|Win32.ActiveCfg = Release|x86 48 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release|Win32.Build.0 = Release|x86 49 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release|x64.ActiveCfg = Release|x64 50 | {1C83D005-06B3-4FC5-8A26-032A0B328838}.Release|x64.Build.0 = Release|x64 51 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Debug|Win32.ActiveCfg = Debug|x86 52 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Debug|Win32.Build.0 = Debug|x86 53 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Debug|x64.ActiveCfg = Debug|x64 54 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Debug|x64.Build.0 = Debug|x64 55 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release - Signed|Win32.ActiveCfg = Release - Signed|Any CPU 56 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release - Signed|Win32.Build.0 = Release - Signed|x86 57 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release - Signed|x64.ActiveCfg = Release - Signed|x64 58 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release - Signed|x64.Build.0 = Release - Signed|x64 59 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release|Win32.ActiveCfg = Release|x86 60 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release|Win32.Build.0 = Release|x86 61 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release|x64.ActiveCfg = Release|x64 62 | {DAC18D1F-F3F2-454A-B386-365D9CF53470}.Release|x64.Build.0 = Release|x64 63 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Debug|Win32.ActiveCfg = Debug|x86 64 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Debug|Win32.Build.0 = Debug|x86 65 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Debug|x64.ActiveCfg = Debug|x64 66 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Debug|x64.Build.0 = Debug|x64 67 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release - Signed|Win32.ActiveCfg = Release - Signed|Any CPU 68 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release - Signed|Win32.Build.0 = Release - Signed|x86 69 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release - Signed|x64.ActiveCfg = Release - Signed|x64 70 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release - Signed|x64.Build.0 = Release - Signed|x64 71 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release|Win32.ActiveCfg = Release|x86 72 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release|Win32.Build.0 = Release|x86 73 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release|x64.ActiveCfg = Release|x64 74 | {CF9918BA-989A-463B-BC64-02593041C9DD}.Release|x64.Build.0 = Release|x64 75 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug|Win32.ActiveCfg = Debug|Win32 76 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug|Win32.Build.0 = Debug|Win32 77 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug|x64.ActiveCfg = Debug|x64 78 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug|x64.Build.0 = Debug|x64 79 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release - Signed|Win32.ActiveCfg = Release - Signed|Win32 80 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release - Signed|Win32.Build.0 = Release - Signed|Win32 81 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release - Signed|x64.ActiveCfg = Release - Signed|x64 82 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release - Signed|x64.Build.0 = Release - Signed|x64 83 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release|Win32.ActiveCfg = Release|Win32 84 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release|Win32.Build.0 = Release|Win32 85 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release|x64.ActiveCfg = Release|x64 86 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release|x64.Build.0 = Release|x64 87 | EndGlobalSection 88 | GlobalSection(SolutionProperties) = preSolution 89 | HideSolutionNode = FALSE 90 | EndGlobalSection 91 | EndGlobal 92 | -------------------------------------------------------------------------------- /UdtProtocol/Ack2Packet.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "Ack2Packet.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | Ack2Packet::Ack2Packet(const CPacket* packet) 42 | : ControlPacket(packet) 43 | { 44 | } 45 | 46 | Ack2Packet::Ack2Packet(void) 47 | { 48 | int seqNo = 0; 49 | _packet->pack(TypeCode, &seqNo); 50 | } 51 | 52 | int Ack2Packet::SequenceNumber::get(void) 53 | { 54 | AssertNotDisposed(); 55 | return _packet->m_iMsgNo; 56 | } 57 | 58 | void Ack2Packet::SequenceNumber::set(int value) 59 | { 60 | AssertIsMutable(); 61 | _packet->m_iMsgNo = value; 62 | } 63 | -------------------------------------------------------------------------------- /UdtProtocol/Ack2Packet.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ControlPacket.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol acknowledgement of acknowledgement (ACK-2) control packet. 43 | /// 44 | public ref class Ack2Packet : public ControlPacket 45 | { 46 | internal: 47 | Ack2Packet(const CPacket* packet); 48 | 49 | literal int TypeCode = 6; 50 | 51 | public: 52 | 53 | Ack2Packet(void); 54 | 55 | /// 56 | /// Acknowledgement (ACK) packet sequence number. Default value is 0. 57 | /// 58 | /// If attempting to set the value and is false. 59 | property int SequenceNumber { 60 | int get(void); 61 | void set(int value); 62 | } 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /UdtProtocol/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "stdafx.h" 34 | 35 | using namespace System; 36 | using namespace System::Reflection; 37 | using namespace System::Runtime::CompilerServices; 38 | using namespace System::Runtime::InteropServices; 39 | using namespace System::Security::Permissions; 40 | 41 | // 42 | // General Information about an assembly is controlled through the following 43 | // set of attributes. Change these attribute values to modify the information 44 | // associated with an assembly. 45 | // 46 | [assembly:AssemblyTitleAttribute("Udt")]; 47 | [assembly:AssemblyDescriptionAttribute("UDT.Net wrapper library")]; 48 | [assembly:AssemblyConfigurationAttribute("")]; 49 | [assembly:AssemblyCompanyAttribute("")]; 50 | [assembly:AssemblyProductAttribute("Udt")]; 51 | [assembly:AssemblyCopyrightAttribute("Copyright (c) 2011")]; 52 | [assembly:AssemblyTrademarkAttribute("")]; 53 | [assembly:AssemblyCultureAttribute("")]; 54 | 55 | // 56 | // Version information for an assembly consists of the following four values: 57 | // 58 | // Major Version 59 | // Minor Version 60 | // Build Number 61 | // Revision 62 | // 63 | // You can specify all the value or you can default the Revision and Build Numbers 64 | // by using the '*' as shown below: 65 | 66 | [assembly:AssemblyVersionAttribute("0.10.0.0")]; 67 | 68 | [assembly:ComVisible(false)]; 69 | 70 | [assembly:CLSCompliantAttribute(true)]; 71 | 72 | [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; 73 | -------------------------------------------------------------------------------- /UdtProtocol/CCCWrapper.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "CCCWrapper.h" 35 | #include "Packet.h" 36 | 37 | using namespace Udt; 38 | using namespace System; 39 | 40 | CCCWrapper::CCCWrapper(Udt::CongestionControl^ wrapped) 41 | : _wrapped(nullptr) 42 | { 43 | if (wrapped->_cccWrapper != NULL) throw gcnew InvalidOperationException("Congestion control object already in use. Can not reuse congestion control objects."); 44 | if (wrapped->IsDisposed) throw gcnew InvalidOperationException("Invalid congestion control object. Object is disposed."); 45 | 46 | _wrapped = wrapped; 47 | _wrapped->_cccWrapper = this; 48 | } 49 | 50 | CCCWrapper::~CCCWrapper(void) 51 | { 52 | } 53 | 54 | void CCCWrapper::onPktReceived(const CPacket* packet) 55 | { 56 | Packet^ managedPacket = Packet::Wrap(packet); 57 | 58 | __try 59 | { 60 | _wrapped->OnPacketReceived(managedPacket); 61 | } 62 | __finally 63 | { 64 | delete managedPacket; 65 | } 66 | } 67 | 68 | void CCCWrapper::onPktSent(const CPacket* packet) 69 | { 70 | Packet^ managedPacket = Packet::Wrap(packet); 71 | 72 | __try 73 | { 74 | _wrapped->OnPacketSent(managedPacket); 75 | } 76 | __finally 77 | { 78 | delete managedPacket; 79 | } 80 | } 81 | 82 | void CCCWrapper::processCustomMsg(const CPacket* packet) 83 | { 84 | Packet^ managedPacket = Packet::Wrap(packet); 85 | 86 | __try 87 | { 88 | _wrapped->ProcessCustomMessage(managedPacket); 89 | } 90 | __finally 91 | { 92 | delete managedPacket; 93 | } 94 | } 95 | 96 | void CCCWrapper::onLoss(const int32_t* losslist, int size) 97 | { 98 | NativeIntArray^ list = gcnew NativeIntArray(losslist, size); 99 | 100 | __try 101 | { 102 | _wrapped->OnLoss(list); 103 | } 104 | __finally 105 | { 106 | delete list; 107 | } 108 | } 109 | 110 | void CCCWrapper::setACKTimer(TimeSpan value) 111 | { 112 | if (value.CompareTo(TimeSpan::Zero) < 0) 113 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 114 | 115 | int ms = (int)value.TotalMilliseconds; 116 | this->CCC::setACKTimer(ms); 117 | } 118 | 119 | void CCCWrapper::setACKInterval(int packets) 120 | { 121 | if (packets < 0) 122 | throw gcnew System::ArgumentOutOfRangeException("packets", packets, "Value must be greater than or equal to 0."); 123 | 124 | this->CCC::setACKInterval(packets); 125 | } 126 | 127 | void CCCWrapper::setRTO(TimeSpan value) 128 | { 129 | if (value.CompareTo(TimeSpan::Zero) < 0) 130 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 131 | 132 | int us = (int)(value.Ticks / 10); 133 | this->CCC::setRTO(us); 134 | } 135 | 136 | TraceInfo^ CCCWrapper::getPerfInfo(void) 137 | { 138 | const UDT::TRACEINFO* trace_info = this->CCC::getPerfInfo(); 139 | return gcnew TraceInfo(*trace_info); 140 | } 141 | 142 | void CCCWrapper::setPacketSendPeriod(System::TimeSpan value) 143 | { 144 | if (value.CompareTo(TimeSpan::Zero) < 0) 145 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 146 | 147 | m_dPktSndPeriod = value.Ticks / 10.0; 148 | } 149 | 150 | System::TimeSpan CCCWrapper::getPacketSendPeriod(void) const 151 | { 152 | return System::TimeSpan((__int64)(m_dPktSndPeriod * 10)); 153 | } 154 | 155 | void CCCWrapper::setWindowSize(int value) 156 | { 157 | if (value < 0) 158 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 159 | 160 | m_dCWndSize = value; 161 | } 162 | 163 | int CCCWrapper::getWindowSize() const 164 | { 165 | return (int)m_dCWndSize; 166 | } 167 | 168 | void CCCWrapper::setRoundTripTime(System::TimeSpan value) 169 | { 170 | if (value.CompareTo(TimeSpan::Zero) < 0) 171 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 172 | 173 | m_iRTT = (int)(value.Ticks / 10); 174 | } 175 | 176 | System::TimeSpan CCCWrapper::getRoundTripTime(void) const 177 | { 178 | return System::TimeSpan(m_iRTT * 10); 179 | } 180 | 181 | void CCCWrapper::setMaxPacketSize(int value) 182 | { 183 | if (value < 0) 184 | throw gcnew System::ArgumentOutOfRangeException("value", value, "Value must be greater than or equal to 0."); 185 | 186 | m_iMSS = value; 187 | } 188 | 189 | int CCCWrapper::getMaxPacketSize() const 190 | { 191 | return m_iMSS; 192 | } 193 | -------------------------------------------------------------------------------- /UdtProtocol/CCCWrapper.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "CongestionControl.h" 36 | #include "NativeIntArray.h" 37 | #include "TraceInfo.h" 38 | #include 39 | #include 40 | 41 | namespace Udt 42 | { 43 | ref class Packet; 44 | 45 | class CCCWrapper : public CCC 46 | { 47 | private: 48 | gcroot _wrapped; 49 | 50 | public: 51 | 52 | CCCWrapper(CongestionControl^ wrapped); 53 | virtual ~CCCWrapper(void); 54 | 55 | virtual void init() { _wrapped->Initialize(); } 56 | virtual void close() { _wrapped->Close(); } 57 | virtual void onTimeout() { _wrapped->OnTimeout(); } 58 | virtual void onACK(int32_t ack) { _wrapped->OnAck(ack); } 59 | virtual void onLoss(const int32_t* losslist, int size); 60 | virtual void onPktReceived(const CPacket* packet); 61 | virtual void onPktSent(const CPacket*); 62 | virtual void processCustomMsg(const CPacket*); 63 | 64 | void setACKTimer(System::TimeSpan value); 65 | void setACKInterval(int packets); 66 | void setRTO(System::TimeSpan value); 67 | TraceInfo^ getPerfInfo(void); 68 | 69 | void setPacketSendPeriod(System::TimeSpan value); 70 | System::TimeSpan getPacketSendPeriod(void) const; 71 | 72 | void setWindowSize(int value); 73 | int getWindowSize() const; 74 | 75 | void setRoundTripTime(System::TimeSpan value); 76 | System::TimeSpan getRoundTripTime(void) const; 77 | 78 | void setMaxPacketSize(int value); 79 | int getMaxPacketSize() const; 80 | }; 81 | } 82 | -------------------------------------------------------------------------------- /UdtProtocol/CCCWrapperFactory.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | 35 | #include "ICongestionControlFactory.h" 36 | 37 | #include "CCCWrapperFactory.h" 38 | #include "CCCWrapper.h" 39 | 40 | using namespace Udt; 41 | 42 | CCCWrapperFactory::CCCWrapperFactory(ICongestionControlFactory^ managedFactory) 43 | : _managedFactory(managedFactory) 44 | { 45 | } 46 | 47 | CCCWrapperFactory::~CCCWrapperFactory(void) 48 | { 49 | } 50 | 51 | CCC* CCCWrapperFactory::create() 52 | { 53 | return new CCCWrapper(_managedFactory->CreateCongestionControl()); 54 | } 55 | 56 | CCCVirtualFactory* CCCWrapperFactory::clone() 57 | { 58 | return new CCCWrapperFactory(_managedFactory); 59 | } 60 | -------------------------------------------------------------------------------- /UdtProtocol/CCCWrapperFactory.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | 38 | namespace Udt 39 | { 40 | interface class ICongestionControlFactory; 41 | 42 | class CCCWrapperFactory : public CCCVirtualFactory 43 | { 44 | private: 45 | gcroot _managedFactory; 46 | 47 | public: 48 | 49 | CCCWrapperFactory(ICongestionControlFactory^ managedFactory); 50 | virtual ~CCCWrapperFactory(void); 51 | 52 | virtual CCC* create(); 53 | virtual CCCVirtualFactory* clone(); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionControl.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "CongestionControl.h" 35 | #include "Packet.h" 36 | 37 | #include "CCCWrapper.h" 38 | 39 | using namespace Udt; 40 | using namespace System; 41 | 42 | CongestionControl::CongestionControl(void) 43 | : _cccWrapper(NULL), _isDisposed(false) 44 | { 45 | } 46 | 47 | void CongestionControl::AssertNotDisposed() 48 | { 49 | if (this->IsDisposed) throw gcnew ObjectDisposedException(this->ToString()); 50 | } 51 | 52 | void CongestionControl::SetAckTimer(System::TimeSpan value) 53 | { 54 | AssertNotDisposed(); 55 | _cccWrapper->setACKTimer(value); 56 | } 57 | 58 | void CongestionControl::SetAckInterval(int value) 59 | { 60 | AssertNotDisposed(); 61 | _cccWrapper->setACKInterval(value); 62 | } 63 | 64 | void CongestionControl::SetReadTimeout(System::TimeSpan value) 65 | { 66 | AssertNotDisposed(); 67 | _cccWrapper->setRTO(value); 68 | } 69 | 70 | TraceInfo^ CongestionControl::PerformanceInfo::get(void) 71 | { 72 | AssertNotDisposed(); 73 | return _cccWrapper->getPerfInfo(); 74 | } 75 | 76 | void CongestionControl::PacketSendPeriod::set(System::TimeSpan value) 77 | { 78 | AssertNotDisposed(); 79 | _cccWrapper->setPacketSendPeriod(value); 80 | } 81 | 82 | System::TimeSpan CongestionControl::PacketSendPeriod::get(void) 83 | { 84 | AssertNotDisposed(); 85 | return _cccWrapper->getPacketSendPeriod(); 86 | } 87 | 88 | void CongestionControl::WindowSize::set(int value) 89 | { 90 | AssertNotDisposed(); 91 | _cccWrapper->setWindowSize(value); 92 | } 93 | 94 | int CongestionControl::WindowSize::get(void) 95 | { 96 | AssertNotDisposed(); 97 | return _cccWrapper->getWindowSize(); 98 | } 99 | 100 | void CongestionControl::MaxPacketSize::set(int value) 101 | { 102 | AssertNotDisposed(); 103 | _cccWrapper->setMaxPacketSize(value); 104 | } 105 | 106 | int CongestionControl::MaxPacketSize::get(void) 107 | { 108 | AssertNotDisposed(); 109 | return _cccWrapper->getMaxPacketSize(); 110 | } 111 | 112 | void CongestionControl::RoundtripTime::set(System::TimeSpan value) 113 | { 114 | AssertNotDisposed(); 115 | _cccWrapper->setRoundTripTime(value); 116 | } 117 | 118 | System::TimeSpan CongestionControl::RoundtripTime::get(void) 119 | { 120 | AssertNotDisposed(); 121 | return _cccWrapper->getRoundTripTime(); 122 | } 123 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionControl.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "TraceInfo.h" 36 | 37 | namespace Udt 38 | { 39 | ref class Packet; 40 | class CCCWrapper; 41 | 42 | public ref class CongestionControl abstract 43 | { 44 | internal: 45 | CCCWrapper* _cccWrapper; 46 | bool _isDisposed; 47 | 48 | protected: 49 | CongestionControl(void); 50 | 51 | public: 52 | virtual void Initialize() { } 53 | virtual void Close() { } 54 | 55 | property bool IsDisposed { bool get(void) { return _isDisposed; } } 56 | 57 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 58 | "Microsoft.Naming", 59 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 60 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 61 | virtual void OnAck(int ack) { } 62 | virtual void OnLoss(System::Collections::Generic::IList^ lossList) { } 63 | virtual void OnTimeout() { } 64 | virtual void OnPacketSent(Packet^ packet) { } 65 | virtual void OnPacketReceived(Packet^ packet) { } 66 | virtual void ProcessCustomMessage(Packet^ packet) { } 67 | 68 | protected: 69 | 70 | void AssertNotDisposed(); 71 | 72 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 73 | "Microsoft.Naming", 74 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 75 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 76 | void SetAckTimer(System::TimeSpan value); 77 | 78 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 79 | "Microsoft.Naming", 80 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 81 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 82 | void SetAckInterval(int value); 83 | 84 | void SetReadTimeout(System::TimeSpan value); 85 | 86 | property TraceInfo^ PerformanceInfo { TraceInfo^ get(void); } 87 | 88 | property System::TimeSpan PacketSendPeriod 89 | { 90 | System::TimeSpan get(void); 91 | void set(System::TimeSpan value); 92 | } 93 | 94 | property int WindowSize 95 | { 96 | int get(void); 97 | void set(int value); 98 | } 99 | 100 | property int MaxPacketSize 101 | { 102 | int get(void); 103 | void set(int value); 104 | } 105 | 106 | property System::TimeSpan RoundtripTime 107 | { 108 | System::TimeSpan get(void); 109 | void set(System::TimeSpan value); 110 | } 111 | }; 112 | } 113 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionControlFactory.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "CongestionControlFactory.h" 35 | 36 | using namespace Udt; 37 | using namespace System; 38 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionControlFactory.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ICongestionControlFactory.h" 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Factory that creates instances for a 41 | /// . 42 | /// 43 | /// 44 | /// must return a new instance every 45 | /// time it is invoked. If the same instance returns the same instance more 46 | /// than once, the result is undefined behavior. 47 | /// 48 | public ref class CongestionControlFactory : public ICongestionControlFactory 49 | { 50 | private: 51 | 52 | initonly System::Func^ _callback; 53 | 54 | public: 55 | 56 | /// 57 | /// Initialize a new instance that creates instances of 58 | /// using the provided callback. 59 | /// 60 | /// Function to invoke to create new instances of 61 | /// If is null. 62 | CongestionControlFactory(System::Func^ callback) 63 | : _callback(callback) 64 | { 65 | if (callback == nullptr) throw gcnew System::ArgumentNullException("callback"); 66 | } 67 | 68 | /// 69 | /// Create a new instance. 70 | /// 71 | /// 72 | /// This method must return a new instance every time it is invoked. 73 | /// If the same instance returns the same instance more than once, 74 | /// the result is undefined behavior. 75 | /// 76 | /// New congestion control object. 77 | virtual CongestionControl^ CreateCongestionControl(void) 78 | { 79 | return _callback(); 80 | } 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionPacket.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "CongestionPacket.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | CongestionPacket::CongestionPacket(const CPacket* packet) 42 | : ControlPacket(packet) 43 | { 44 | } 45 | 46 | CongestionPacket::CongestionPacket(void) 47 | { 48 | _packet->pack(TypeCode, NULL, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /UdtProtocol/CongestionPacket.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ControlPacket.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol congestion/delay warning control packet. 43 | /// 44 | public ref class CongestionPacket : public ControlPacket 45 | { 46 | internal: 47 | CongestionPacket(const CPacket* packet); 48 | 49 | literal int TypeCode = 4; 50 | 51 | public: 52 | 53 | CongestionPacket(void); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /UdtProtocol/ControlPacket.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "ControlPacket.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | ControlPacket::ControlPacket(void) 42 | { 43 | } 44 | 45 | ControlPacket::ControlPacket(const CPacket* packet) 46 | : Packet(packet) 47 | { 48 | } 49 | 50 | ControlPacket::~ControlPacket(void) 51 | { 52 | } 53 | -------------------------------------------------------------------------------- /UdtProtocol/ControlPacket.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "Packet.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol control packet. 43 | /// 44 | public ref class ControlPacket : public Packet 45 | { 46 | internal: 47 | ControlPacket(void); 48 | ControlPacket(const CPacket* packet); 49 | 50 | public: 51 | virtual ~ControlPacket(void); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /UdtProtocol/ErrorPacket.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "ErrorPacket.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | ErrorPacket::ErrorPacket(const CPacket* packet) 42 | : ControlPacket(packet) 43 | { 44 | } 45 | 46 | ErrorPacket::ErrorPacket(void) 47 | { 48 | int errorCode = 0; 49 | _packet->pack(TypeCode, &errorCode, NULL); 50 | } 51 | 52 | ErrorPacket::ErrorPacket(int errorCode) 53 | { 54 | _packet->pack(TypeCode, &errorCode, NULL); 55 | } 56 | 57 | int ErrorPacket::ErrorCode::get(void) 58 | { 59 | AssertNotDisposed(); 60 | return _packet->m_iMsgNo; 61 | } 62 | 63 | void ErrorPacket::ErrorCode::set(int value) 64 | { 65 | AssertIsMutable(); 66 | _packet->m_iMsgNo = value; 67 | } 68 | -------------------------------------------------------------------------------- /UdtProtocol/ErrorPacket.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ControlPacket.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol error signal control packet. 43 | /// 44 | public ref class ErrorPacket : public ControlPacket 45 | { 46 | internal: 47 | ErrorPacket(const CPacket* packet); 48 | 49 | literal int TypeCode = 8; 50 | 51 | public: 52 | 53 | ErrorPacket(void); 54 | ErrorPacket(int errorCode); 55 | 56 | /// 57 | /// Get or set the error code. Default value is 0. 58 | /// 59 | /// If attempting to set the value and is false. 60 | property int ErrorCode { 61 | int get(void); 62 | void set(int value); 63 | } 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /UdtProtocol/ICongestionControlFactory.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "ICongestionControlFactory.h" 35 | -------------------------------------------------------------------------------- /UdtProtocol/ICongestionControlFactory.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | namespace Udt 36 | { 37 | ref class CongestionControl; 38 | ref class Socket; 39 | 40 | /// 41 | /// Factory that creates instances for a 42 | /// . 43 | /// 44 | /// 45 | /// must return a new instance every 46 | /// time it is invoked. If the same instance returns the same instance more 47 | /// than once, the result is undefined behavior. 48 | /// 49 | public interface class ICongestionControlFactory 50 | { 51 | /// 52 | /// Create a new instance. 53 | /// 54 | /// 55 | /// This method must return a new instance every time it is invoked. 56 | /// If the same instance returns the same instance more than once, 57 | /// the result is undefined behavior. 58 | /// 59 | /// New congestion control object. 60 | CongestionControl^ CreateCongestionControl(); 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /UdtProtocol/KeepAlivePacket.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "KeepAlivePacket.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | KeepAlivePacket::KeepAlivePacket(const CPacket* packet) 42 | : ControlPacket(packet) 43 | { 44 | } 45 | 46 | KeepAlivePacket::KeepAlivePacket(void) 47 | { 48 | _packet->pack(TypeCode, NULL, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /UdtProtocol/KeepAlivePacket.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ControlPacket.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol keep-alive control packet. 43 | /// 44 | public ref class KeepAlivePacket : public ControlPacket 45 | { 46 | internal: 47 | KeepAlivePacket(const CPacket* packet); 48 | 49 | literal int TypeCode = 1; 50 | 51 | public: 52 | 53 | KeepAlivePacket(void); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /UdtProtocol/LocalTraceInfo.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "LocalTraceInfo.h" 35 | 36 | using namespace Udt; 37 | using namespace System; 38 | 39 | LocalTraceInfo::LocalTraceInfo(const UDT::TRACEINFO& copy) 40 | { 41 | this->PacketsSent = copy.pktSent; 42 | this->PacketsReceived = copy.pktRecv; 43 | this->SendPacketsLost = copy.pktSndLoss; 44 | this->ReceivePacketsLost = copy.pktRcvLoss; 45 | this->PacketsRetransmitted = copy.pktRetrans; 46 | this->AcksSent = copy.pktSentACK; 47 | this->AcksReceived = copy.pktRecvACK; 48 | this->NaksSent = copy.pktSentNAK; 49 | this->NaksReceived = copy.pktRecvNAK; 50 | this->SendMbps = copy.mbpsSendRate; 51 | this->ReceiveMbps = copy.mbpsRecvRate; 52 | this->SendDuration = FromMicroseconds(copy.usSndDuration); 53 | } 54 | 55 | LocalTraceInfo::LocalTraceInfo(void) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /UdtProtocol/LocalTraceInfo.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Performance trace information local since the last time they were recorded. 41 | /// 42 | public ref class LocalTraceInfo 43 | { 44 | internal: 45 | LocalTraceInfo(const UDT::TRACEINFO& copy); 46 | 47 | public: 48 | /// 49 | /// Initialize a new instance with default values. 50 | /// 51 | LocalTraceInfo(void); 52 | 53 | /// 54 | /// Number of sent packets, including retransmissions. 55 | /// 56 | property __int64 PacketsSent; 57 | 58 | /// 59 | /// Number of received packets. 60 | /// 61 | property __int64 PacketsReceived; 62 | 63 | /// 64 | /// Number of lost packets, measured in the sending side. 65 | /// 66 | property int SendPacketsLost; 67 | 68 | /// 69 | /// Number of lost packets, measured in the receiving side. 70 | /// 71 | property int ReceivePacketsLost; 72 | 73 | /// 74 | /// Number of retransmitted packets, measured in the sending side. 75 | /// 76 | property int PacketsRetransmitted; 77 | 78 | /// 79 | /// Number of sent ACK packets. 80 | /// 81 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 82 | "Microsoft.Naming", 83 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 84 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 85 | property int AcksSent; 86 | 87 | /// 88 | /// Number of received ACK packets. 89 | /// 90 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 91 | "Microsoft.Naming", 92 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 93 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 94 | property int AcksReceived; 95 | 96 | /// 97 | /// Number of sent NAK packets. 98 | /// 99 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 100 | "Microsoft.Naming", 101 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 102 | Justification = "NAK is the accepted abbreviation for negative acknowledgement in this context.")] 103 | property int NaksSent; 104 | 105 | /// 106 | /// Number of received NAK packets. 107 | /// 108 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 109 | "Microsoft.Naming", 110 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 111 | Justification = "NAK is the accepted abbreviation for negative acknowledgement in this context.")] 112 | property int NaksReceived; 113 | 114 | /// 115 | /// Sending rate in Mbps. 116 | /// 117 | property double SendMbps; 118 | 119 | /// 120 | /// Receiving rate in Mbps. 121 | /// 122 | property double ReceiveMbps; 123 | 124 | /// 125 | /// Busy sending time (i.e., idle time exclusive). 126 | /// 127 | property System::TimeSpan SendDuration; 128 | }; 129 | } 130 | -------------------------------------------------------------------------------- /UdtProtocol/Message.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "Message.h" 35 | 36 | using namespace Udt; 37 | 38 | Message::Message(cli::array^ array) 39 | { 40 | _buffer = System::ArraySegment(array); 41 | _timeToLive = Message::Infinite; 42 | } 43 | 44 | Message::Message(cli::array^ array, int offset, int count) 45 | { 46 | _buffer = System::ArraySegment(array, offset, count); 47 | _timeToLive = Message::Infinite; 48 | } 49 | 50 | Message::Message(System::ArraySegment buffer) 51 | { 52 | if (buffer.Array == nullptr) 53 | throw gcnew System::ArgumentException("Array can not be a null reference.", "buffer"); 54 | 55 | _buffer = buffer; 56 | _timeToLive = Message::Infinite; 57 | } 58 | -------------------------------------------------------------------------------- /UdtProtocol/Message.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | namespace Udt 36 | { 37 | /// 38 | /// Message sent over a UDT socket. 39 | /// 40 | public ref class Message 41 | { 42 | public: 43 | 44 | /// 45 | /// Infinite . 46 | /// 47 | static initonly System::TimeSpan Infinite = System::TimeSpan(0, 0, 0, 0, -1); 48 | 49 | /// 50 | /// Maximum value for . 51 | /// 52 | static initonly System::TimeSpan Max = System::TimeSpan(0, 0, 0, 0, System::Int32::MaxValue); 53 | 54 | private: 55 | System::ArraySegment _buffer; 56 | System::TimeSpan _timeToLive; 57 | 58 | public: 59 | 60 | /// 61 | /// Initialize a new instance. 62 | /// 63 | /// Array that contains the message bytes. 64 | /// If is a null reference. 65 | Message(cli::array^ array); 66 | 67 | /// 68 | /// Initialize a new instance. 69 | /// 70 | /// Array that contains the message bytes. 71 | /// Offset into that the message starts. 72 | /// Number of bytes from to include in the message. 73 | /// 74 | /// If is a null reference. 75 | /// 76 | /// 77 | /// If is negative. 78 | /// 79 | /// 80 | /// If and do not 81 | /// specify a valid range in . 82 | /// 83 | Message(cli::array^ array, int offset, int count); 84 | 85 | /// 86 | /// Initialize a new instance. 87 | /// 88 | /// Array segment that contains the message bytes. 89 | /// 90 | /// If the array in is a null reference. 91 | /// 92 | Message(System::ArraySegment buffer); 93 | 94 | /// 95 | /// Gets the message content. 96 | /// 97 | property System::ArraySegment Buffer 98 | { 99 | System::ArraySegment get(void) { return _buffer; } 100 | } 101 | 102 | /// 103 | /// True if the message should be delivered in order. 104 | /// Default value is false. 105 | /// 106 | property bool InOrder; 107 | 108 | /// 109 | /// The time-to-live of the message. 110 | /// Default value is . 111 | /// 112 | /// 113 | /// If is not and is less 114 | /// than or greater than 115 | /// . 116 | /// 117 | property System::TimeSpan TimeToLive 118 | { 119 | System::TimeSpan get(void) { return _timeToLive; } 120 | 121 | void set(System::TimeSpan value) 122 | { 123 | if (value != Message::Infinite && (value.CompareTo(System::TimeSpan::Zero) < 0 || value.CompareTo(Message::Max) > 0)) 124 | throw gcnew System::ArgumentOutOfRangeException("value", value, System::String::Concat("Value must be ", Infinite, " or between ", System::TimeSpan::Zero, " and ", Max, ".")); 125 | 126 | _timeToLive = value; 127 | } 128 | } 129 | }; 130 | } 131 | -------------------------------------------------------------------------------- /UdtProtocol/MessageBoundary.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | namespace Udt 36 | { 37 | public enum class MessageBoundary : char 38 | { 39 | None = 0, 40 | Last = 1, 41 | First = 2, 42 | Solo = 3, 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /UdtProtocol/NativeIntArray.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "NativeIntArray.h" 35 | -------------------------------------------------------------------------------- /UdtProtocol/NativeIntArray.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | namespace Udt 36 | { 37 | ref class NativeIntArray : public System::Collections::Generic::IList 38 | { 39 | private: 40 | const int* _data; 41 | int _length; 42 | 43 | void AssertIsValid() 44 | { 45 | if (_data == NULL) 46 | throw gcnew System::InvalidOperationException("Internal native array is no longer valid."); 47 | } 48 | 49 | internal: 50 | NativeIntArray(const int* data, int length) 51 | { 52 | _data = data; 53 | _length = length; 54 | } 55 | 56 | ~NativeIntArray(void) 57 | { 58 | _data = NULL; 59 | } 60 | 61 | public: 62 | 63 | virtual property int default[int] 64 | { 65 | int get(int index) 66 | { 67 | AssertIsValid(); 68 | 69 | if (index < 0 || index > _length) 70 | throw gcnew System::ArgumentOutOfRangeException("index", index, "Value must be greater than or equal to 0 and less than the length of the list."); 71 | 72 | return _data[index]; 73 | } 74 | 75 | void set(int index, int value) 76 | { 77 | throw gcnew System::NotSupportedException("Collection is read-only."); 78 | } 79 | } 80 | 81 | virtual void Add(int item) = System::Collections::Generic::ICollection::Add 82 | { 83 | throw gcnew System::NotSupportedException("Collection is read-only."); 84 | } 85 | 86 | virtual void Insert(int index, int item) = System::Collections::Generic::IList::Insert 87 | { 88 | throw gcnew System::NotSupportedException("Collection is read-only."); 89 | } 90 | 91 | virtual void RemoveAt(int index) = System::Collections::Generic::IList::RemoveAt 92 | { 93 | throw gcnew System::NotSupportedException("Collection is read-only."); 94 | } 95 | 96 | virtual bool Remove(int item) = System::Collections::Generic::ICollection::Remove 97 | { 98 | throw gcnew System::NotSupportedException("Collection is read-only."); 99 | } 100 | 101 | virtual void Clear() = System::Collections::Generic::ICollection::Clear 102 | { 103 | throw gcnew System::NotSupportedException("Collection is read-only."); 104 | } 105 | 106 | virtual bool Contains(int item) 107 | { 108 | return IndexOf(item) >= 0; 109 | } 110 | 111 | virtual int IndexOf(int item) 112 | { 113 | AssertIsValid(); 114 | 115 | int itemIndex = -1; 116 | 117 | for (int index = 0; index < _length; ++index) 118 | { 119 | if (_data[index] == item) 120 | { 121 | itemIndex = index; 122 | break; 123 | } 124 | } 125 | 126 | return itemIndex; 127 | } 128 | 129 | virtual property int Count 130 | { 131 | int get(void) { return _length; } 132 | } 133 | 134 | virtual property bool IsReadOnly 135 | { 136 | bool get(void) = System::Collections::Generic::IList::IsReadOnly::get 137 | { return true; } 138 | } 139 | 140 | virtual void CopyTo(cli::array^ array, int arrayIndex) = System::Collections::Generic::ICollection::CopyTo 141 | { 142 | AssertIsValid(); 143 | 144 | if (array == nullptr) 145 | throw gcnew System::ArgumentNullException("array"); 146 | 147 | if (arrayIndex < 0) 148 | throw gcnew System::ArgumentOutOfRangeException("arrayIndex", arrayIndex, "Value must be greater than or equal to 0."); 149 | 150 | if (Count > (array->Length - arrayIndex)) 151 | throw gcnew System::ArgumentException("Not enough space in target array.", "array"); 152 | 153 | for (int index = 0; index < _length; ++index) 154 | { 155 | array->SetValue(_data[index], index + arrayIndex); 156 | arrayIndex += 1; 157 | } 158 | } 159 | 160 | virtual System::Collections::Generic::IEnumerator^ GetEnumerator() 161 | { 162 | AssertIsValid(); 163 | return gcnew Enumerator(this); 164 | } 165 | 166 | virtual System::Collections::IEnumerator^ EnumerableGetEnumerator() = System::Collections::IEnumerable::GetEnumerator 167 | { 168 | return GetEnumerator(); 169 | } 170 | 171 | private: 172 | 173 | ref class Enumerator : System::Collections::Generic::IEnumerator 174 | { 175 | private: 176 | NativeIntArray^ _a; 177 | int _index; 178 | 179 | public: 180 | Enumerator(NativeIntArray^ a) {_a = a; _index = -1;} 181 | ~Enumerator(void) {} 182 | 183 | virtual property int Current 184 | { 185 | int get(void) 186 | { 187 | if (_index < 0 || _index > _a->_length) 188 | throw gcnew System::InvalidOperationException(); 189 | 190 | _a->AssertIsValid(); 191 | return _a->_data[_index]; 192 | } 193 | } 194 | 195 | virtual property System::Object^ CurrentObject 196 | { 197 | System::Object^ get(void) = System::Collections::IEnumerator::Current::get 198 | { 199 | return Current; 200 | } 201 | } 202 | 203 | virtual bool MoveNext() 204 | { 205 | bool moved = false; 206 | 207 | if (_index < _a->_length) 208 | { 209 | _index += 1; 210 | moved = true; 211 | } 212 | 213 | return moved; 214 | } 215 | 216 | virtual void Reset() 217 | { 218 | throw gcnew System::NotSupportedException("Reset not supported."); 219 | } 220 | }; 221 | }; 222 | } 223 | -------------------------------------------------------------------------------- /UdtProtocol/NetworkStream.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | 35 | #include "NetworkStream.h" 36 | #include "Socket.h" 37 | 38 | using namespace Udt; 39 | using namespace System; 40 | using namespace System::IO; 41 | 42 | bool Readable(FileAccess access) 43 | { 44 | return (int)((access & FileAccess::Read)) != 0; 45 | } 46 | 47 | bool Writeable(FileAccess access) 48 | { 49 | return (int)((access & FileAccess::Write)) != 0; 50 | } 51 | 52 | NetworkStream::NetworkStream(Udt::Socket^ socket) 53 | { 54 | _socket = socket; 55 | _access = FileAccess::ReadWrite; 56 | _ownsSocket = true; 57 | 58 | Initialize(socket); 59 | } 60 | 61 | NetworkStream::NetworkStream(Udt::Socket^ socket, bool ownsSocket) 62 | { 63 | _socket = socket; 64 | _access = FileAccess::ReadWrite; 65 | _ownsSocket = ownsSocket; 66 | 67 | Initialize(socket); 68 | } 69 | 70 | NetworkStream::NetworkStream(Udt::Socket^ socket, FileAccess access) 71 | { 72 | _socket = socket; 73 | _access = access; 74 | _ownsSocket = true; 75 | 76 | Initialize(socket); 77 | } 78 | 79 | NetworkStream::NetworkStream(Udt::Socket^ socket, FileAccess access, bool ownsSocket) 80 | { 81 | _socket = socket; 82 | _access = access; 83 | _ownsSocket = ownsSocket; 84 | 85 | Initialize(socket); 86 | } 87 | 88 | void NetworkStream::Initialize(Udt::Socket^ socket) 89 | { 90 | if (socket == nullptr) 91 | throw gcnew ArgumentNullException("socket"); 92 | 93 | if (socket->SocketType != System::Net::Sockets::SocketType::Stream) 94 | throw gcnew ArgumentException("Socket type must be Stream.", "socket"); 95 | 96 | if ((Readable(_access) && !socket->BlockingReceive) || 97 | (Writeable(_access) && !socket->BlockingSend)) 98 | { 99 | throw gcnew ArgumentException("Socket must be in blocking state.", "socket"); 100 | } 101 | } 102 | 103 | NetworkStream::~NetworkStream() 104 | { 105 | Udt::Socket^ socket = _socket; 106 | _socket = nullptr; 107 | 108 | if (_ownsSocket) delete socket; 109 | } 110 | 111 | void NetworkStream::AssertNotDisposed(void) 112 | { 113 | if (_socket == nullptr) 114 | throw gcnew ObjectDisposedException(this->ToString()); 115 | } 116 | 117 | Udt::Socket^ NetworkStream::Socket::get(void) 118 | { 119 | AssertNotDisposed(); 120 | return _socket; 121 | } 122 | 123 | bool NetworkStream::CanRead::get(void) 124 | { 125 | return _socket != nullptr && Readable(_access); 126 | } 127 | 128 | bool NetworkStream::CanWrite::get(void) 129 | { 130 | return _socket != nullptr && Writeable(_access); 131 | } 132 | 133 | void NetworkStream::Flush(void) 134 | { 135 | } 136 | 137 | int NetworkStream::Read(cli::array^ buffer, int offset, int count) 138 | { 139 | AssertNotDisposed(); 140 | 141 | if (!CanRead) 142 | throw gcnew NotSupportedException("Stream does not support reading."); 143 | 144 | return _socket->Receive(buffer, offset, count); 145 | } 146 | 147 | void NetworkStream::Write(cli::array^ buffer, int offset, int count) 148 | { 149 | AssertNotDisposed(); 150 | 151 | if (!CanWrite) 152 | throw gcnew NotSupportedException("Stream does not support writing."); 153 | 154 | _socket->Send(buffer, offset, count); 155 | } 156 | 157 | __int64 NetworkStream::Seek(__int64 offset, System::IO::SeekOrigin origin) 158 | { 159 | throw gcnew NotSupportedException("Stream does not support seeking."); 160 | } 161 | 162 | void NetworkStream::SetLength(__int64 value) 163 | { 164 | throw gcnew NotSupportedException("Stream does not support seeking."); 165 | } 166 | 167 | __int64 NetworkStream::Length::get(void) 168 | { 169 | throw gcnew NotSupportedException("Stream does not support seeking."); 170 | } 171 | 172 | __int64 NetworkStream::Position::get(void) 173 | { 174 | throw gcnew NotSupportedException("Stream does not support seeking."); 175 | } 176 | 177 | void NetworkStream::Position::set(__int64 value) 178 | { 179 | throw gcnew NotSupportedException("Stream does not support seeking."); 180 | } 181 | -------------------------------------------------------------------------------- /UdtProtocol/NetworkStream.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | namespace Udt 36 | { 37 | ref class Socket; // Forward declaration 38 | 39 | /// 40 | /// Provides a interface to a UDT socket. 41 | /// 42 | public ref class NetworkStream : System::IO::Stream 43 | { 44 | private: 45 | Socket^ _socket; 46 | initonly bool _ownsSocket; 47 | initonly System::IO::FileAccess _access; 48 | 49 | void Initialize(Udt::Socket^ socket); 50 | 51 | protected: 52 | 53 | /// 54 | /// Get the underlying socket. 55 | /// 56 | property Udt::Socket^ Socket 57 | { 58 | Udt::Socket^ get(void); 59 | } 60 | 61 | void AssertNotDisposed(void); 62 | 63 | public: 64 | 65 | /// 66 | /// Initialize a new instance. 67 | /// 68 | /// Socket this stream will use to send/receive data. 69 | /// If is a null reference. 70 | /// 71 | /// If .SocketType is not
72 | /// - or -
73 | /// is in non-blocking mode 74 | ///
75 | NetworkStream(Udt::Socket^ socket); 76 | 77 | /// 78 | /// Initialize a new instance. 79 | /// 80 | /// Socket this stream will use to send/receive data. 81 | /// True if this stream will assume ownership of the . 82 | /// If is a null reference. 83 | /// 84 | /// If .SocketType is not
85 | /// - or -
86 | /// is in non-blocking mode 87 | ///
88 | NetworkStream(Udt::Socket^ socket, bool ownsSocket); 89 | 90 | /// 91 | /// Initialize a new instance. 92 | /// 93 | /// Socket this stream will use to send/receive data. 94 | /// Type of access to the given to the stream. 95 | /// If is a null reference. 96 | /// 97 | /// If .SocketType is not
98 | /// - or -
99 | /// is in non-blocking mode 100 | ///
101 | NetworkStream(Udt::Socket^ socket, System::IO::FileAccess access); 102 | 103 | /// 104 | /// Initialize a new instance. 105 | /// 106 | /// Socket this stream will use to send/receive data. 107 | /// Type of access to the given to the stream. 108 | /// True if this stream will assume ownership of the . 109 | /// If is a null reference. 110 | /// 111 | /// If .SocketType is not
112 | /// - or -
113 | /// is in non-blocking mode 114 | ///
115 | NetworkStream(Udt::Socket^ socket, System::IO::FileAccess access, bool ownsSocket); 116 | 117 | /// 118 | /// Dispose of the stream. 119 | /// 120 | virtual ~NetworkStream(); 121 | 122 | virtual property bool CanWrite { bool get(void) override; } 123 | virtual property bool CanRead { bool get(void) override; } 124 | virtual property bool CanSeek { bool get(void) override { return false; } } 125 | virtual property __int64 Length { __int64 get(void) override; } 126 | virtual property __int64 Position { __int64 get(void) override; void set(__int64 value) override; } 127 | 128 | virtual void Flush() override; 129 | virtual int Read(cli::array^ buffer, int offset, int count) override; 130 | virtual void Write(cli::array^ buffer, int offset, int count) override; 131 | virtual __int64 Seek(__int64 offset, System::IO::SeekOrigin origin) override; 132 | virtual void SetLength(__int64 value) override; 133 | }; 134 | } 135 | -------------------------------------------------------------------------------- /UdtProtocol/Packet.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | 35 | #include "Packet.h" 36 | #include "DataPacket.h" 37 | #include "ControlPacket.h" 38 | #include "KeepAlivePacket.h" 39 | #include "ShutdownPacket.h" 40 | #include "CongestionPacket.h" 41 | #include "ErrorPacket.h" 42 | #include "Ack2Packet.h" 43 | 44 | #include 45 | #include 46 | 47 | using namespace Udt; 48 | using namespace System; 49 | 50 | Packet^ Packet::Wrap(const CPacket* packet) 51 | { 52 | Packet^ wrapper; 53 | 54 | if (packet->getFlag()) 55 | { 56 | switch (packet->getType()) 57 | { 58 | case Ack2Packet::TypeCode: 59 | wrapper = gcnew Ack2Packet(packet); 60 | break; 61 | 62 | case ErrorPacket::TypeCode: 63 | wrapper = gcnew ErrorPacket(packet); 64 | break; 65 | 66 | case CongestionPacket::TypeCode: 67 | wrapper = gcnew CongestionPacket(packet); 68 | break; 69 | 70 | case ShutdownPacket::TypeCode: 71 | wrapper = gcnew ShutdownPacket(packet); 72 | break; 73 | 74 | case KeepAlivePacket::TypeCode: 75 | wrapper = gcnew KeepAlivePacket(packet); 76 | break; 77 | 78 | default: 79 | wrapper = gcnew ControlPacket(packet); 80 | break; 81 | } 82 | } 83 | else 84 | { 85 | wrapper = gcnew DataPacket(packet); 86 | } 87 | 88 | return wrapper; 89 | } 90 | 91 | Packet::Packet() 92 | : _packet(new CPacket()), _deletePacket(true) 93 | { 94 | } 95 | 96 | Packet::Packet(const CPacket* packet) 97 | : _packet((CPacket*)packet), _deletePacket(false) 98 | { 99 | } 100 | 101 | Packet::~Packet() 102 | { 103 | if (_deletePacket) 104 | { 105 | FreePacketData(); 106 | delete _packet; 107 | } 108 | 109 | _packet = NULL; 110 | } 111 | 112 | void Packet::AssertNotDisposed() 113 | { 114 | if (_packet == NULL) 115 | throw gcnew ObjectDisposedException(this->ToString()); 116 | } 117 | 118 | void Packet::AssertIsMutable() 119 | { 120 | AssertNotDisposed(); 121 | if (!IsEditable) throw gcnew InvalidOperationException("Packet can not be modified."); 122 | } 123 | 124 | TimeSpan Packet::TimeStamp::get(void) 125 | { 126 | AssertNotDisposed(); 127 | return FromMicroseconds((uint32_t)_packet->m_iTimeStamp); 128 | } 129 | 130 | void Packet::TimeStamp::set(TimeSpan value) 131 | { 132 | AssertIsMutable(); 133 | 134 | if (value < TimeSpan::Zero || value > MaxTimeStamp) 135 | throw gcnew ArgumentOutOfRangeException("value", value, String::Concat("Value must be between ", TimeSpan::Zero, " and ", MaxTimeStamp, ".")); 136 | 137 | _packet->m_iTimeStamp = (int32_t)ToMicroseconds(value); 138 | } 139 | 140 | int Packet::DestinationId::get(void) 141 | { 142 | AssertNotDisposed(); 143 | return _packet->m_iID; 144 | } 145 | 146 | void Packet::DestinationId::set(int value) 147 | { 148 | AssertIsMutable(); 149 | _packet->m_iID = value; 150 | } 151 | -------------------------------------------------------------------------------- /UdtProtocol/Packet.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | class CPacket; 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// UDT data packet. 41 | /// 42 | public ref class Packet abstract 43 | { 44 | private: 45 | bool _deletePacket; 46 | 47 | protected: 48 | 49 | CPacket* _packet; 50 | void AssertNotDisposed(); 51 | void AssertIsMutable(); 52 | virtual void FreePacketData() {} 53 | 54 | internal: 55 | 56 | static Packet^ Wrap(const CPacket* packet); 57 | 58 | Packet(void); 59 | Packet(const CPacket* packet); 60 | 61 | public: 62 | virtual ~Packet(void); 63 | 64 | /// 65 | /// Get true if the packet can be modified. 66 | /// 67 | property bool IsEditable { 68 | bool get(void) { return _packet != NULL && _deletePacket; } 69 | } 70 | 71 | /// 72 | /// Get true if the packet has been disposed. 73 | /// 74 | property bool IsDisposed { 75 | bool get(void) { return _packet == NULL; } 76 | } 77 | 78 | /// 79 | /// Get or set the time stamp associated with the packet. 80 | /// Default value is . 81 | /// 82 | /// 83 | /// 84 | /// The time stamp is generally the difference between when the 85 | /// packet was created and when the socket it was sent on was 86 | /// created. 87 | /// 88 | /// 89 | /// The resolution of this property is 1 microsecond 90 | /// (1000 nanoseconds). The resolution of 91 | /// is 100 nanoseconds. When setting the property, the value will 92 | /// be rounded down to the nearest microsecond. 93 | /// 94 | /// 95 | /// If is less than or greater than . 96 | /// If the object has been disposed. 97 | /// If attempting to set the value and is false. 98 | property System::TimeSpan TimeStamp { 99 | System::TimeSpan get(void); 100 | void set(System::TimeSpan value); 101 | } 102 | 103 | /// 104 | /// Get or set ID of the destination socket for the packet. 105 | /// Default value is 0. 106 | /// 107 | /// If the object has been disposed. 108 | /// If attempting to set the value and is false. 109 | property int DestinationId { 110 | int get(void); 111 | void set(int value); 112 | } 113 | 114 | /// 115 | /// Maximum allowed value for . 116 | /// 117 | /// 4,294,967,295 microseconds (01:11:34.9672950). 118 | static initonly System::TimeSpan MaxTimeStamp = FromMicroseconds(System::UInt32::MaxValue); 119 | }; 120 | } 121 | -------------------------------------------------------------------------------- /UdtProtocol/ProbeTraceInfo.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "ProbeTraceInfo.h" 35 | 36 | using namespace Udt; 37 | using namespace System; 38 | 39 | ProbeTraceInfo::ProbeTraceInfo(const UDT::TRACEINFO& copy) 40 | { 41 | this->PacketSendPeriod = FromMicroseconds((__int64)copy.usPktSndPeriod); 42 | this->FlowWindow = copy.pktFlowWindow; 43 | this->CongestionWindow = copy.pktCongestionWindow; 44 | this->FlightSize = copy.pktFlightSize; 45 | this->RoundtripTime = FromMilliseconds((__int64)copy.msRTT); 46 | this->BandwidthMbps = copy.mbpsBandwidth; 47 | this->AvailableSendBuffer = copy.byteAvailSndBuf; 48 | this->AvailableReceiveBuffer = copy.byteAvailRcvBuf; 49 | } 50 | 51 | ProbeTraceInfo::ProbeTraceInfo(void) 52 | { 53 | } 54 | -------------------------------------------------------------------------------- /UdtProtocol/ProbeTraceInfo.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Performance trace information instant values at the time they are observed. 41 | /// 42 | public ref class ProbeTraceInfo 43 | { 44 | internal: 45 | ProbeTraceInfo(const UDT::TRACEINFO& copy); 46 | 47 | public: 48 | /// 49 | /// Initialize a new instance with default values. 50 | /// 51 | ProbeTraceInfo(void); 52 | 53 | /// 54 | /// Packet sending period. 55 | /// 56 | property System::TimeSpan PacketSendPeriod; 57 | 58 | /// 59 | /// Flow window size, in number of packets. 60 | /// 61 | property int FlowWindow; 62 | 63 | /// 64 | /// Congestion window size, in number of packets. 65 | /// 66 | property int CongestionWindow; 67 | 68 | /// 69 | /// Number packets on the flight. 70 | /// 71 | property int FlightSize; 72 | 73 | /// 74 | /// Round trip time, in milliseconds. 75 | /// 76 | property System::TimeSpan RoundtripTime; 77 | 78 | /// 79 | /// Estimated bandwidth, in Mbps. 80 | /// 81 | property double BandwidthMbps; 82 | 83 | /// 84 | /// Available sending buffer size, in bytes. 85 | /// 86 | property int AvailableSendBuffer; 87 | 88 | /// 89 | /// Available receiving buffer size, in bytes. 90 | /// 91 | property int AvailableReceiveBuffer; 92 | }; 93 | } 94 | -------------------------------------------------------------------------------- /UdtProtocol/ShutdownPacket.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "ShutdownPacket.h" 35 | 36 | #include 37 | #include 38 | 39 | using namespace Udt; 40 | 41 | ShutdownPacket::ShutdownPacket(const CPacket* packet) 42 | : ControlPacket(packet) 43 | { 44 | } 45 | 46 | ShutdownPacket::ShutdownPacket(void) 47 | { 48 | _packet->pack(TypeCode); 49 | } 50 | -------------------------------------------------------------------------------- /UdtProtocol/ShutdownPacket.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "ControlPacket.h" 36 | 37 | class CPacket; 38 | 39 | namespace Udt 40 | { 41 | /// 42 | /// UDT protocol shutdown control packet. 43 | /// 44 | public ref class ShutdownPacket : public ControlPacket 45 | { 46 | internal: 47 | ShutdownPacket(const CPacket* packet); 48 | 49 | literal int TypeCode = 5; 50 | 51 | public: 52 | 53 | ShutdownPacket(void); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /UdtProtocol/SocketEvents.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Events available on the socket. 41 | /// 42 | [System::Flags] 43 | public enum class SocketEvents 44 | { 45 | /// 46 | /// No status flags. 47 | /// 48 | None = 0, 49 | 50 | /// 51 | /// Socket has an error. 52 | /// 53 | Error = UDT_EPOLL_ERR, 54 | 55 | /// 56 | /// There is data pending to read. 57 | /// 58 | Input = UDT_EPOLL_IN, 59 | 60 | /// 61 | /// There is data pending to send. 62 | /// 63 | Output = UDT_EPOLL_OUT, 64 | }; 65 | } -------------------------------------------------------------------------------- /UdtProtocol/SocketException.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "SocketException.h" 35 | 36 | #include 37 | 38 | using namespace System; 39 | using namespace Udt; 40 | 41 | SocketException::SocketException(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) 42 | : System::Exception(info, context) 43 | { 44 | _socketErrorCode = (Udt::SocketError)info->GetInt32("ErrorCode"); 45 | } 46 | 47 | SocketException::SocketException(void) 48 | { 49 | _socketErrorCode = Udt::SocketError::Error; 50 | } 51 | 52 | SocketException::SocketException(System::String^ message) 53 | : System::Exception(message) 54 | { 55 | _socketErrorCode = Udt::SocketError::Error; 56 | } 57 | 58 | SocketException::SocketException(System::String^ message, System::Exception^ inner) 59 | : System::Exception(message, inner) 60 | { 61 | _socketErrorCode = Udt::SocketError::Error; 62 | } 63 | 64 | SocketException::SocketException(System::String^ message, Udt::SocketError errorCode) 65 | : System::Exception(message) 66 | { 67 | _socketErrorCode = errorCode; 68 | } 69 | 70 | SocketException^ SocketException::GetLastError(String^ message) 71 | { 72 | UDT::ERRORINFO& lastError = UDT::getlasterror(); 73 | int errorCode = lastError.getErrorCode(); 74 | String^ udtMessage = (gcnew String(lastError.getErrorMessage()))->TrimEnd(); 75 | String^ exMessage; 76 | 77 | if (String::IsNullOrEmpty(message)) 78 | exMessage = String::Concat(udtMessage, Environment::NewLine, "UDT Error Code: ", (Object^)errorCode); 79 | else 80 | exMessage = String::Concat(message, Environment::NewLine, udtMessage, Environment::NewLine, "UDT Error Code: ", (Object^)errorCode); 81 | 82 | return gcnew SocketException(exMessage, (Udt::SocketError)errorCode); 83 | } 84 | -------------------------------------------------------------------------------- /UdtProtocol/SocketException.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include "SocketError.h" 36 | 37 | namespace Udt 38 | { 39 | [System::Serializable] 40 | public ref class SocketException : System::Exception 41 | { 42 | private: 43 | Udt::SocketError _socketErrorCode; 44 | 45 | internal: 46 | static SocketException^ GetLastError(System::String^ message); 47 | 48 | protected: 49 | SocketException(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context); 50 | 51 | public: 52 | SocketException(void); 53 | SocketException(System::String^ message); 54 | SocketException(System::String^ message, System::Exception^ inner); 55 | SocketException(System::String^ message, Udt::SocketError errorCode); 56 | 57 | [System::Security::Permissions::SecurityPermission( 58 | System::Security::Permissions::SecurityAction::LinkDemand, 59 | Flags = System::Security::Permissions::SecurityPermissionFlag::SerializationFormatter)] 60 | virtual void GetObjectData(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext context) override 61 | { 62 | this->System::Exception::GetObjectData(info, context); 63 | info->AddValue("ErrorCode", _socketErrorCode); 64 | } 65 | 66 | property Udt::SocketError SocketErrorCode 67 | { 68 | Udt::SocketError get() { return _socketErrorCode; } 69 | } 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /UdtProtocol/SocketOptionName.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Socket configuration option names. 41 | /// 42 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 43 | "Microsoft.Design", 44 | "CA1027:MarkEnumsWithFlags", 45 | Justification = "This is a set of discrete values, not a set of flags.")] 46 | public enum class SocketOptionName 47 | { 48 | /// 49 | /// The maximum transfer unit. 50 | /// 51 | MaxPacketSize = UDT_MSS, 52 | 53 | /// 54 | /// If sending is blocking. 55 | /// 56 | BlockingSend = UDT_SNDSYN, 57 | 58 | /// 59 | /// If receiving is blocking. 60 | /// 61 | BlockingReceive = UDT_RCVSYN, 62 | 63 | /// 64 | /// Flight flag size (window size). 65 | /// 66 | MaxWindowSize = UDT_FC, 67 | 68 | /// 69 | /// Maximum buffer in sending queue. 70 | /// 71 | SendBuffer = UDT_SNDBUF, 72 | 73 | /// 74 | /// UDT receiving buffer size. 75 | /// 76 | ReceiveBuffer = UDT_RCVBUF, 77 | 78 | /// 79 | /// UDP sending buffer size. 80 | /// 81 | UdpSendBuffer = UDP_SNDBUF, 82 | 83 | /// 84 | /// UDP receiving buffer size. 85 | /// 86 | UdpReceiveBuffer = UDP_RCVBUF, 87 | 88 | /// 89 | /// Rendezvous connection mode. 90 | /// 91 | Rendezvous = UDT_RENDEZVOUS, 92 | 93 | /// 94 | /// Send timeout. 95 | /// 96 | SendTimeout = UDT_SNDTIMEO, 97 | 98 | /// 99 | /// Receive timeout. 100 | /// 101 | ReceiveTimeout = UDT_RCVTIMEO, 102 | 103 | /// 104 | /// Reuse an existing port or create a new one. 105 | /// 106 | ReuseAddress = UDT_REUSEADDR, 107 | 108 | /// 109 | /// Maximum bandwidth (bytes per second) that the connection can use. 110 | /// 111 | MaxBandwidth = UDT_MAXBW, 112 | 113 | /// 114 | /// Waiting for unsent data when closing. 115 | /// 116 | Linger = UDT_LINGER, 117 | 118 | /// 119 | /// Custom congestion control algorithm. 120 | /// 121 | CongestionControl = UDT_CC, 122 | 123 | /// 124 | /// Size of data in the sending buffer (read only). 125 | /// 126 | SendData = UDT_SNDDATA, 127 | 128 | /// 129 | /// Size of data available for receiving (read only). 130 | /// 131 | ReceiveData = UDT_RCVDATA, 132 | 133 | /// 134 | /// Events available on the socket (read only). 135 | /// 136 | Events = UDT_EVENT, 137 | 138 | /// 139 | /// Socket state (read only). 140 | /// 141 | State = UDT_STATE, 142 | }; 143 | } 144 | -------------------------------------------------------------------------------- /UdtProtocol/SocketPoller.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "SocketPoller.h" 35 | 36 | #include "Socket.h" 37 | #include "SocketException.h" 38 | 39 | #include 40 | 41 | using namespace System; 42 | using namespace System::Collections::Generic; 43 | using namespace System::Collections::ObjectModel; 44 | using namespace Udt; 45 | 46 | SocketPoller::SocketPoller(void) 47 | { 48 | _epollId = UDT::epoll_create(); 49 | 50 | if (_epollId < 0) 51 | throw Udt::SocketException::GetLastError("Error creating epoll id."); 52 | 53 | _pollSockets = gcnew Dictionary(); 54 | _writeSockets = _readSockets = (ICollection^)EmptySocketList; 55 | } 56 | 57 | SocketPoller::~SocketPoller(void) 58 | { 59 | if (_epollId >= 0) 60 | { 61 | UDT::epoll_release(_epollId); 62 | _epollId = -1; 63 | } 64 | } 65 | 66 | void SocketPoller::AssertNotDisposed() 67 | { 68 | if (_epollId < 0) throw gcnew ObjectDisposedException(this->ToString()); 69 | } 70 | 71 | void SocketPoller::AddSocket(Udt::Socket^ socket) 72 | { 73 | if (socket == nullptr) throw gcnew ArgumentNullException("socket"); 74 | 75 | AssertNotDisposed(); 76 | 77 | if (UDT::epoll_add_usock(_epollId, socket->Handle) < 0) 78 | { 79 | throw Udt::SocketException::GetLastError("Error adding UDT socket to epoll."); 80 | } 81 | 82 | _pollSockets[socket->Handle] = socket; 83 | } 84 | 85 | void SocketPoller::RemoveSocket(Udt::Socket^ socket) 86 | { 87 | if (socket == nullptr) throw gcnew ArgumentNullException("socket"); 88 | 89 | AssertNotDisposed(); 90 | 91 | if (UDT::epoll_remove_usock(_epollId, socket->Handle) < 0) 92 | throw Udt::SocketException::GetLastError("Error removing UDT socket from epoll."); 93 | 94 | _pollSockets->Remove(socket->Handle); 95 | } 96 | 97 | void SocketPoller::Wait() 98 | { 99 | Wait(Udt::Socket::InfiniteTimeout); 100 | } 101 | 102 | bool SocketPoller::Wait(System::TimeSpan timeout) 103 | { 104 | AssertNotDisposed(); 105 | 106 | if (_pollSockets->Count == 0) throw gcnew InvalidOperationException("No sockets have been added to the poller."); 107 | 108 | _writeSockets = _readSockets = (ICollection^)EmptySocketList; 109 | 110 | std::set readSockets; 111 | std::set writeSockets; 112 | 113 | int result = UDT::epoll_wait(_epollId, &readSockets, &writeSockets, (int64_t)timeout.TotalMilliseconds); 114 | 115 | if (result < 0) { 116 | if (UDT::getlasterror().getErrorCode() == CUDTException::ETIMEOUT) { 117 | return false; 118 | } 119 | 120 | throw Udt::SocketException::GetLastError("Error waiting for socket epoll."); 121 | } 122 | 123 | if (result == 0) 124 | return false; 125 | 126 | if (readSockets.size() > 0) 127 | { 128 | List^ socketList = GetSockets(readSockets); 129 | 130 | if (socketList->Count > 0) 131 | { 132 | _readSockets = gcnew ReadOnlyCollection(socketList); 133 | } 134 | } 135 | 136 | if (writeSockets.size() > 0) 137 | { 138 | List^ socketList = GetSockets(writeSockets); 139 | 140 | if (socketList->Count > 0) 141 | { 142 | _writeSockets = gcnew ReadOnlyCollection(socketList); 143 | } 144 | } 145 | 146 | return true; 147 | } 148 | 149 | List^ SocketPoller::GetSockets(std::set& handles) 150 | { 151 | List^ list = gcnew List((int)handles.size()); 152 | 153 | for (std::set::iterator handleIter = handles.begin(); handleIter != handles.end(); ++handleIter) 154 | { 155 | Udt::Socket^ socket; 156 | 157 | if (_pollSockets->TryGetValue(*handleIter, socket)) 158 | list->Add(socket); 159 | } 160 | 161 | return list; 162 | } 163 | 164 | ICollection^ SocketPoller::ReadSockets::get(void) 165 | { 166 | return _readSockets; 167 | } 168 | 169 | ICollection^ SocketPoller::WriteSockets::get(void) 170 | { 171 | return _writeSockets; 172 | } 173 | -------------------------------------------------------------------------------- /UdtProtocol/SocketPoller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /***************************************************************** 3 | * 4 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 5 | * 6 | * Copyright (c) 2010, Cory Thomas 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * * Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * * Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * * Neither the name of the nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | ****************************************************************/ 33 | 34 | #pragma once 35 | 36 | #include 37 | 38 | namespace Udt 39 | { 40 | ref class Socket; 41 | ref class SocketException; 42 | 43 | /// 44 | /// Used to poll IO events from multiple sockets. 45 | /// 46 | public ref class SocketPoller 47 | { 48 | private: 49 | int _epollId; 50 | System::Collections::Generic::Dictionary^ _pollSockets; 51 | System::Collections::Generic::ICollection^ _readSockets; 52 | System::Collections::Generic::ICollection^ _writeSockets; 53 | 54 | static cli::array^ EmptySocketList = gcnew cli::array(0); 55 | 56 | void AssertNotDisposed(); 57 | System::Collections::Generic::List^ GetSockets(std::set& handles); 58 | 59 | public: 60 | 61 | /// 62 | /// Initialize a new instance. 63 | /// 64 | SocketPoller(void); 65 | 66 | virtual ~SocketPoller(void); 67 | 68 | /// 69 | /// Add a socket to the poller. 70 | /// 71 | /// 72 | /// If the has already been added to the poller, 73 | /// it will be ignored if added again. 74 | /// 75 | /// Socket to add. 76 | /// If is null. 77 | /// If an error occurs adding the socket. 78 | /// If the object has been disposed. 79 | void AddSocket(Udt::Socket^ socket); 80 | 81 | /// 82 | /// Remove a socket from the poller. 83 | /// 84 | /// Socket to remove. 85 | /// If is null. 86 | /// If an error occurs removing the socket. 87 | /// If the object has been disposed. 88 | void RemoveSocket(Udt::Socket^ socket); 89 | 90 | /// 91 | /// Wait indefinitely for a socket event to occur. 92 | /// 93 | /// If an error occurs waiting. 94 | /// If no sockets have been added to the poller. 95 | /// If the object has been disposed. 96 | void Wait(); 97 | 98 | /// 99 | /// Wait for a socket event to occur. 100 | /// 101 | /// 102 | /// Use and to get 103 | /// the sockets an event occurred on. 104 | /// 105 | /// Maximum amount of time to wait for an event to occur or -1 milliseconds to wait indefinitely. 106 | /// True if an event occurred before the timeout expired. 107 | /// If an error occurs waiting. 108 | /// If no sockets have been added to the poller. 109 | /// If the object has been disposed. 110 | bool Wait(System::TimeSpan timeout); 111 | 112 | /// 113 | /// Sockets that are ready to read or empty for none. 114 | /// By default the collection is empty. 115 | /// 116 | /// 117 | /// The collection is read-only. A new collection instance is 118 | /// created each time is called. 119 | /// 120 | property System::Collections::Generic::ICollection^ ReadSockets 121 | { 122 | System::Collections::Generic::ICollection^ get(void); 123 | } 124 | 125 | /// 126 | /// Sockets that are ready to write or broken or empty for none. 127 | /// By default the collection is empty. 128 | /// 129 | /// 130 | /// The collection is read-only. A new collection instance is 131 | /// created each time is called. 132 | /// 133 | property System::Collections::Generic::ICollection^ WriteSockets 134 | { 135 | System::Collections::Generic::ICollection^ get(void); 136 | } 137 | }; 138 | } 139 | -------------------------------------------------------------------------------- /UdtProtocol/SocketState.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// States the UDT socket can be in. 41 | /// 42 | public enum class SocketState 43 | { 44 | /// 45 | /// Invalid socket state. A socket will never be in this state. 46 | /// 47 | Invalid = 0, 48 | 49 | /// 50 | /// Socket is in initialized state. 51 | /// 52 | Initial = INIT, 53 | 54 | /// 55 | /// Socket is open. 56 | /// 57 | Open = OPENED, 58 | 59 | /// 60 | /// Socket is listening. 61 | /// 62 | Listening = LISTENING, 63 | 64 | /// 65 | /// Socket is establishing the connection. 66 | /// 67 | Connecting = CONNECTING, 68 | 69 | /// 70 | /// Socket is connected. 71 | /// 72 | Connected = CONNECTED, 73 | 74 | /// 75 | /// Socket is broken. 76 | /// 77 | Broken = BROKEN, 78 | 79 | /// 80 | /// Socket is closing. 81 | /// 82 | Closing = CLOSING, 83 | 84 | /// 85 | /// Socket is closed. 86 | /// 87 | Closed = CLOSED, 88 | }; 89 | } -------------------------------------------------------------------------------- /UdtProtocol/Stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // UdtProtocol.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | System::TimeSpan FromMicroseconds(__int64 us) 8 | { 9 | return System::TimeSpan(us * 10); 10 | } 11 | 12 | System::TimeSpan FromMilliseconds(__int64 ms) 13 | { 14 | return System::TimeSpan(ms * 10000); 15 | } 16 | 17 | __int64 ToMicroseconds(System::TimeSpan value) 18 | { 19 | return value.Ticks / 10; 20 | } 21 | -------------------------------------------------------------------------------- /UdtProtocol/Stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, 3 | // but are changed infrequently 4 | 5 | #pragma once 6 | 7 | #ifndef NULL 8 | #define NULL 0 9 | #endif 10 | 11 | System::TimeSpan FromMicroseconds(__int64 us); 12 | System::TimeSpan FromMilliseconds(__int64 ms); 13 | 14 | __int64 ToMicroseconds(System::TimeSpan value); 15 | -------------------------------------------------------------------------------- /UdtProtocol/TotalTraceInfo.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "TotalTraceInfo.h" 35 | 36 | using namespace Udt; 37 | using namespace System; 38 | 39 | TotalTraceInfo::TotalTraceInfo(const UDT::TRACEINFO& copy) 40 | { 41 | this->SocketCreated = FromMilliseconds(copy.msTimeStamp); 42 | this->PacketsSent = copy.pktSentTotal; 43 | this->PacketsReceived = copy.pktRecvTotal; 44 | this->SendPacketsLost = copy.pktSndLossTotal; 45 | this->ReceivePacketsLost = copy.pktRcvLossTotal; 46 | this->PacketsRetransmitted = copy.pktRetransTotal; 47 | this->AcksSent = copy.pktSentACKTotal; 48 | this->AcksReceived = copy.pktRecvACKTotal; 49 | this->NaksSent = copy.pktSentNAKTotal; 50 | this->NaksReceived = copy.pktRecvNAKTotal; 51 | this->SendDuration = FromMicroseconds(copy.usSndDurationTotal); 52 | } 53 | 54 | TotalTraceInfo::TotalTraceInfo(void) 55 | { 56 | } 57 | -------------------------------------------------------------------------------- /UdtProtocol/TotalTraceInfo.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | 37 | namespace Udt 38 | { 39 | /// 40 | /// Performance trace information aggregated since the socket was created. 41 | /// 42 | public ref class TotalTraceInfo 43 | { 44 | internal: 45 | TotalTraceInfo(const UDT::TRACEINFO& copy); 46 | 47 | public: 48 | /// 49 | /// Initialize a new instance with default values. 50 | /// 51 | TotalTraceInfo(void); 52 | 53 | /// 54 | /// Time elapsed since the UDT socket is created. 55 | /// 56 | property System::TimeSpan SocketCreated; 57 | 58 | /// 59 | /// Total number of sent packets, including retransmissions. 60 | /// 61 | property __int64 PacketsSent; 62 | 63 | /// 64 | /// Total number of received packets. 65 | /// 66 | property __int64 PacketsReceived; 67 | 68 | /// 69 | /// Total number of lost packets, measured in the sending side. 70 | /// 71 | property int SendPacketsLost; 72 | 73 | /// 74 | /// Total number of lost packets, measured in the receiving side. 75 | /// 76 | property int ReceivePacketsLost; 77 | 78 | /// 79 | /// Total number of retransmitted packets, measured in the sending side. 80 | /// 81 | property int PacketsRetransmitted; 82 | 83 | /// 84 | /// Total number of sent ACK packets. 85 | /// 86 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 87 | "Microsoft.Naming", 88 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 89 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 90 | property int AcksSent; 91 | 92 | /// 93 | /// Total number of received ACK packets. 94 | /// 95 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 96 | "Microsoft.Naming", 97 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 98 | Justification = "ACK is the accepted abbreviation for acknowledgement in this context.")] 99 | property int AcksReceived; 100 | 101 | /// 102 | /// Total number of sent NAK packets. 103 | /// 104 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 105 | "Microsoft.Naming", 106 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 107 | Justification = "NAK is the accepted abbreviation for negative acknowledgement in this context.")] 108 | property int NaksSent; 109 | 110 | /// 111 | /// Total number of received NAK packets. 112 | /// 113 | [System::Diagnostics::CodeAnalysis::SuppressMessageAttribute( 114 | "Microsoft.Naming", 115 | "CA1704:IdentifiersShouldBeSpelledCorrectly", 116 | Justification = "NAK is the accepted abbreviation for negative acknowledgement in this context.")] 117 | property int NaksReceived; 118 | 119 | /// 120 | /// Total time duration when UDT is sending data (idle time exclusive). 121 | /// 122 | property System::TimeSpan SendDuration; 123 | }; 124 | } 125 | -------------------------------------------------------------------------------- /UdtProtocol/TraceInfo.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #include "StdAfx.h" 34 | #include "TraceInfo.h" 35 | 36 | using namespace Udt; 37 | using namespace System; 38 | 39 | TraceInfo::TraceInfo(const UDT::TRACEINFO& copy) 40 | { 41 | _total = gcnew TotalTraceInfo(copy); 42 | _local = gcnew LocalTraceInfo(copy); 43 | _probe = gcnew ProbeTraceInfo(copy); 44 | } 45 | 46 | TraceInfo::TraceInfo(void) 47 | { 48 | _total = gcnew TotalTraceInfo(); 49 | _local = gcnew LocalTraceInfo(); 50 | _probe = gcnew ProbeTraceInfo(); 51 | } 52 | -------------------------------------------------------------------------------- /UdtProtocol/TraceInfo.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * BSD LICENCE (http://www.opensource.org/licenses/bsd-license.php) 4 | * 5 | * Copyright (c) 2010, Cory Thomas 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * * Neither the name of the nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | ****************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include "TotalTraceInfo.h" 37 | #include "LocalTraceInfo.h" 38 | #include "ProbeTraceInfo.h" 39 | 40 | namespace Udt 41 | { 42 | /// 43 | /// UDT socket performance trace information. 44 | /// 45 | public ref class TraceInfo 46 | { 47 | private: 48 | [System::Diagnostics::DebuggerBrowsable(System::Diagnostics::DebuggerBrowsableState::Never)] 49 | Udt::TotalTraceInfo^ _total; 50 | 51 | [System::Diagnostics::DebuggerBrowsable(System::Diagnostics::DebuggerBrowsableState::Never)] 52 | Udt::LocalTraceInfo^ _local; 53 | 54 | [System::Diagnostics::DebuggerBrowsable(System::Diagnostics::DebuggerBrowsableState::Never)] 55 | Udt::ProbeTraceInfo^ _probe; 56 | 57 | internal: 58 | TraceInfo(const UDT::TRACEINFO& copy); 59 | 60 | public: 61 | /// 62 | /// Initialize a new instance with default values. 63 | /// 64 | TraceInfo(void); 65 | 66 | /// 67 | /// Aggregate values since the UDT socket is created. 68 | /// 69 | property Udt::TotalTraceInfo^ Total { Udt::TotalTraceInfo^ get(void) { return _total; } } 70 | 71 | /// 72 | /// Local values since the last time they are recorded. 73 | /// 74 | /// 75 | /// The local attributes are reset when true is passed to 76 | /// Udt.Socket.GetPerformanceInfo(bool). 77 | /// 78 | property Udt::LocalTraceInfo^ Local { Udt::LocalTraceInfo^ get(void) { return _local; } } 79 | 80 | /// 81 | /// Instant values at the time they are observed. 82 | /// 83 | property Udt::ProbeTraceInfo^ Probe { Udt::ProbeTraceInfo^ get(void) { return _probe; } } 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /UdtProtocol/UdtProtocol.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""afxres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 0,10,0,0 55 | PRODUCTVERSION 0,10,0,0 56 | FILEFLAGSMASK 0x17L 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x4L 63 | FILETYPE 0x2L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileDescription", "UDT.Net wrapper library" 71 | VALUE "FileVersion", "0.10.0.0" 72 | VALUE "InternalName", "UdtProtocol" 73 | VALUE "LegalCopyright", "Copyright (C) 2011" 74 | VALUE "OriginalFilename", "UdtProtocol.dll" 75 | VALUE "ProductName", "UDT.Net wrapper library" 76 | VALUE "ProductVersion", "0.10.0.0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x409, 1200 82 | END 83 | END 84 | 85 | #endif // English (United States) resources 86 | ///////////////////////////////////////////////////////////////////////////// 87 | 88 | 89 | 90 | #ifndef APSTUDIO_INVOKED 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Generated from the TEXTINCLUDE 3 resource. 94 | // 95 | 96 | 97 | ///////////////////////////////////////////////////////////////////////////// 98 | #endif // not APSTUDIO_INVOKED 99 | 100 | -------------------------------------------------------------------------------- /UdtProtocol/UdtProtocol.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | Source Files 95 | 96 | 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | 193 | 194 | Resource Files 195 | 196 | 197 | -------------------------------------------------------------------------------- /UdtProtocol/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by UdtProtocol.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------