Exemplo n.º 1
0
        static LibZmq()
        {
            AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion);

            if (MajorVersion >= 3)
            {
                zmq_msg_recv = zmq_msg_recv_v3;
                zmq_msg_send = zmq_msg_send_v3;

                zmq_buffer_recv = zmq_recvbuf_v3;
                zmq_buffer_send = zmq_sendbuf_v3;

                zmq_msg_get = zmq_msg_get_v3;
                zmq_msg_init_data = zmq_msg_init_data_v3;
                zmq_msg_move = zmq_msg_move_v3;

                zmq_ctx_get = zmq_ctx_get_v3;
                zmq_ctx_set = zmq_ctx_set_v3;
                zmq_socket_monitor = zmq_socket_monitor_v3;

                zmq_unbind = zmq_unbind_v3;
                zmq_disconnect = zmq_disconnect_v3;

                PollTimeoutRatio = 1;
                ZmqMsgTSize = Zmq3MsgTSize;

                zmq_ctx_new = zmq_ctx_new_v3;
                zmq_ctx_destroy = zmq_ctx_destroy_v3;
            }
            else if (MajorVersion == 2)
            {
                zmq_msg_recv = (msg, sck, flags) => zmq_recvmsg(sck, msg, flags);
                zmq_msg_send = (msg, sck, flags) => zmq_sendmsg(sck, msg, flags);

                zmq_buffer_recv = null;
                zmq_buffer_send = null;

                zmq_msg_get = (message, option, optval, optvallen) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 1); };
                zmq_msg_init_data = (msg, data, size, ffn, hint) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 1); };
                zmq_msg_move = (destmsg, srcmsg) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 1); };

                zmq_ctx_get = (ctx, opt) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 2); };
                zmq_ctx_set = (ctx, opt, val) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 2); };
                zmq_socket_monitor = (sck, addr, e) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 2); };

                zmq_unbind = (sck, addr) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 2); };
                zmq_disconnect = (sck, addr) => { throw new ZmqVersionException(MajorVersion, MinorVersion, 3, 2); };

                PollTimeoutRatio = 1000;
                ZmqMsgTSize = Zmq2MsgTSize;

                zmq_ctx_new = () => zmq_init(1);
                zmq_ctx_destroy = zmq_term;
            }
        }
Exemplo n.º 2
-1
        static LibZmq()
        {
            NativeLib = new UnmanagedLibrary(LibData.LibraryName);

            AssignCommonDelegates();
            AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion);

            if (MajorVersion >= 3)
            {
                zmq_msg_get = NativeLib.GetUnmanagedFunction<ZmqMsgGetProc>("zmq_msg_get");
                zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data");
                zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move");

                zmq_msg_recv = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_msg_recv");
                zmq_msg_send = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_msg_send");

                zmq_buffer_recv = NativeLib.GetUnmanagedFunction<ZmqBufferRecvProc>("zmq_recv");
                zmq_buffer_send = NativeLib.GetUnmanagedFunction<ZmqBufferSendProc>("zmq_send");

                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");
                zmq_socket_monitor = NativeLib.GetUnmanagedFunction<ZmqSocketMonitorProc>("zmq_socket_monitor");

                zmq_unbind = NativeLib.GetUnmanagedFunction<ZmqBindProc>("zmq_unbind");
                zmq_disconnect = NativeLib.GetUnmanagedFunction<ZmqConnectProc>("zmq_disconnect");

                PollTimeoutRatio = 1;
                ZmqMsgTSize = Zmq3MsgTSize;
            }
            else if (MajorVersion == 2)
            {
                var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_recv");
                var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_send");
                zmq_msg_recv = (msg, sck, flags) => zmq_msg_recv_impl(sck, msg, flags);
                zmq_msg_send = (msg, sck, flags) => zmq_msg_send_impl(sck, msg, flags);

                zmq_buffer_recv = null;
                zmq_buffer_send = null;

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

                PollTimeoutRatio = 1000;
                ZmqMsgTSize = Zmq2MsgTSize;
            }
        }