예제 #1
0
        public void SetOption(ZmqSocketOption option, int value)
        {
            while (ZmqNative.setsockopt(_handle, (int)option, &value, (IntPtr)sizeof(int)) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                ZmqUtil.ThrowLastError($"Unable to set ZMQ socket option {option} to {value}");
            }
        }
예제 #2
0
        public static void Init(ZmqMessage *message)
        {
            while (ZmqNative.msg_init(message) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                ZmqUtil.ThrowLastError("Could not initialize ZMQ message");
            }
        }
예제 #3
0
파일: ZmqSocket.cs 프로젝트: ocoanet/Zebus
        public void Connect(string endpoint)
        {
            while (ZmqNative.connect(_handle, endpoint) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                ZmqUtil.ThrowLastError($"Unable to connect ZMQ socket to {endpoint}");
            }
        }
예제 #4
0
파일: ZmqSocket.cs 프로젝트: ocoanet/Zebus
        public bool TryDisconnect(string endpoint)
        {
            while (ZmqNative.disconnect(_handle, endpoint) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }
예제 #5
0
        public void SetOption(ZmqSocketOption option, byte[] value)
        {
            fixed(byte *valuePtr = value)
            {
                while (ZmqNative.setsockopt(_handle, (int)option, valuePtr, (IntPtr)(value?.Length ?? 0)) == -1)
                {
                    if (ZmqUtil.WasInterrupted())
                    {
                        continue;
                    }

                    ZmqUtil.ThrowLastError($"Unable to set ZMQ socket option {option}");
                }
            }
        }
예제 #6
0
파일: ZmqSocket.cs 프로젝트: ocoanet/Zebus
        private void Close(bool canThrow)
        {
            if (_handle == IntPtr.Zero)
            {
                return;
            }

            while (ZmqNative.close(_handle) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                if (canThrow)
                {
                    ZmqUtil.ThrowLastError("Could not close ZMQ socket");
                }
            }

            _handle = IntPtr.Zero;
        }
예제 #7
0
        public string GetOptionString(ZmqSocketOption option)
        {
            const int bufSize = 256;
            var       buf     = stackalloc byte[bufSize];
            var       size    = (IntPtr)bufSize;

            while (ZmqNative.getsockopt(_handle, (int)option, buf, &size) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                ZmqUtil.ThrowLastError($"Unable to get ZMQ socket option {option}");
            }

            if ((long)size <= 1)
            {
                return(string.Empty);
            }

            return(Marshal.PtrToStringAnsi((IntPtr)buf, (int)size - 1));
        }
예제 #8
0
        private void Terminate(bool canThrow)
        {
            if (Handle == IntPtr.Zero)
            {
                return;
            }

            while (ZmqNative.ctx_term(Handle) == -1)
            {
                if (ZmqUtil.WasInterrupted())
                {
                    continue;
                }

                if (canThrow)
                {
                    ZmqUtil.ThrowLastError("Could not terminate ZMQ context");
                }

                break;
            }

            Handle = IntPtr.Zero;
        }