Skip to content

Commit

Permalink
Update compatibility for libzmq v2.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoz committed Jul 16, 2012
1 parent 0f18fec commit 6dfef9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@
This project aims to provide the full functionality of the underlying ZeroMQ API to CLR projects.

Bundled libzmq version: **3.2.0-rc1**
Legacy libzmq version supported: **2.1.11 (stable)**
Legacy libzmq version supported: **2.2.0 (stable)**

## Getting Started

Expand Down
22 changes: 13 additions & 9 deletions src/ZeroMQ/Interop/LibZmq.NET.cs
Expand Up @@ -38,14 +38,16 @@ static LibZmq()
if (MajorVersion >= 3)
{
zmq_msg_get = NativeLib.GetUnmanagedFunction<ZmqMsgGetProc>("zmq_msg_get");
zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_msg_recv");
zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_msg_send");
zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data");
zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move");

var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_msg_recv");
var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_msg_send");
zmq_msg_send = (msg, sck, flags) => zmq_msg_send_impl(msg, sck, flags);
zmq_msg_recv = (msg, sck, flags) => zmq_msg_recv_impl(msg, sck, flags);

zmq_ctx_new = NativeLib.GetUnmanagedFunction<ZmqCtxNewProc>("zmq_ctx_new");
zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_ctx_destroy");
zmq_ctx_get = NativeLib.GetUnmanagedFunction<ZmqCtxGetProc>("zmq_ctx_get");
zmq_ctx_set = NativeLib.GetUnmanagedFunction<ZmqCtxSetProc>("zmq_ctx_set");

Expand All @@ -56,20 +58,21 @@ static LibZmq()
}
else if (MajorVersion == 2)
{
zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_recv");
zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_send");

var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_recv");
var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_send");
zmq_msg_send = (msg, sck, flags) => zmq_msg_send_impl(sck, msg, flags);
zmq_msg_recv = (msg, sck, flags) => zmq_msg_recv_impl(sck, msg, flags);

var zmq_init = NativeLib.GetUnmanagedFunction<ZmqInitProc>("zmq_init");
zmq_ctx_new = () => zmq_init(1);
zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_term");

PollTimeoutRatio = 1000;
}
}

private static void AssignCommonDelegates()
{
zmq_ctx_new = NativeLib.GetUnmanagedFunction<ZmqCtxNewProc>("zmq_ctx_new");
zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_ctx_destroy");
zmq_close = NativeLib.GetUnmanagedFunction<ZmqCloseProc>("zmq_close");
zmq_setsockopt = NativeLib.GetUnmanagedFunction<ZmqSetSockOptProc>("zmq_setsockopt");
zmq_getsockopt = NativeLib.GetUnmanagedFunction<ZmqGetSockOptProc>("zmq_getsockopt");
Expand Down Expand Up @@ -114,6 +117,9 @@ private static void AssignCurrentVersion(out int majorVersion, out int minorVers
public delegate IntPtr ZmqCtxNewProc();
public static ZmqCtxNewProc zmq_ctx_new;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr ZmqInitProc(int io_threads);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ZmqCtxDestroyProc(IntPtr context);
public static ZmqCtxDestroyProc zmq_ctx_destroy;
Expand Down Expand Up @@ -155,13 +161,11 @@ private static void AssignCurrentVersion(out int majorVersion, out int minorVers
// NOTE: For 2.x, this method signature is (socket, msg, flags)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ZmqMsgRecvProc(IntPtr msg, IntPtr socket, int flags);
private static readonly ZmqMsgRecvProc zmq_msg_recv_impl;
public static ZmqMsgRecvProc zmq_msg_recv;

// NOTE: For 2.x, this method signature is (socket, msg, flags)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ZmqMsgSendProc(IntPtr msg, IntPtr socket, int flags);
private static readonly ZmqMsgSendProc zmq_msg_send_impl;
public static ZmqMsgSendProc zmq_msg_send;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
Expand Down

0 comments on commit 6dfef9f

Please sign in to comment.