Created
February 7, 2014 15:40
-
-
Save jtacoma/8865094 to your computer and use it in GitHub Desktop.
Apply this diff to bfc0349506fc8d2ea80e80eb36cbd838092313a6 of zeromq/netmq to make it compatible with .Net 3.5, thanks to https://gist.github.com/tobi-tobsen/6389448 for an earlier version of this patch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/NetMQ.Tests/NetMQ.Tests.csproj b/src/NetMQ.Tests/NetMQ.Tests.csproj | |
| index bb7590e..5d4f9f8 100644 | |
| --- a/src/NetMQ.Tests/NetMQ.Tests.csproj | |
| +++ b/src/NetMQ.Tests/NetMQ.Tests.csproj | |
| @@ -12,6 +12,8 @@ | |
| <AssemblyName>NetMQ.Tests</AssemblyName> | |
| <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |
| <FileAlignment>512</FileAlignment> | |
| + <TargetFrameworkProfile> | |
| + </TargetFrameworkProfile> | |
| </PropertyGroup> | |
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
| <DebugSymbols>true</DebugSymbols> | |
| @@ -64,7 +66,6 @@ | |
| <Compile Include="ExpectedZmqException.cs" /> | |
| <Compile Include="MessageTests.cs" /> | |
| <Compile Include="MonitorPollTests.cs" /> | |
| - <Compile Include="NetMQSchedulerTest.cs" /> | |
| <Compile Include="NetMQTestRunner.cs" /> | |
| <Compile Include="PgmTests.cs" /> | |
| <Compile Include="PollerTests.cs" /> | |
| @@ -73,7 +74,6 @@ | |
| <Compile Include="PubSubTests.cs" /> | |
| <Compile Include="PushPullTests.cs" /> | |
| <Compile Include="ReqRepTests.cs" /> | |
| - <Compile Include="Security\SecureChannelTests.cs" /> | |
| <Compile Include="SocketTests.cs" /> | |
| <Compile Include="StreamTests.cs" /> | |
| <Compile Include="zmq\YQueueTests.cs" /> | |
| @@ -87,6 +87,7 @@ | |
| </ItemGroup> | |
| <ItemGroup /> | |
| <ItemGroup> | |
| + <None Include="app.config" /> | |
| <None Include="NetMQ.Testing.crt"> | |
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |
| </None> | |
| diff --git a/src/NetMQ/Devices/ThreadedDeviceRunner.cs b/src/NetMQ/Devices/ThreadedDeviceRunner.cs | |
| index b6ef2a3..f6e304c 100644 | |
| --- a/src/NetMQ/Devices/ThreadedDeviceRunner.cs | |
| +++ b/src/NetMQ/Devices/ThreadedDeviceRunner.cs | |
| @@ -1,4 +1,4 @@ | |
| -using System.Threading.Tasks; | |
| +using System.Threading; | |
| namespace NetMQ.Devices | |
| { | |
| @@ -14,7 +14,7 @@ public ThreadedDeviceRunner(IDevice device) | |
| public override void Start() | |
| { | |
| - Task.Factory.StartNew(Device.Run, TaskCreationOptions.LongRunning); | |
| + ThreadPool.QueueUserWorkItem(delegate { this.Device.Run(); }); | |
| } | |
| } | |
| } | |
| \ No newline at end of file | |
| diff --git a/src/NetMQ/Monitoring/NetMQMonitor.cs b/src/NetMQ/Monitoring/NetMQMonitor.cs | |
| index 66c5a61..b649d88 100644 | |
| --- a/src/NetMQ/Monitoring/NetMQMonitor.cs | |
| +++ b/src/NetMQ/Monitoring/NetMQMonitor.cs | |
| @@ -13,7 +13,7 @@ public class NetMQMonitor : IDisposable | |
| private bool m_isOwner; | |
| private Poller m_attachedPoller = null; | |
| - readonly CancellationTokenSource m_cancellationTokenSource = new CancellationTokenSource(); | |
| + bool m_cancellationTokenSource = false; | |
| private readonly ManualResetEvent m_isStoppedEvent = new ManualResetEvent(true); | |
| @@ -214,7 +214,7 @@ public void Start() | |
| try | |
| { | |
| - while (!m_cancellationTokenSource.IsCancellationRequested) | |
| + while (!m_cancellationTokenSource) | |
| { | |
| MonitoringSocket.Poll(Timeout); | |
| } | |
| @@ -233,7 +233,7 @@ public void Stop() | |
| throw new InvalidOperationException("Monitor attached to a poller, please detach from poller and don't use the stop method"); | |
| } | |
| - m_cancellationTokenSource.Cancel(); | |
| + m_cancellationTokenSource = true; | |
| m_isStoppedEvent.WaitOne(); | |
| } | |
| diff --git a/src/NetMQ/NetMQ.csproj b/src/NetMQ/NetMQ.csproj | |
| index dcb6b5b..3a1dfa2 100644 | |
| --- a/src/NetMQ/NetMQ.csproj | |
| +++ b/src/NetMQ/NetMQ.csproj | |
| @@ -10,8 +10,9 @@ | |
| <AppDesignerFolder>Properties</AppDesignerFolder> | |
| <RootNamespace>NetMQ</RootNamespace> | |
| <AssemblyName>NetMQ</AssemblyName> | |
| - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | |
| + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | |
| <FileAlignment>512</FileAlignment> | |
| + <TargetFrameworkProfile>Client</TargetFrameworkProfile> | |
| </PropertyGroup> | |
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
| <DebugSymbols>true</DebugSymbols> | |
| @@ -38,7 +39,6 @@ | |
| </ItemGroup> | |
| <ItemGroup> | |
| <Compile Include="IReceivingSocket.cs" /> | |
| - <Compile Include="NetMQScheduler.cs" /> | |
| <Compile Include="OutgoingSocketExtensions.cs" /> | |
| <Compile Include="ErrorPollingException.cs" /> | |
| <Compile Include="NetMQFrame.cs" /> | |
| @@ -50,25 +50,6 @@ | |
| <Compile Include="NetMQSocketEventArgs.cs" /> | |
| <Compile Include="Poller.cs" /> | |
| <Compile Include="ReceivingSocketExtensions.cs" /> | |
| - <Compile Include="Security\NetMQSecurityException.cs"> | |
| - <SubType>Code</SubType> | |
| - </Compile> | |
| - <Compile Include="Security\CipherSuite.cs" /> | |
| - <Compile Include="Security\V0_1\ContentType.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeLayer.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\ClientHelloMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\FinishedMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\HandshakeMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\CertificateMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\ServerHelloDoneMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\ServerHelloMessage.cs" /> | |
| - <Compile Include="Security\V0_1\HandshakeMessages\ClientKeyExchangeMessage.cs" /> | |
| - <Compile Include="Security\ISecureChannel.cs" /> | |
| - <Compile Include="Security\V0_1\OutgoingMessageBag.cs" /> | |
| - <Compile Include="Security\V0_1\RecordLayer.cs" /> | |
| - <Compile Include="Security\V0_1\SecureChannel.cs" /> | |
| - <Compile Include="Security\V0_1\SecurityParameters.cs" /> | |
| - <Compile Include="Security\V0_1\SHA256PRF.cs" /> | |
| <Compile Include="Sockets\DealerSocket.cs" /> | |
| <Compile Include="Devices\DeviceBase.cs" /> | |
| <Compile Include="Devices\DeviceMode.cs" /> | |
| diff --git a/src/NetMQ/NetMQSocket.cs b/src/NetMQ/NetMQSocket.cs | |
| index b4ec985..3eb62fd 100644 | |
| --- a/src/NetMQ/NetMQSocket.cs | |
| +++ b/src/NetMQ/NetMQSocket.cs | |
| @@ -169,7 +169,7 @@ public bool Poll(TimeSpan timeout) | |
| ZMQ.Poll(items, (int)timeout.TotalMilliseconds); | |
| - if (item.ResultEvent.HasFlag(PollEvents.PollError) && !IgnoreErrors) | |
| + if (EnumFlagsHelper.HasFlag(item.ResultEvent, PollEvents.PollError) && !IgnoreErrors) | |
| { | |
| Errors++; | |
| @@ -211,7 +211,7 @@ internal void InvokeEvents(object sender, PollEvents events) | |
| { | |
| m_socketEventArgs.Init(events); | |
| - if (events.HasFlag(PollEvents.PollIn)) | |
| + if (EnumFlagsHelper.HasFlag(events, PollEvents.PollIn)) | |
| { | |
| var temp = m_receiveReady; | |
| if (temp != null) | |
| @@ -220,7 +220,7 @@ internal void InvokeEvents(object sender, PollEvents events) | |
| } | |
| } | |
| - if (events.HasFlag(PollEvents.PollOut)) | |
| + if (EnumFlagsHelper.HasFlag(events, PollEvents.PollOut)) | |
| { | |
| var temp = m_sendReady; | |
| if (temp != null) | |
| diff --git a/src/NetMQ/NetMQSocketEventArgs.cs b/src/NetMQ/NetMQSocketEventArgs.cs | |
| index 25dd489..0fe77e6 100644 | |
| --- a/src/NetMQ/NetMQSocketEventArgs.cs | |
| +++ b/src/NetMQ/NetMQSocketEventArgs.cs | |
| @@ -15,8 +15,8 @@ public NetMQSocketEventArgs(NetMQSocket socket) | |
| internal void Init(PollEvents events) | |
| { | |
| - this.ReceiveReady = events.HasFlag(PollEvents.PollIn); | |
| - this.SendReady = events.HasFlag(PollEvents.PollOut); | |
| + this.ReceiveReady = EnumFlagsHelper.HasFlag(events, PollEvents.PollIn); | |
| + this.SendReady = EnumFlagsHelper.HasFlag(events, PollEvents.PollOut); | |
| } | |
| public NetMQSocket Socket { get; private set; } | |
| diff --git a/src/NetMQ/Poller.cs b/src/NetMQ/Poller.cs | |
| index 218bccd..74a7540 100644 | |
| --- a/src/NetMQ/Poller.cs | |
| +++ b/src/NetMQ/Poller.cs | |
| @@ -36,7 +36,7 @@ public NetMQSocket NetMQSocket | |
| readonly List<NetMQTimer> m_timers = new List<NetMQTimer>(); | |
| readonly List<NetMQTimer> m_zombies = new List<NetMQTimer>(); | |
| - readonly CancellationTokenSource m_cancellationTokenSource; | |
| + bool m_cancellationTokenSource = false; | |
| readonly ManualResetEvent m_isStoppedEvent = new ManualResetEvent(false); | |
| private bool m_isStarted; | |
| @@ -46,8 +46,6 @@ public NetMQSocket NetMQSocket | |
| public Poller() | |
| { | |
| PollTimeout = 1000; | |
| - | |
| - m_cancellationTokenSource = new CancellationTokenSource(); | |
| } | |
| public Poller(params NetMQSocket[] sockets) | |
| @@ -274,7 +272,7 @@ public void Start() | |
| } | |
| } | |
| - while (!m_cancellationTokenSource.IsCancellationRequested) | |
| + while (!m_cancellationTokenSource) | |
| { | |
| if (m_isDirty) | |
| { | |
| @@ -306,7 +304,7 @@ public void Start() | |
| NetMQSocket socket = m_pollact[itemNbr]; | |
| PollItem item = m_pollset[itemNbr]; | |
| - if (item.ResultEvent.HasFlag(PollEvents.PollError) && !socket.IgnoreErrors) | |
| + if (EnumFlagsHelper.HasFlag(item.ResultEvent, PollEvents.PollError) && !socket.IgnoreErrors) | |
| { | |
| socket.Errors++; | |
| @@ -359,7 +357,7 @@ public void Stop(bool waitForCloseToComplete) | |
| if (m_isStarted) | |
| { | |
| - m_cancellationTokenSource.Cancel(); | |
| + m_cancellationTokenSource = true; | |
| if (waitForCloseToComplete) | |
| { | |
| diff --git a/src/NetMQ/ReceivingSocketExtensions.cs b/src/NetMQ/ReceivingSocketExtensions.cs | |
| index 1bece12..4c25083 100644 | |
| --- a/src/NetMQ/ReceivingSocketExtensions.cs | |
| +++ b/src/NetMQ/ReceivingSocketExtensions.cs | |
| @@ -10,7 +10,7 @@ public static class ReceivingSocketExtensions | |
| { | |
| public static byte[] Receive(this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore) | |
| { | |
| - return socket.Receive(options.HasFlag(SendReceiveOptions.DontWait), out hasMore); | |
| + return socket.Receive(EnumFlagsHelper.HasFlag(options, SendReceiveOptions.DontWait), out hasMore); | |
| } | |
| public static byte[] Receive(this IReceivingSocket socket, out bool hasMore) | |
| @@ -38,7 +38,7 @@ public static string ReceiveString(this IReceivingSocket socket, bool dontWait, | |
| public static string ReceiveString(this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore) | |
| { | |
| - return socket.ReceiveString(options.HasFlag(SendReceiveOptions.DontWait), out hasMore); | |
| + return socket.ReceiveString(EnumFlagsHelper.HasFlag(options, SendReceiveOptions.DontWait), out hasMore); | |
| } | |
| public static string ReceiveString(this IReceivingSocket socket, SendReceiveOptions options) | |
| @@ -71,10 +71,10 @@ public static NetMQMessage ReceiveMessage(this NetMQSocket socket, TimeSpan time | |
| var items = new[] { item }; | |
| ZMQ.Poll(items, (int)timeout.TotalMilliseconds); | |
| - if (item.ResultEvent.HasFlag(PollEvents.PollError) && !socket.IgnoreErrors) | |
| + if (EnumFlagsHelper.HasFlag(item.ResultEvent, PollEvents.PollError) && !socket.IgnoreErrors) | |
| throw new ErrorPollingException("Error while polling", socket); | |
| - if (!item.ResultEvent.HasFlag(PollEvents.PollIn)) | |
| + if (!EnumFlagsHelper.HasFlag(item.ResultEvent, PollEvents.PollIn)) | |
| return null; | |
| var msg = socket.ReceiveMessage(); | |
| diff --git a/src/NetMQ/zmq/Address.cs b/src/NetMQ/zmq/Address.cs | |
| index ca40994..20cb869 100644 | |
| --- a/src/NetMQ/zmq/Address.cs | |
| +++ b/src/NetMQ/zmq/Address.cs | |
| @@ -50,12 +50,7 @@ public Address(EndPoint endpoint) | |
| { | |
| Protocol = TcpProtocol; | |
| - if (endpoint is DnsEndPoint) | |
| - { | |
| - DnsEndPoint dnsEndpoint = endpoint as DnsEndPoint; | |
| - AddressString = dnsEndpoint.Host + ":" + dnsEndpoint.Port; | |
| - } | |
| - else if (endpoint is IPEndPoint) | |
| + if (endpoint is IPEndPoint) | |
| { | |
| IPEndPoint ipEndpoint = endpoint as IPEndPoint; | |
| AddressString = ipEndpoint.Address + ":" + ipEndpoint.Port; | |
| diff --git a/src/NetMQ/zmq/Enums.cs b/src/NetMQ/zmq/Enums.cs | |
| index 7724a53..c03e540 100644 | |
| --- a/src/NetMQ/zmq/Enums.cs | |
| +++ b/src/NetMQ/zmq/Enums.cs | |
| @@ -122,4 +122,17 @@ public enum PollEvents | |
| PollOut = 0x2, | |
| PollError = 0x4 | |
| } | |
| -} | |
| \ No newline at end of file | |
| + | |
| + public class EnumFlagsHelper | |
| + { | |
| + public static bool HasFlag(PollEvents flags, PollEvents flag) | |
| + { | |
| + return (flags & flag) != 0; | |
| + } | |
| + | |
| + public static bool HasFlag(SendReceiveOptions flags, SendReceiveOptions flag) | |
| + { | |
| + return (flags & flag) != 0; | |
| + } | |
| + } | |
| +} | |
| diff --git a/src/NetMQ/zmq/RawEncoder.cs b/src/NetMQ/zmq/RawEncoder.cs | |
| index 19ce0b9..e98106e 100644 | |
| --- a/src/NetMQ/zmq/RawEncoder.cs | |
| +++ b/src/NetMQ/zmq/RawEncoder.cs | |
| @@ -46,7 +46,7 @@ bool RawMessageSizeReady() | |
| { | |
| // Write message body into the buffer. | |
| NextStep(m_inProgress.Data, m_inProgress.Size, | |
| - RawMessageReadyState, !m_inProgress.Flags.HasFlag(MsgFlags.More)); | |
| + RawMessageReadyState, (m_inProgress.Flags & MsgFlags.More) == 0); | |
| return true; | |
| } | |
| diff --git a/src/NetMQ/zmq/Signaler.cs b/src/NetMQ/zmq/Signaler.cs | |
| index 8ead080..dd6d5bf 100644 | |
| --- a/src/NetMQ/zmq/Signaler.cs | |
| +++ b/src/NetMQ/zmq/Signaler.cs | |
| @@ -109,7 +109,7 @@ private void MakeFDpair() | |
| sync.ReleaseMutex(); | |
| // Release the kernel object | |
| - sync.Dispose(); | |
| + sync.Close(); | |
| } | |
| public Socket FD | |
| diff --git a/src/Samples/Load Balancing Pattern/ROUTERbrokerDEALERworkers/ROUTERbrokerDEALERworkers.csproj b/src/Samples/Load Balancing Pattern/ROUTERbrokerDEALERworkers/ROUTERbrokerDEALERworkers.csproj | |
| index 899734b..eb6f07a 100644 | |
| --- a/src/Samples/Load Balancing Pattern/ROUTERbrokerDEALERworkers/ROUTERbrokerDEALERworkers.csproj | |
| +++ b/src/Samples/Load Balancing Pattern/ROUTERbrokerDEALERworkers/ROUTERbrokerDEALERworkers.csproj | |
| @@ -48,7 +48,7 @@ | |
| <None Include="App.config" /> | |
| </ItemGroup> | |
| <ItemGroup> | |
| - <ProjectReference Include="..\..\..\..\..\..\GitHub\netmq\src\NetMQ\NetMQ.csproj"> | |
| + <ProjectReference Include="..\..\..\NetMQ\NetMQ.csproj"> | |
| <Project>{82934bac-07fb-41ac-ae59-46fee6026a40}</Project> | |
| <Name>NetMQ</Name> | |
| </ProjectReference> | |
| diff --git a/src/Samples/Load Balancing Pattern/ROUTERbrokerREQworkers/ROUTERbrokerREQworkers.csproj b/src/Samples/Load Balancing Pattern/ROUTERbrokerREQworkers/ROUTERbrokerREQworkers.csproj | |
| index 9e0529a..eba605d 100644 | |
| --- a/src/Samples/Load Balancing Pattern/ROUTERbrokerREQworkers/ROUTERbrokerREQworkers.csproj | |
| +++ b/src/Samples/Load Balancing Pattern/ROUTERbrokerREQworkers/ROUTERbrokerREQworkers.csproj | |
| @@ -48,7 +48,7 @@ | |
| <None Include="App.config" /> | |
| </ItemGroup> | |
| <ItemGroup> | |
| - <ProjectReference Include="..\..\..\..\..\..\GitHub\netmq\src\NetMQ\NetMQ.csproj"> | |
| + <ProjectReference Include="..\..\..\NetMQ\NetMQ.csproj"> | |
| <Project>{82934bac-07fb-41ac-ae59-46fee6026a40}</Project> | |
| <Name>NetMQ</Name> | |
| </ProjectReference> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment