Exemple #1
0
        public int Forward(IntPtr destinationHandle)
        {
            if (LibZmq.zmq_msg_init(_message) == -1)
            {
                return(-1);
            }

            int receiveMore;
            int bytesSent;

            do
            {
                if (LibZmq.zmq_recvmsg(SocketHandle, _message, 0) == -1)
                {
                    return(-1);
                }

                if (GetReceiveMore(out receiveMore) == -1)
                {
                    return(-1);
                }

                if ((bytesSent = LibZmq.zmq_sendmsg(destinationHandle, _message, receiveMore == 1 ? (int)SocketFlags.SendMore : 0)) == -1)
                {
                    return(-1);
                }
            }while (receiveMore == 1);

            if (LibZmq.zmq_msg_close(_message) == -1)
            {
                return(-1);
            }

            return(bytesSent);
        }
Exemple #2
0
        public int Init()
        {
            int rc = LibZmq.zmq_msg_init(_ptr);

            _initialized = true;

            return(rc);
        }
Exemple #3
0
        public byte[] Receive(byte[] buffer, int flags, out int size)
        {
            size = -1;

            if (LibZmq.zmq_msg_init(_message) == -1)
            {
                return(buffer);
            }

            int bytesReceived = RetryIfInterrupted(() => LibZmq.zmq_recvmsg(SocketHandle, _message, flags));

            if (bytesReceived >= 0)
            {
                if (bytesReceived == 0 && LibZmq.MajorVersion < 3)
                {
                    // 0MQ 2.x does not return number of bytes received
                    bytesReceived = LibZmq.zmq_msg_size(_message);
                }

                size = bytesReceived;

                if (buffer == null || size > buffer.Length)
                {
                    buffer = new byte[size];
                }

                Marshal.Copy(LibZmq.zmq_msg_data(_message), buffer, 0, size);
            }

            if (LibZmq.zmq_msg_close(_message) == -1)
            {
                size = -1;
            }

            return(buffer);
        }