├── .gitignore
├── .travis.yml
├── AssemblyInfo.cs
├── Devices
├── PubSubDevice.cs
├── PushPullDevice.cs
├── RouterDealerDevice.cs
└── StreamDealerDevice.cs
├── LICENSE.txt
├── Monitoring
├── ZMonitor.cs
├── ZMonitorEventArgs.cs
├── ZMonitorEventData.cs
├── ZMonitorEvents.cs
├── ZMonitorFileDescriptorEventArgs.cs
├── ZMonitorIntervalEventArgs.cs
└── ZMonitors.cs
├── Platform
├── DispoIntPtr.Ansi.cs
├── DispoIntPtr.cs
├── Platform.MacOSX.cs
├── Platform.Posix.cs
├── Platform.Win32.cs
├── Platform.__Internal.cs
├── Platform.cs
├── UnmanagedLibrary.cs
├── zmq.cs
├── zmq_pollitem_posix_t.cs
└── zmq_pollitem_windows_t.cs
├── README.md
├── RouterMandatory.cs
├── TcpKeepaliveBehaviour.cs
├── Z85.cs
├── ZActor.cs
├── ZAuth.cs
├── ZCert.cs
├── ZCertStore.cs
├── ZContext.cs
├── ZContextOption.cs
├── ZDevice.cs
├── ZError.cs
├── ZException.cs
├── ZFrame.cs
├── ZFrameOption.cs
├── ZGuideExamples
├── AssemblyInfo.cs
├── Program.cs
├── ProgramRunner.cs
├── README.md
├── Z85Encode.cs
├── ZGuideExamples.mono.csproj
├── ZGuideExamples.netcore.csproj
├── ZGuideExamples.vs.csproj
├── asyncsrv.cs
├── eagain.cs
├── espresso.cs
├── flcliapi.cs
├── flclient1.cs
├── flclient2.cs
├── flclient3.cs
├── flserver1.cs
├── flserver2.cs
├── flserver3.cs
├── hwclient.cs
├── hwserver.cs
├── identity.cs
├── interrupt.cs
├── ironhouseclient.cs
├── ironhouseserver.cs
├── lbbroker.cs
├── lpclient.cs
├── lpserver.cs
├── lvcache.cs
├── mdbroker.cs
├── mdcliapi.cs
├── mdcliapi2.cs
├── mdclient.cs
├── mdclient2.cs
├── mdp.cs
├── mdworker.cs
├── mdwrkapi.cs
├── mmiecho.cs
├── msgqueue.cs
├── mspoller.cs
├── msreader.cs
├── mtrelay.cs
├── mtserver.cs
├── pathopub.cs
├── pathosub.cs
├── peering1.cs
├── peering2.cs
├── ppqueue.cs
├── ppworker.cs
├── project.json
├── psenvpub.cs
├── psenvsub.cs
├── rrbroker.cs
├── rrclient.cs
├── rrworker.cs
├── rtdealer.cs
├── rtreq.cs
├── spqueue.cs
├── spworker.cs
├── suisnail.cs
├── syncpub.cs
├── syncsub.cs
├── tasksink.cs
├── tasksink2.cs
├── taskvent.cs
├── taskwork.cs
├── taskwork2.cs
├── ticlient.cs
├── titanic.cs
├── tripping.cs
├── version.cs
├── wuclient.cs
├── wuproxy.cs
└── wuserver.cs
├── ZMessage.cs
├── ZPoll.cs
├── ZPollItem.cs
├── ZPollItems.Posix.cs
├── ZPollItems.Win32.cs
├── ZPollItems.cs
├── ZSocket.cs
├── ZSocketFlags.cs
├── ZSocketOption.cs
├── ZSocketSetup.cs
├── ZSocketType.cs
├── ZSymbol.cs
├── ZThread.cs
├── ZeroMQ.7z.Release.cmd
├── ZeroMQ.gif
├── ZeroMQ.ico
├── ZeroMQ.mono.csproj
├── ZeroMQ.netcore.csproj
├── ZeroMQ.nuspec
├── ZeroMQ.snk
├── ZeroMQ.targets
├── ZeroMQ.vs.csproj
├── ZeroMQ.zip.Release.sh
├── app.config
├── appveyor.yml
├── build.sh
├── clrzmq4.mono.sln
├── clrzmq4.netcore.sln
├── clrzmq4.vs.sln
├── project.json
└── travis.preinstall.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .*
2 | **/.*
3 | bin/*
4 | obj/*
5 | **/bin/*
6 | **/obj/*
7 |
8 | packages/*
9 |
10 | *.lock*
11 | *.cache*
12 | *.old*
13 | *.user*
14 | *.userprefs
15 | *.suo
16 | *.nupkg
17 |
18 | amd64/*
19 | i386/*
20 |
21 | ZeroMQ.*.zip
22 |
23 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | solution: clrzmq4.mono.sln
2 | language: csharp
3 | mono: latest
4 | #sudo: required
5 |
6 | matrix:
7 | include:
8 | - os: linux
9 | dist: xenial
10 |
11 | - os: osx
12 | osx_image: xcode9.4
13 | # osx_image: xcode7.3
14 |
15 | before_install:
16 | - chmod a+x ./travis.preinstall.sh
17 | - chmod a+x ./build.sh
18 |
19 | install:
20 | - ./travis.preinstall.sh
21 | - ./build.sh
22 |
23 | #before_script:
24 |
25 | script:
26 | - mono bin/Release/ZGuideExamples.exe Version
27 | - mono bin/Release/ZGuideExamples.exe EAgain
28 | - mono bin/Release/ZGuideExamples.exe Espresso
29 | - mono bin/Release/ZGuideExamples.exe AsyncSrv
30 |
--------------------------------------------------------------------------------
/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | // Information about this assembly is defined by the following attributes.
5 | // Change them to the values specific to your project.
6 |
7 | [assembly: AssemblyTitle("ZeroMQ")]
8 | [assembly: AssemblyDescription("ZeroMQ CLR namespace")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("ØMQ")]
11 | [assembly: AssemblyProduct("ØMQ")]
12 | [assembly: AssemblyCopyright("ØMQ")]
13 | [assembly: AssemblyTrademark("")]
14 | // [assembly: AssemblyCulture("")]
15 |
16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
19 |
20 | [assembly: AssemblyVersion("4.1.0.31")]
21 |
22 | // The following attributes are used to specify the signing key for the assembly,
23 | // if desired. See the Mono documentation for more information about signing.
24 |
25 | // [assembly: AssemblyDelaySign(false)]
26 | // [assembly: AssemblyKeyFile("ZeroMQ.snk")]
27 |
28 |
--------------------------------------------------------------------------------
/Devices/PubSubDevice.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Devices
2 | {
3 | using System;
4 |
5 | ///
6 | /// Device for a Publisher and Subscribers
7 | ///
8 | public class PubSubDevice : ZDevice
9 | {
10 | ///
11 | /// The frontend for a forwarder device.
12 | ///
13 | public static readonly ZSocketType FrontendType = ZSocketType.XSUB;
14 |
15 | ///
16 | /// The backend for a forwarder device.
17 | ///
18 | public static readonly ZSocketType BackendType = ZSocketType.XPUB;
19 |
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | public PubSubDevice() : this(ZContext.Current) { }
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | public PubSubDevice(ZContext context)
29 | : base(context, FrontendType, BackendType)
30 | {
31 | BackendSetup.SubscribeAll();
32 | }
33 |
34 | ///
35 | /// Initializes a new instance of the class.
36 | ///
37 | public PubSubDevice(string frontendBindAddr, string backendBindAddr)
38 | : this(ZContext.Current, frontendBindAddr, backendBindAddr)
39 | { }
40 |
41 | ///
42 | /// Initializes a new instance of the class.
43 | ///
44 | public PubSubDevice(ZContext context, string frontendBindAddr, string backendBindAddr)
45 | : base(context, FrontendType, BackendType)
46 | {
47 | FrontendSetup.Bind(frontendBindAddr);
48 | BackendSetup.Bind(backendBindAddr);
49 | BackendSetup.SubscribeAll();
50 | }
51 |
52 | ///
53 | /// Forwards requests from the frontend socket to the backend socket.
54 | ///
55 | protected override bool FrontendHandler(ZSocket socket, out ZMessage message, out ZError error)
56 | {
57 | return FrontendSocket.Forward(BackendSocket, out message, out error);
58 | }
59 |
60 | ///
61 | /// PubSub Forwards the Subscription messages
62 | ///
63 | protected override bool BackendHandler(ZSocket args, out ZMessage message, out ZError error)
64 | {
65 | return BackendSocket.Forward(FrontendSocket, out message, out error);
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/Devices/PushPullDevice.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Devices
2 | {
3 | using System;
4 |
5 | ///
6 | /// Queuing Push-Pull Device
7 | ///
8 | public class PushPullDevice : ZDevice
9 | {
10 | ///
11 | /// The frontend for a streamer device.
12 | ///
13 | public static readonly ZSocketType FrontendType = ZSocketType.PULL;
14 |
15 | ///
16 | /// The backend for a streamer device.
17 | ///
18 | public static readonly ZSocketType BackendType = ZSocketType.PUSH;
19 |
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | public PushPullDevice() : this(ZContext.Current) { }
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | public PushPullDevice(ZContext context)
29 | : base(context, FrontendType, BackendType)
30 | { }
31 |
32 | ///
33 | /// Initializes a new instance of the class.
34 | ///
35 | public PushPullDevice(string frontendBindAddr, string backendBindAddr)
36 | : this(ZContext.Current, frontendBindAddr, backendBindAddr)
37 | { }
38 |
39 | ///
40 | /// Initializes a new instance of the class.
41 | ///
42 | public PushPullDevice(ZContext context, string frontendBindAddr, string backendBindAddr)
43 | : base(context, FrontendType, BackendType)
44 | {
45 | FrontendSetup.Bind(frontendBindAddr);
46 | BackendSetup.Bind(backendBindAddr);
47 | }
48 |
49 | ///
50 | /// Forwards requests from the frontend socket to the backend socket.
51 | ///
52 | protected override bool FrontendHandler(ZSocket args, out ZMessage message, out ZError error)
53 | {
54 | return FrontendSocket.Forward(BackendSocket, out message, out error);
55 | }
56 |
57 | ///
58 | /// Not implemented for the .
59 | ///
60 | protected override bool BackendHandler(ZSocket args, out ZMessage message, out ZError error)
61 | {
62 | throw new NotSupportedException();
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/Devices/RouterDealerDevice.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Devices
2 | {
3 | ///
4 | /// A Device on Routers and Dealers
5 | ///
6 | public class RouterDealerDevice : ZDevice
7 | {
8 | ///
9 | /// The frontend for a queue device.
10 | ///
11 | public static readonly ZSocketType FrontendType = ZSocketType.ROUTER;
12 |
13 | ///
14 | /// The backend for a queue device.
15 | ///
16 | public static readonly ZSocketType BackendType = ZSocketType.DEALER;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | public RouterDealerDevice() : this(ZContext.Current) { }
22 |
23 | ///
24 | /// Initializes a new instance of the class.
25 | ///
26 | public RouterDealerDevice(ZContext context)
27 | : base(context, FrontendType, BackendType)
28 | { }
29 |
30 | ///
31 | /// Initializes a new instance of the class
32 | /// and binds to the specified Frontend and Backend address.
33 | ///
34 | public RouterDealerDevice(string frontendBindAddr, string backendBindAddr)
35 | : this(ZContext.Current, frontendBindAddr, backendBindAddr)
36 | { }
37 |
38 | ///
39 | /// Initializes a new instance of the class
40 | /// and binds to the specified Frontend and Backend address.
41 | ///
42 | public RouterDealerDevice(ZContext context, string frontendBindAddr, string backendBindAddr)
43 | : base(context, FrontendType, BackendType)
44 | {
45 | FrontendSetup.Bind(frontendBindAddr);
46 | BackendSetup.Bind(backendBindAddr);
47 | }
48 |
49 | ///
50 | /// Forwards requests from the frontend socket to the backend socket.
51 | ///
52 | protected override bool FrontendHandler(ZSocket args, out ZMessage message, out ZError error)
53 | {
54 | return FrontendSocket.Forward(BackendSocket, out message, out error);
55 | }
56 |
57 | ///
58 | /// Forwards replies from the backend socket to the frontend socket.
59 | ///
60 | protected override bool BackendHandler(ZSocket args, out ZMessage message, out ZError error)
61 | {
62 | return BackendSocket.Forward(FrontendSocket, out message, out error);
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitorEventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Monitoring
2 | {
3 | using System;
4 |
5 | ///
6 | /// A base class for the all ZmqMonitor events.
7 | ///
8 | public class ZMonitorEventArgs : EventArgs
9 | {
10 | ///
11 | /// Initializes a new instance of the class.
12 | ///
13 | /// The that triggered the event.
14 | /// The peer address.
15 | public ZMonitorEventArgs(ZMonitor monitor, ZMonitorEventData ed)
16 | {
17 | this.Monitor = monitor;
18 | this.Event = ed;
19 | }
20 |
21 | public ZMonitorEventData Event { get; private set; }
22 |
23 | ///
24 | /// Gets the monitor that triggered the event.
25 | ///
26 | public ZMonitor Monitor { get; private set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitorEventData.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Monitoring
2 | {
3 | using System;
4 |
5 | public struct ZMonitorEventData
6 | {
7 | public ZMonitorEvents Event;
8 | public Int32 EventValue;
9 | public String Address;
10 | }
11 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitorEvents.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Monitoring
2 | {
3 | using System;
4 |
5 | ///
6 | /// Socket transport events (for TCP and IPC sockets) that can be monitored.
7 | ///
8 | [Flags]
9 | public enum ZMonitorEvents
10 | {
11 | ///
12 | /// Triggered when a connection has been established to a remote peer.
13 | ///
14 | Connected = 1,
15 |
16 | ///
17 | /// Triggered when an immediate connection attempt is delayed and it's completion is being polled for.
18 | ///
19 | ConnectDelayed = 2,
20 |
21 | ///
22 | /// Triggered when a connection attempt is being handled by reconnect timer. The reconnect interval is recomputed for each attempt.
23 | ///
24 | ConnectRetried = 4,
25 |
26 | ///
27 | /// Triggered when a socket is successfully bound to a an interface.
28 | ///
29 | Listening = 8,
30 |
31 | ///
32 | /// Triggered when a socket could not bind to a given interface.
33 | ///
34 | BindFailed = 16,
35 |
36 | ///
37 | /// Triggered when a connection from a remote peer has been established with a socket's listen address.
38 | ///
39 | Accepted = 32,
40 |
41 | ///
42 | /// Triggered when a connection attempt to a socket's bound address fails.
43 | ///
44 | AcceptFailed = 64,
45 |
46 | ///
47 | /// Triggered when a connection's underlying descriptor has been closed.
48 | ///
49 | Closed = 128,
50 |
51 | ///
52 | /// Triggered when a descriptor could not be released back to the OS.
53 | ///
54 | CloseFailed = 256,
55 |
56 | ///
57 | /// Triggered when the stream engine (tcp and ipc specific) detects a corrupted / broken session.
58 | ///
59 | Disconnected = 512,
60 |
61 | ///
62 | /// Monitoring on this socket ended.
63 | ///
64 | Stopped = 1024,
65 |
66 | ///
67 | /// Any event, maybe readable from EventValue.
68 | ///
69 | AllEvents = 0xFFFF
70 | }
71 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitorFileDescriptorEventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Monitoring
2 | {
3 | using System;
4 | using lib;
5 |
6 | ///
7 | /// Provides data for , , , and events.
8 | ///
9 | public class ZMonitorFileDescriptorEventArgs : ZMonitorEventArgs
10 | {
11 | internal ZMonitorFileDescriptorEventArgs(ZMonitor monitor, ZMonitorEventData data)
12 | : base(monitor, data)
13 | {
14 | if (Platform.Kind == PlatformKind.Posix)
15 | {
16 | this.FileDescriptor_Posix = data.EventValue;
17 | }
18 | else if (Platform.Kind == PlatformKind.Win32)
19 | {
20 | this.FileDescriptor_Windows = new IntPtr(data.EventValue);
21 | }
22 | else
23 | {
24 | throw new PlatformNotSupportedException();
25 | }
26 | }
27 |
28 | ///
29 | /// Gets the monitor descriptor (Posix)
30 | ///
31 | public int FileDescriptor_Posix { get; private set; }
32 |
33 | ///
34 | /// Gets the monitor descriptor (Windows)
35 | ///
36 | public IntPtr FileDescriptor_Windows { get; private set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitorIntervalEventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.Monitoring
2 | {
3 | ///
4 | /// Provides data for event.
5 | ///
6 | public class ZMonitorIntervalEventArgs : ZMonitorEventArgs
7 | {
8 | internal ZMonitorIntervalEventArgs(ZMonitor monitor, ZMonitorEventData data)
9 | : base(monitor, data)
10 | {
11 | this.Interval = data.EventValue;
12 | }
13 |
14 | ///
15 | /// Gets the computed reconnect interval.
16 | ///
17 | public int Interval { get; private set; }
18 | }
19 | }
--------------------------------------------------------------------------------
/Monitoring/ZMonitors.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | using ZeroMQ.lib;
5 |
6 | namespace ZeroMQ.Monitoring
7 | {
8 |
9 | ///
10 | /// Defines extension methods related to monitoring for instances.
11 | ///
12 | public static class ZMonitors
13 | {
14 | ///
15 | /// Spawns a socket that publishes all events for
16 | /// the specified socket over the inproc transport at the given endpoint.
17 | ///
18 | public static bool Monitor(this ZSocket socket, string endpoint)
19 | {
20 | ZError error;
21 | if (!Monitor(socket, endpoint, ZMonitorEvents.AllEvents, out error))
22 | {
23 | throw new ZException(error);
24 | }
25 | return true;
26 | }
27 |
28 | ///
29 | /// Spawns a socket that publishes all events for
30 | /// the specified socket over the inproc transport at the given endpoint.
31 | ///
32 | public static bool Monitor(this ZSocket socket, string endpoint, out ZError error)
33 | {
34 | return Monitor(socket, endpoint, ZMonitorEvents.AllEvents, out error);
35 | }
36 |
37 | ///
38 | /// Spawns a socket that publishes all events for
39 | /// the specified socket over the inproc transport at the given endpoint.
40 | ///
41 | public static bool Monitor(this ZSocket socket, string endpoint, ZMonitorEvents eventsToMonitor)
42 | {
43 | ZError error;
44 | if (!Monitor(socket, endpoint, eventsToMonitor, out error))
45 | {
46 | throw new ZException(error);
47 | }
48 | return true;
49 | }
50 |
51 | ///
52 | /// Spawns a socket that publishes all events for
53 | /// the specified socket over the inproc transport at the given endpoint.
54 | ///
55 | public static bool Monitor(this ZSocket socket, string endpoint, ZMonitorEvents eventsToMonitor, out ZError error)
56 | {
57 | if (socket == null)
58 | {
59 | throw new ArgumentNullException("socket");
60 | }
61 |
62 | if (endpoint == null)
63 | {
64 | throw new ArgumentNullException("endpoint");
65 | }
66 |
67 | if (endpoint == string.Empty)
68 | {
69 | throw new ArgumentException("Unable to publish socket events to an empty endpoint.", "endpoint");
70 | }
71 |
72 | error = ZError.None;
73 |
74 | using (var endpointPtr = DispoIntPtr.AllocString(endpoint))
75 | {
76 | while (-1 == zmq.socket_monitor(socket.SocketPtr, endpointPtr, (Int32)eventsToMonitor))
77 | {
78 | error = ZError.GetLastErr();
79 |
80 | if (error == ZError.EINTR)
81 | {
82 | error = default(ZError);
83 | continue;
84 | }
85 |
86 | return false;
87 | }
88 | }
89 | return true;
90 | }
91 | }
92 | }
--------------------------------------------------------------------------------
/Platform/DispoIntPtr.Ansi.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 |
3 | namespace ZeroMQ.lib
4 | {
5 | using System;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Runtime.InteropServices;
9 |
10 | internal sealed partial class DispoIntPtr : IDisposable
11 | {
12 | public static class Ansi
13 | {
14 | unsafe internal static DispoIntPtr AllocStringNative(string str, out int byteCount)
15 | {
16 | // use builtin allocation
17 | var dispPtr = new DispoIntPtr();
18 | dispPtr._ptr = Marshal.StringToHGlobalAnsi(str);
19 | dispPtr.isAllocated = true;
20 |
21 | byteCount = Encoding.Default.GetByteCount(str);
22 | return dispPtr; /**/
23 |
24 | /* use encoding or Encoding.Default ( system codepage of ANSI )
25 | var enc = Encoding.Default.GetEncoder();
26 |
27 | // var encoded = new byte[length];
28 | // Marshal.Copy(encoded, 0, dispPtr._ptr, length);
29 |
30 | IntPtr ptr;
31 | int charCount = str.Length;
32 |
33 | fixed (char* strP = str)
34 | {
35 | byteCount = enc.GetByteCount(strP, charCount, false);
36 |
37 | ptr = Marshal.AllocHGlobal(byteCount + 1);
38 |
39 | enc.GetBytes(strP, charCount, (byte*)ptr, byteCount, true);
40 |
41 | *((byte*)ptr + byteCount) = 0x00;
42 | }
43 |
44 | var dispPtr = new DispoIntPtr ();
45 | dispPtr._ptr = ptr;
46 | dispPtr.isAllocated = true;
47 |
48 | // and a C char 0x00 terminator
49 | // Marshal.WriteByte(dispPtr._ptr + length, byte.MinValue);
50 | // *((byte*)dispPtr._ptr + length) = 0x00;
51 |
52 | return dispPtr; /**/
53 | }
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Platform/DispoIntPtr.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 |
3 | namespace ZeroMQ.lib
4 | {
5 | using System;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Runtime.InteropServices;
9 |
10 | internal sealed partial class DispoIntPtr : IDisposable
11 | {
12 | private delegate DispoIntPtr AllocStringNativeDelegate(string str, out int byteCount);
13 |
14 | private static readonly AllocStringNativeDelegate AllocStringNative = Ansi.AllocStringNative;
15 |
16 | /* static DispoIntPtr() {
17 | // Platform.SetupPlatformImplementation(typeof(DispoIntPtr));
18 | } */
19 |
20 | public static DispoIntPtr Alloc(int size)
21 | {
22 | var dispPtr = new DispoIntPtr();
23 | dispPtr._ptr = Marshal.AllocHGlobal(size);
24 | dispPtr.isAllocated = true;
25 | return dispPtr;
26 | }
27 |
28 | public static DispoIntPtr AllocString(string str)
29 | {
30 | int byteCount;
31 | return AllocString(str, out byteCount);
32 | }
33 |
34 | public static DispoIntPtr AllocString(string str, out int byteCount)
35 | {
36 | return AllocStringNative(str, out byteCount);
37 | }
38 |
39 | public static implicit operator IntPtr(DispoIntPtr dispoIntPtr)
40 | {
41 | return dispoIntPtr == null ? IntPtr.Zero : dispoIntPtr._ptr;
42 | }
43 |
44 | unsafe public static explicit operator void*(DispoIntPtr dispoIntPtr)
45 | {
46 | return dispoIntPtr == null ? (void*)null : (void*)dispoIntPtr._ptr;
47 | }
48 |
49 | unsafe public static explicit operator byte*(DispoIntPtr dispoIntPtr)
50 | {
51 | return dispoIntPtr == null ? (byte*)null : (byte*)dispoIntPtr._ptr;
52 | }
53 |
54 | unsafe public static explicit operator sbyte*(DispoIntPtr dispoIntPtr)
55 | {
56 | return dispoIntPtr == null ? (sbyte*)null : (sbyte*)dispoIntPtr._ptr;
57 | }
58 |
59 | unsafe public static explicit operator short*(DispoIntPtr dispoIntPtr)
60 | {
61 | return dispoIntPtr == null ? (short*)null : (short*)dispoIntPtr._ptr;
62 | }
63 |
64 | unsafe public static explicit operator ushort*(DispoIntPtr dispoIntPtr)
65 | {
66 | return dispoIntPtr == null ? (ushort*)null : (ushort*)dispoIntPtr._ptr;
67 | }
68 |
69 | unsafe public static explicit operator char*(DispoIntPtr dispoIntPtr)
70 | {
71 | return dispoIntPtr == null ? (char*)null : (char*)dispoIntPtr._ptr;
72 | }
73 |
74 | unsafe public static explicit operator int*(DispoIntPtr dispoIntPtr)
75 | {
76 | return dispoIntPtr == null ? (int*)null : (int*)dispoIntPtr._ptr;
77 | }
78 |
79 | unsafe public static explicit operator uint*(DispoIntPtr dispoIntPtr)
80 | {
81 | return dispoIntPtr == null ? (uint*)null : (uint*)dispoIntPtr._ptr;
82 | }
83 |
84 | unsafe public static explicit operator long*(DispoIntPtr dispoIntPtr)
85 | {
86 | return dispoIntPtr == null ? (long*)null : (long*)dispoIntPtr._ptr;
87 | }
88 |
89 | unsafe public static explicit operator ulong*(DispoIntPtr dispoIntPtr)
90 | {
91 | return dispoIntPtr == null ? (ulong*)null : (ulong*)dispoIntPtr._ptr;
92 | }
93 |
94 | private bool isAllocated;
95 |
96 | private IntPtr _ptr;
97 |
98 | public IntPtr Ptr
99 | {
100 | get { return _ptr; }
101 | }
102 |
103 | internal DispoIntPtr() { }
104 |
105 | ~DispoIntPtr()
106 | {
107 | Dispose(false);
108 | }
109 |
110 | public void Dispose()
111 | {
112 | Dispose(true);
113 | GC.SuppressFinalize(this);
114 | }
115 |
116 | void Dispose(bool disposing)
117 | {
118 | // TODO: instance ThreadStatic && do ( o == null ? return : ( lock(o, ms), check threadId, .. ) )
119 | IntPtr handle = _ptr;
120 | if (handle != IntPtr.Zero)
121 | {
122 | if (isAllocated)
123 | {
124 | Marshal.FreeHGlobal(handle);
125 | isAllocated = false;
126 | }
127 | _ptr = IntPtr.Zero;
128 | }
129 | }
130 |
131 | /* public void ReAlloc(long size) {
132 | _ptr = Marshal.ReAllocHGlobal(_ptr, new IntPtr(size));
133 | } */
134 | }
135 | }
--------------------------------------------------------------------------------
/Platform/Platform.MacOSX.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.lib
2 | {
3 |
4 | public static partial class Platform
5 | {
6 | public static class MacOSX
7 | {
8 |
9 | // public const string LibraryFileExtension = ".dylib";
10 |
11 | public static readonly string[] LibraryPaths = new string[] {
12 | "/lib/{LibraryName}*.dylib",
13 | "/lib/{LibraryName}*.dylib.*",
14 | "/usr/lib/{LibraryName}*.dylib",
15 | "/usr/lib/{LibraryName}*.dylib.*",
16 | "/usr/local/lib/{LibraryName}*.dylib",
17 | "/usr/local/lib/{LibraryName}*.dylib.*",
18 | "{DllPath}/{LibraryName}*.dylib",
19 | "{DllPath}/{LibraryName}*.dylib.*",
20 | "{Path}/{LibraryName}*.dylib",
21 | "{Path}/{LibraryName}*.dylib.*",
22 | "{AppBase}/{Arch}/{LibraryName}*.dylib",
23 | "{AppBase}/{Arch}/{LibraryName}*.dylib.*",
24 | };
25 |
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Platform/Platform.__Internal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | /* Example: sqlite3.cs
5 |
6 | using System;
7 | using System.Runtime.InteropServices;
8 |
9 | namespace lib
10 | {
11 | public static unsafe class sqlite3
12 | {
13 | private const string __Internal = "__Internal";
14 |
15 | private const CallingConvention CCCdecl = CallingConvention.Cdecl;
16 |
17 | // Use a const for the library name
18 | private const string LibraryName = "sqlite3";
19 |
20 | // Hold a handle to the static instance
21 | private static readonly UnmanagedLibrary NativeLib;
22 |
23 | // The static constructor prepares static readonly fields
24 | static sqlite3()
25 | {
26 | // (0) Initialize Library handle
27 | NativeLib = Platform.LoadUnmanagedLibrary(LibraryName);
28 |
29 | // (1) Initialize Platform information
30 | Platform.SetupImplementation(typeof(sqlite3));
31 |
32 | // Set once LibVersion to libversion()
33 | LibVersion = Marshal.PtrToStringAnsi(libversion());
34 | }
35 |
36 | // (2) Declare privately the extern entry point
37 | [DllImport(LibraryName, EntryPoint = "sqlite3_libversion", CallingConvention = CCCdecl)]
38 | private static extern IntPtr sqlite3_libversion();
39 | [DllImport(__Internal, EntryPoint = "sqlite3_libversion", CallingConvention = CCCdecl)]
40 | private static extern IntPtr sqlite3_libversion__Internal();
41 |
42 | // (3) Describe the extern function using a delegate
43 | public delegate IntPtr sqlite3_libversion_delegate ();
44 |
45 | // (4) Save and return the managed delegate to the unmanaged function
46 | // This static readonly field definition allows to be
47 | // initialized and possibly redirected by the static constructor.
48 | //
49 | // By default this is set to the extern function declaration,
50 | // it may be set to the __Internal extern function declaration.
51 | public static readonly sqlite3_libversion_delegate libversion = sqlite3_libversion;
52 |
53 | // Static LibVersion
54 | public static readonly Version LibVersion;
55 |
56 | }
57 | }
58 |
59 | */
60 |
61 | namespace ZeroMQ.lib
62 | {
63 | public static partial class Platform
64 | {
65 | public static class __Internal
66 | {
67 | public static UnmanagedLibrary LoadUnmanagedLibrary(string libraryName)
68 | {
69 | return null;
70 | }
71 |
72 | public static SafeLibraryHandle OpenHandle(string fileName)
73 | {
74 | throw new NotSupportedException();
75 | }
76 |
77 | public static IntPtr LoadProcedure(SafeLibraryHandle libHandle, string functionName)
78 | {
79 | throw new NotSupportedException();
80 | }
81 |
82 | public static bool ReleaseHandle(IntPtr handle)
83 | {
84 | throw new NotSupportedException();
85 | }
86 |
87 | public static Exception GetLastLibraryError()
88 | {
89 | return new NotSupportedException();
90 | }
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/Platform/UnmanagedLibrary.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.lib
2 | {
3 | using System;
4 | using System.Diagnostics;
5 | using System.IO;
6 | using System.Reflection;
7 | using System.Runtime.InteropServices;
8 | using System.Security.Permissions;
9 |
10 | ///
11 | /// Safe handle for unmanaged libraries. See http://msdn.microsoft.com/msdnmag/issues/05/10/Reliability/ for more about safe handles.
12 | ///
13 | [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
14 | public sealed class SafeLibraryHandle
15 | : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
16 | {
17 | private SafeLibraryHandle()
18 | : base(true)
19 | { }
20 |
21 | protected override bool ReleaseHandle()
22 | {
23 | return Platform.ReleaseHandle(handle);
24 | }
25 | }
26 |
27 | internal static class SafeLibraryHandles
28 | {
29 | public static bool IsNullOrInvalid(this SafeLibraryHandle handle)
30 | {
31 | return handle == null || handle.IsInvalid;
32 | }
33 | }
34 |
35 | ///
36 | /// Utility class to wrap an unmanaged shared lib and be responsible for freeing it.
37 | ///
38 | ///
39 | /// This is a managed wrapper over the native LoadLibrary, GetProcAddress, and FreeLibrary calls on Windows
40 | /// and dlopen, dlsym, and dlclose on Posix environments.
41 | ///
42 | public sealed class UnmanagedLibrary : IDisposable
43 | {
44 | private readonly string TraceLabel;
45 |
46 | private readonly SafeLibraryHandle _handle;
47 |
48 | internal UnmanagedLibrary(string libraryName, SafeLibraryHandle libraryHandle)
49 | {
50 | if (string.IsNullOrWhiteSpace(libraryName))
51 | {
52 | throw new ArgumentException("A valid library name is expected.", "libraryName");
53 | }
54 | if (libraryHandle.IsNullOrInvalid())
55 | {
56 | throw new ArgumentNullException("libraryHandle");
57 | }
58 |
59 | TraceLabel = string.Format("UnmanagedLibrary[{0}]", libraryName);
60 |
61 | _handle = libraryHandle;
62 | }
63 |
64 | ///
65 | /// Dynamically look up a function in the dll via kernel32!GetProcAddress or libdl!dlsym.
66 | ///
67 | /// Delegate type to load
68 | /// Raw name of the function in the export table.
69 | /// A delegate to the unmanaged function.
70 | /// Thrown if the given function name is not found in the library.
71 | ///
72 | /// GetProcAddress results are valid as long as the dll is not yet unloaded. This
73 | /// is very very dangerous to use since you need to ensure that the dll is not unloaded
74 | /// until after you're done with any objects implemented by the dll. For example, if you
75 | /// get a delegate that then gets an IUnknown implemented by this dll,
76 | /// you can not dispose this library until that IUnknown is collected. Else, you may free
77 | /// the library and then the CLR may call release on that IUnknown and it will crash.
78 | ///
79 | public TDelegate GetUnmanagedFunction(string functionName) where TDelegate : class
80 | {
81 | IntPtr p = Platform.LoadProcedure(_handle, functionName);
82 |
83 | if (p == IntPtr.Zero)
84 | {
85 | throw new MissingMethodException("Unable to find function '" + functionName + "' in dynamically loaded library.");
86 | }
87 |
88 | // Ideally, we'd just make the constraint on TDelegate be
89 | // System.Delegate, but compiler error CS0702 (constrained can't be System.Delegate)
90 | // prevents that. So we make the constraint system.object and do the cast from object-->TDelegate.
91 | return (TDelegate)(object)Marshal.GetDelegateForFunctionPointer(p, typeof(TDelegate));
92 | }
93 |
94 | public void Dispose()
95 | {
96 | if (_handle != null && !_handle.IsClosed)
97 | {
98 | _handle.Close();
99 | }
100 | }
101 |
102 | }
103 | }
--------------------------------------------------------------------------------
/Platform/zmq_pollitem_posix_t.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.lib
2 | {
3 | using System;
4 | using System.Runtime.InteropServices;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct zmq_pollitem_posix_t // : zmq_pollitem_i
8 | {
9 | private IntPtr socketPtr;
10 | private int fileDescriptor; // POSIX fd is an Int32
11 | private short events;
12 | private short readyEvents;
13 |
14 | public zmq_pollitem_posix_t(IntPtr socket, ZPoll pollEvents)
15 | {
16 | if (socket == IntPtr.Zero)
17 | {
18 | throw new ArgumentException("Expected a valid socket handle.", "socket");
19 | }
20 |
21 | socketPtr = socket;
22 | fileDescriptor = 0;
23 | events = (short)pollEvents;
24 | readyEvents = (short)ZPoll.None;
25 | }
26 |
27 | public IntPtr SocketPtr
28 | {
29 | get { return socketPtr; }
30 | set { socketPtr = value; }
31 | }
32 |
33 | public int FileDescriptor
34 | {
35 | get { return fileDescriptor; }
36 | set { fileDescriptor = value; }
37 | }
38 |
39 | public short Events
40 | {
41 | get { return events; }
42 | set { events = value; }
43 | }
44 |
45 | public short ReadyEvents
46 | {
47 | get { return readyEvents; }
48 | set { readyEvents = value; }
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/Platform/zmq_pollitem_windows_t.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ.lib
2 | {
3 | using System;
4 | using System.Runtime.InteropServices;
5 |
6 | [StructLayout(LayoutKind.Sequential)]
7 | public struct zmq_pollitem_windows_t // : zmq_pollitem_i
8 | {
9 | private IntPtr socketPtr;
10 | private IntPtr fileDescriptor; // Windows is an size_t
11 | private short events;
12 | private short readyEvents;
13 |
14 | public zmq_pollitem_windows_t(IntPtr socket, ZPoll pollEvents)
15 | {
16 | if (socket == IntPtr.Zero)
17 | {
18 | throw new ArgumentException("Expected a valid socket handle.", "socket");
19 | }
20 |
21 | socketPtr = socket;
22 | fileDescriptor = IntPtr.Zero;
23 | events = (short)pollEvents;
24 | readyEvents = 0;
25 | }
26 |
27 | public IntPtr SocketPtr
28 | {
29 | get { return socketPtr; }
30 | set { socketPtr = value; }
31 | }
32 |
33 | public IntPtr FileDescriptor
34 | {
35 | get { return fileDescriptor; }
36 | set { fileDescriptor = value; }
37 | }
38 |
39 | public short Events
40 | {
41 | get { return events; }
42 | set { events = value; }
43 | }
44 |
45 | public short ReadyEvents
46 | {
47 | get { return readyEvents; }
48 | set { readyEvents = value; }
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/RouterMandatory.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ
2 | {
3 | ///
4 | /// Specifies socket behavior when
5 | /// an unroutable message is encountered.
6 | ///
7 | public enum RouterMandatory
8 | {
9 | ///
10 | /// Silently discard messages.
11 | ///
12 | Discard = 0,
13 |
14 | ///
15 | /// Force sending to fail with an 'EAGAIN' error code, effectively
16 | /// enabling blocking sends.
17 | ///
18 | Report = 1,
19 | }
20 | }
--------------------------------------------------------------------------------
/TcpKeepaliveBehaviour.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ
2 | {
3 | ///
4 | /// Keep-alive packets behavior for a connection.
5 | ///
6 | public enum TcpKeepaliveBehaviour : int
7 | {
8 | ///
9 | /// Use Operating System default behavior.
10 | ///
11 | Default = -1,
12 |
13 | ///
14 | /// Disable keep-alive packets.
15 | ///
16 | Disable = 0,
17 |
18 | ///
19 | /// Enable keep-alive packets.
20 | ///
21 | Enable = 1,
22 | }
23 | }
--------------------------------------------------------------------------------
/Z85.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using System.Text;
4 | using ZeroMQ.lib;
5 |
6 | namespace ZeroMQ
7 | {
8 | public static class Z85
9 | {
10 | public static void CurveKeypair(out byte[] publicKey, out byte[] secretKey)
11 | {
12 | const int destLen = 40;
13 | using (var publicKeyData = DispoIntPtr.Alloc(destLen + 1))
14 | using (var secretKeyData = DispoIntPtr.Alloc(destLen + 1))
15 | {
16 | if (0 != zmq.curve_keypair(publicKeyData, secretKeyData))
17 | {
18 | throw new InvalidOperationException();
19 | }
20 |
21 | publicKey = new byte[destLen];
22 | Marshal.Copy(publicKeyData, publicKey, 0, destLen);
23 |
24 | secretKey = new byte[destLen];
25 | Marshal.Copy(secretKeyData, secretKey, 0, destLen);
26 | }
27 | }
28 |
29 | public static byte[] Encode(byte[] decoded)
30 | {
31 | int dataLen = decoded.Length;
32 | if (dataLen % 4 > 0)
33 | {
34 | throw new InvalidOperationException("decoded.Length must be divisible by 4");
35 | }
36 | int destLen = (Int32)(decoded.Length * 1.25);
37 |
38 | var data = GCHandle.Alloc(decoded, GCHandleType.Pinned);
39 |
40 | // the buffer dest must be one byte larger than destLen to accomodate the null termination character
41 | using (var dest = DispoIntPtr.Alloc(destLen + 1))
42 | {
43 | zmq.z85_encode(dest, data.AddrOfPinnedObject(), dataLen);
44 | data.Free();
45 |
46 | var bytes = new byte[destLen];
47 | Marshal.Copy(dest, bytes, 0, destLen);
48 | return bytes;
49 | }
50 | }
51 |
52 | public static byte[] ToZ85Encoded(this byte[] decoded)
53 | {
54 | return Encode(decoded);
55 | }
56 |
57 | public static string ToZ85Encoded(this string decoded)
58 | {
59 | return Encode(decoded, ZContext.Encoding);
60 | }
61 |
62 | public static string ToZ85Encoded(this string decoded, Encoding encoding)
63 | {
64 | return Encode(decoded, encoding);
65 | }
66 |
67 | public static byte[] ToZ85EncodedBytes(this string decoded)
68 | {
69 | return EncodeBytes(decoded, ZContext.Encoding);
70 | }
71 |
72 | public static byte[] ToZ85EncodedBytes(this string decoded, Encoding encoding)
73 | {
74 | return EncodeBytes(decoded, encoding);
75 | }
76 |
77 | public static string Encode(string strg)
78 | {
79 | return Encode(strg, ZContext.Encoding);
80 | }
81 |
82 | public static string Encode(string strg, Encoding encoding)
83 | {
84 | byte[] encoded = EncodeBytes(strg, encoding);
85 | return encoding.GetString(encoded);
86 | }
87 |
88 | public static byte[] EncodeBytes(string strg)
89 | {
90 | return EncodeBytes(strg, ZContext.Encoding);
91 | }
92 |
93 | public static byte[] EncodeBytes(string strg, Encoding encoding)
94 | {
95 | byte[] bytes = encoding.GetBytes(strg);
96 | return Encode(bytes);
97 | }
98 |
99 |
100 | public static byte[] Decode(byte[] encoded)
101 | {
102 | int dataLen = encoded.Length;
103 | if (dataLen % 5 > 0)
104 | {
105 | throw new InvalidOperationException("encoded.Length must be divisible by 5");
106 | }
107 | int destLen = (Int32)(encoded.Length * .8);
108 |
109 | var data = GCHandle.Alloc(encoded, GCHandleType.Pinned);
110 |
111 | using (var dest = DispoIntPtr.Alloc(destLen))
112 | {
113 | zmq.z85_decode(dest, data.AddrOfPinnedObject());
114 | data.Free();
115 |
116 | var decoded = new byte[destLen];
117 |
118 | Marshal.Copy(dest, decoded, 0, decoded.Length);
119 |
120 | return decoded;
121 | }
122 | }
123 |
124 | public static byte[] ToZ85Decoded(this byte[] encoded)
125 | {
126 | return Decode(encoded);
127 | }
128 |
129 | public static string ToZ85Decoded(this string encoded)
130 | {
131 | return Decode(encoded, ZContext.Encoding);
132 | }
133 |
134 | public static string ToZ85Decoded(this string encoded, Encoding encoding)
135 | {
136 | return Decode(encoded, encoding);
137 | }
138 |
139 | public static byte[] ToZ85DecodedBytes(this string encoded)
140 | {
141 | return DecodeBytes(encoded, ZContext.Encoding);
142 | }
143 |
144 | public static byte[] ToZ85DecodedBytes(this string encoded, Encoding encoding)
145 | {
146 | return DecodeBytes(encoded, encoding);
147 | }
148 |
149 | public static string Decode(string strg)
150 | {
151 | return Decode(strg, ZContext.Encoding);
152 | }
153 |
154 | public static string Decode(string strg, Encoding encoding)
155 | {
156 | byte[] encoded = DecodeBytes(strg, encoding);
157 | return encoding.GetString(encoded);
158 | }
159 |
160 | public static byte[] DecodeBytes(string strg, Encoding encoding)
161 | {
162 | byte[] bytes = encoding.GetBytes(strg);
163 | return Decode(bytes);
164 | }
165 | }
166 | }
167 |
168 |
--------------------------------------------------------------------------------
/ZActor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ZeroMQ
4 | {
5 | public delegate void ZAction0(ZSocket backend, System.Threading.CancellationTokenSource cancellor, object[] args);
6 |
7 | public delegate void ZAction(ZContext context, ZSocket backend, System.Threading.CancellationTokenSource cancellor, object[] args);
8 |
9 | public class ZActor : ZThread
10 | {
11 | public ZContext Context { get; protected set; }
12 |
13 | public string Endpoint { get; protected set; }
14 |
15 | public ZAction Action { get; protected set; }
16 |
17 | public ZAction0 Action0 { get; protected set; }
18 |
19 | public object[] Arguments { get; protected set; }
20 |
21 | public ZSocket Backend { get; protected set; }
22 |
23 | public ZSocket Frontend { get; protected set; }
24 |
25 | public ZActor(ZContext context, ZAction action, params object[] args)
26 | : this(context, default(string), action, args)
27 | {
28 | var rnd0 = new byte[8];
29 | using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) rng.GetNonZeroBytes(rnd0);
30 | this.Endpoint = string.Format("inproc://{0}", ZContext.Encoding.GetString(rnd0));
31 | }
32 |
33 | public ZActor(ZContext context, string endpoint, ZAction action, params object[] args)
34 | : base()
35 | {
36 | this.Context = context;
37 |
38 | this.Endpoint = endpoint;
39 | this.Action = action;
40 | this.Arguments = args;
41 | }
42 |
43 | ///
44 | /// You are using ZContext.Current!
45 | ///
46 | public ZActor(ZAction0 action, params object[] args)
47 | : this(default(string), action, args)
48 | {
49 | var rnd0 = new byte[8];
50 | using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) rng.GetNonZeroBytes(rnd0);
51 | this.Endpoint = string.Format("inproc://{0}", ZContext.Encoding.GetString(rnd0));
52 | }
53 |
54 | ///
55 | /// You are using ZContext.Current!
56 | ///
57 | public ZActor(string endpoint, ZAction0 action, params object[] args)
58 | : base()
59 | {
60 | this.Context = ZContext.Current;
61 |
62 | this.Endpoint = endpoint;
63 | this.Action0 = action;
64 | this.Arguments = args;
65 | }
66 |
67 | protected override void Run()
68 | {
69 | using (Backend = ZSocket.Create(Context, ZSocketType.PAIR))
70 | {
71 | Backend.Bind(Endpoint);
72 |
73 | if (Action0 != null)
74 | {
75 | Action0(Backend, Cancellor, Arguments);
76 | }
77 | if (Action != null)
78 | {
79 | Action(Context, Backend, Cancellor, Arguments);
80 | }
81 | }
82 | }
83 |
84 | public override void Start()
85 | {
86 | base.Start();
87 |
88 | if (Frontend == null)
89 | {
90 | Frontend = ZSocket.Create(Context, ZSocketType.PAIR);
91 | Frontend.Connect(Endpoint);
92 | }
93 | }
94 |
95 | protected override void Dispose(bool disposing)
96 | {
97 | base.Dispose(disposing);
98 |
99 | if (disposing)
100 | {
101 | if (Frontend != null)
102 | {
103 | Frontend.Dispose();
104 | Frontend = null;
105 | }
106 | if (Backend != null)
107 | {
108 | Backend.Dispose();
109 | Backend = null;
110 | }
111 | }
112 | }
113 | }
114 | }
--------------------------------------------------------------------------------
/ZContextOption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Runtime.InteropServices;
6 |
7 | namespace ZeroMQ
8 | {
9 | public enum ZContextOption : int
10 | {
11 | IO_THREADS = 1,
12 | MAX_SOCKETS = 2,
13 | SOCKET_LIMIT = 3,
14 | THREAD_PRIORITY = 3,
15 | THREAD_SCHED_POLICY = 4,
16 | IPV6 = 42 // in zmq.h ZMQ_IPV6 is in the socket options section
17 | }
18 | }
--------------------------------------------------------------------------------
/ZException.cs:
--------------------------------------------------------------------------------
1 | namespace ZeroMQ
2 | {
3 | using System;
4 | using System.Runtime.Serialization;
5 |
6 | using lib;
7 | using System.Runtime.InteropServices;
8 |
9 | ///
10 | /// An exception thrown by the result of libzmq.
11 | ///
12 | [Serializable]
13 | public class ZException : Exception
14 | {
15 | private ZError _error;
16 |
17 | ///
18 | /// Gets the error code returned by libzmq.
19 | ///
20 | [Obsolete("Use Error property instead")]
21 | public int ErrNo
22 | {
23 | // TODO why is "0" the default?
24 | get { return _error != null ? _error.Number : 0; }
25 | }
26 | ///
27 | /// Gets the error code returned by libzmq.
28 | ///
29 | [Obsolete("Use Error property instead")]
30 | public string ErrName
31 | {
32 | get
33 | {
34 | return _error != null ? _error.Name : string.Empty;
35 | }
36 | }
37 |
38 | ///
39 | /// Gets the error text returned by libzmq.
40 | ///
41 | [Obsolete("Use Error property instead")]
42 | public string ErrText
43 | {
44 | get
45 | {
46 | return _error != null ? _error.Text : string.Empty;
47 | }
48 | }
49 |
50 | public ZError Error
51 | {
52 | get { return _error; }
53 | }
54 |
55 | ///
56 | /// Initializes a new instance of the class.
57 | ///
58 | /// The error code returned by the ZeroMQ library call.
59 | protected ZException()
60 | { }
61 |
62 | ///
63 | /// Initializes a new instance of the class.
64 | ///
65 | /// The error code returned by the ZeroMQ library call.
66 | public ZException(ZError errorSymbol)
67 | : this(errorSymbol, default(string), default(Exception))
68 | { }
69 |
70 | ///
71 | /// Initializes a new instance of the class.
72 | ///
73 | /// The error code returned by the ZeroMQ library call.
74 | public ZException(ZError errorSymbol, string message)
75 | : this(errorSymbol, message, default(Exception))
76 | { }
77 |
78 | public ZException(ZError errorSymbol, string message, Exception inner)
79 | : base(MakeMessage(errorSymbol, message), inner)
80 | {
81 | this._error = errorSymbol;
82 | }
83 |
84 | static string MakeMessage(ZError error, string additionalMessage)
85 | {
86 | return error != null
87 | ? (string.IsNullOrEmpty(additionalMessage)
88 | ? error.ToString()
89 | : string.Format("{0}: {1}", error, additionalMessage))
90 | : additionalMessage;
91 | }
92 |
93 | public override string ToString()
94 | {
95 | return Message;
96 | }
97 |
98 | ///
99 | /// Initializes a new instance of the class.
100 | ///
101 | /// that holds the serialized object data about the exception being thrown.
102 | /// that contains contextual information about the source or destination.
103 | protected ZException(SerializationInfo info, StreamingContext context)
104 | : base(info, context)
105 | { }
106 |
107 | }
108 | }
--------------------------------------------------------------------------------
/ZFrameOption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Runtime.InteropServices;
6 |
7 | namespace ZeroMQ
8 | {
9 | public enum ZFrameOption : int
10 | {
11 | MORE = 1,
12 | SRCFD = 2,
13 | SHARED = 3,
14 | }
15 | }
--------------------------------------------------------------------------------
/ZGuideExamples/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | // Information about this assembly is defined by the following attributes.
5 | // Change them to the values specific to your project.
6 |
7 | [assembly: AssemblyTitle("ZGuideExamples")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("")]
12 | [assembly: AssemblyCopyright("metadings")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
19 |
20 | [assembly: AssemblyVersion("1.0.*")]
21 |
22 | // The following attributes are used to specify the signing key for the assembly,
23 | // if desired. See the Mono documentation for more information about signing.
24 |
25 | //[assembly: AssemblyDelaySign(false)]
26 | //[assembly: AssemblyKeyFile("")]
27 |
28 |
--------------------------------------------------------------------------------
/ZGuideExamples/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 |
7 | using ZeroMQ;
8 |
9 | namespace Examples
10 | {
11 | static partial class Program
12 | {
13 | // INFO: You will find a "static int Main(string[] args)" in ProgramRunner.cs
14 |
15 | public static bool Verbose = false;
16 |
17 | static void Console_WriteZFrame(string format, ZFrame frame, params object[] data)
18 | {
19 | var renderer = new StringBuilder();
20 |
21 | var list = new List