예제 #1
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public virtual bool SendFrame(ZFrame frame, ZSocketFlags flags, out ZError error)
        {
            EnsureNotDisposed();

            if (frame.IsDismissed)
            {
                throw new ObjectDisposedException("frame");
            }

            error = default(ZError);

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

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

                return(false);
            }

            // Tell IDisposable to not unallocate zmq_msg
            frame.Dismiss();
            return(true);
        }
예제 #2
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        /// <summary>
        /// Sends HARD bytes from a byte[n]. Please don't use SendBytes, use instead SendFrame.
        /// </summary>
        public bool SendBytes(byte[] buffer, int offset, int count, ZSocketFlags flags, out ZError error)
        {
            EnsureNotDisposed();

            error = ZError.None;

            // int zmq_send (void *socket, void *buf, size_t len, int flags);

            var    pin    = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr pinPtr = pin.AddrOfPinnedObject() + offset;

            int length;

            while (-1 == (length = zmq.send(SocketPtr, pinPtr, count, (int)flags)))
            {
                error = ZError.GetLastErr();

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

                pin.Free();
                return(false);
            }

            pin.Free();
            return(true);
        }
예제 #3
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public virtual void SendFrame(ZFrame frame, ZSocketFlags flags)
        {
            ZError error;

            if (!SendFrame(frame, flags, out error))
            {
                throw new ZException(error);
            }
        }
예제 #4
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public virtual bool SendFrames(IEnumerable <ZFrame> frames, ZSocketFlags flags, out ZError error)
        {
            int sent = 0;

            if (!SendFrames(frames, ref sent, flags, out error))
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public virtual void SendFrames(IEnumerable <ZFrame> frames, ZSocketFlags flags)
        {
            ZError error;
            int    sent = 0;

            if (!SendFrames(frames, ref sent, flags, out error))
            {
                throw new ZException(error);
            }
        }
예제 #6
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public IEnumerable <ZFrame> ReceiveFrames(int framesToReceive, ZSocketFlags flags)
        {
            ZError error;
            var    frames = ReceiveFrames(framesToReceive, flags, out error);

            if (error != ZError.None)
            {
                throw new ZException(error);
            }
            return(frames);
        }
예제 #7
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public ZFrame ReceiveFrame(ZSocketFlags flags, out ZError error)
        {
            IEnumerable <ZFrame> frames = ReceiveFrames(1, flags & ~ZSocketFlags.More, out error);

            if (frames != null)
            {
                foreach (ZFrame frame in frames)
                {
                    return(frame);
                }
            }
            return(null);
        }
예제 #8
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public IEnumerable <ZFrame> ReceiveFrames(int framesToReceive, ZSocketFlags flags, out ZError error)
        {
            List <ZFrame> frames = null;

            while (!ReceiveFrames(ref framesToReceive, ref frames, flags, out error))
            {
                if (error == ZError.EAGAIN && ((flags & ZSocketFlags.DontWait) == ZSocketFlags.DontWait))
                {
                    break;
                }
                return(null);
            }
            return(frames);
        }
예제 #9
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);
        }
예제 #10
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        public virtual bool SendFrames(IEnumerable <ZFrame> frames, ref int sent, ZSocketFlags flags, out ZError error)
        {
            EnsureNotDisposed();

            error = ZError.None;

            bool more = (flags & ZSocketFlags.More) == ZSocketFlags.More;

            flags = flags | ZSocketFlags.More;

            bool framesIsList = frames is IList <ZFrame>;

            ZFrame[] _frames = frames.ToArray();

            for (int i = 0, l = _frames.Length; i < l; ++i)
            {
                ZFrame frame = _frames[i];

                if (i == l - 1 && !more)
                {
                    flags = flags & ~ZSocketFlags.More;
                }

                if (!SendFrame(frame, flags, out error))
                {
                    return(false);
                }

                if (framesIsList)
                {
                    ((IList <ZFrame>)frames).Remove(frame);
                }

                ++sent;
            }

            return(true);
        }
예제 #11
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        }         // just Send*

        public virtual void Send(ZFrame frame, ZSocketFlags flags)
        {
            SendFrame(frame, flags);
        }         // just Send*
예제 #12
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
 public virtual bool SendFrameMore(ZFrame msg, ZSocketFlags flags, out ZError error)
 {
     return(SendFrame(msg, flags | ZSocketFlags.More, out error));
 }
예제 #13
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
 public virtual void SendFrameMore(ZFrame frame, ZSocketFlags flags)
 {
     SendFrame(frame, flags | ZSocketFlags.More);
 }
예제 #14
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        }         // just Send*

        public virtual bool Send(ZFrame frame, ZSocketFlags flags, out ZError error)
        {
            return(SendFrame(frame, flags, out error));
        }         // just Send*
예제 #15
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        }         // just Send*

        /// <summary>
        /// Sends HARD bytes from a byte[n]. Please don't use SendBytes, use instead SendFrame.
        /// </summary>
        public bool Send(byte[] buffer, int offset, int count, ZSocketFlags flags, out ZError error)
        {
            return(SendBytes(buffer, offset, count, flags, out error));
        }         // just Send*
예제 #16
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        }         // just Send*

        public virtual bool Send(IEnumerable <ZFrame> frames, ref int sent, ZSocketFlags flags, out ZError error)
        {
            return(SendFrames(frames, ref sent, flags, out error));
        }         // just Send*
예제 #17
0
파일: ZSocket.cs 프로젝트: zmapi/ctst4-acmd
        }         // just Send*

        public virtual void Send(IEnumerable <ZFrame> frames, ZSocketFlags flags)
        {
            SendFrames(frames, flags);
        }         // just Send*