예제 #1
0
        public ZFrame Duplicate()
        {
            var frame = ZFrame.CreateEmpty();

            this.CopyZeroTo(frame);
            return(frame);
        }
        static bool ReceiveMsg(ZSocket sock, ref ZMessage message, out string address, out ZError error)
        {
            error = ZError.None;
            // address = IPAddress.None;
            address = string.Empty;

            // STREAM: read frames: identity, body

            // read the ip4 address from (ZFrame)frame.GetOption("Peer-Address")

            int receiveCount = 2;

            do
            {
                var frame = ZFrame.CreateEmpty();

                while (-1 == zmq.msg_recv(frame.Ptr, sock.SocketPtr, (int)(/* ZSocketFlags.DontWait | */ ZSocketFlags.More)))
                {
                    error = ZError.GetLastErr();

                    if (error == ZError.EINTR)
                    {
                        error = default(ZError);
                        continue;
                    }

                    frame.Dispose();
                    return(false);
                }

                if (message == null)
                {
                    message = new ZMessage();
                }
                message.Add(frame);

                if (receiveCount == 2)
                {
                    if (default(string) == (address = frame.GetOption("Peer-Address", out error)))
                    {
                        // just ignore
                        error   = default(ZError);
                        address = string.Empty;
                    }
                }
            } while (--receiveCount > 0);

            return(true);
        }
예제 #3
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public bool ReceiveFrames <ListT>(ref int framesToReceive, ref ListT frames, ZSocketFlags flags, out ZError error)
            where ListT : IList <ZFrame>, new()
        {
            EnsureNotDisposed();

            error = default(ZError);
            flags = flags | ZSocketFlags.More;

            do
            {
                var frame = ZFrame.CreateEmpty();

                if (framesToReceive == 1)
                {
                    flags = flags & ~ZSocketFlags.More;
                }

                while (-1 == zmq.msg_recv(frame.Ptr, _socketPtr, (int)flags))
                {
                    error = ZError.GetLastErr();

                    if (error == ZError.EINTR)
                    {
                        error = default(ZError);
                        continue;
                    }

                    frame.Dispose();
                    return(false);
                }

                if (frames == null)
                {
                    frames = new ListT();
                }
                frames.Add(frame);
            } while (--framesToReceive > 0 && this.ReceiveMore);

            return(true);
        }