コード例 #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);
        }
コード例 #2
0
        public int Send(byte[] buffer, int size, int flags)
        {
            if (LibZmq.zmq_msg_init_size(_message, size) == -1)
            {
                return(-1);
            }

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

            int bytesSent = RetryIfInterrupted(() => LibZmq.zmq_sendmsg(SocketHandle, _message, flags));

            if (bytesSent == 0 && LibZmq.MajorVersion < 3)
            {
                // 0MQ 2.x does not report number of bytes sent, so this may be inaccurate/misleading
                bytesSent = size;
            }

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

            return(bytesSent);
        }