Ejemplo n.º 1
0
Archivo: ZMQ.cs Proyecto: knocte/netmq
        public static bool Bind(SocketBase s, String addr)
        {
            if (s == null || !s.CheckTag())
            {
                throw new InvalidOperationException();
            }

            return s.Bind(addr);
        }
Ejemplo n.º 2
0
        public bool Monitor(String addr, SocketEvent events)
        {
            bool rc;
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = (ErrorNumber.ETERM);
                return false;
            }

            // Support deregistering monitoring endpoints as well
            if (addr == null)
            {
                StopMonitor();
                return true;
            }

            //  Parse addr_ string.
            Uri uri;
            try
            {
                uri = new Uri(addr);
            }
            catch (UriFormatException ex)
            {
                ZError.ErrorNumber = (ErrorNumber.EINVAL);
                throw new ArgumentException(addr, ex);
            }
            String protocol = uri.Scheme;
            String address = uri.Authority;
            String path = uri.AbsolutePath;
            if (string.IsNullOrEmpty(address))
                address = path;

            CheckProtocol(protocol);

            // Event notification only supported over inproc://
            if (!protocol.Equals("inproc"))
            {
                ZError.ErrorNumber = (ErrorNumber.EPROTONOSUPPORT);
                return false;
            }

            // Register events to monitor
            m_monitorEvents = events;

            m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair);
            if (m_monitorSocket == null)
                return false;

            // Never block context termination on pending event messages
            int linger = 0;
            rc = m_monitorSocket.SetSocketOption(ZmqSocketOptions.Linger, linger);
            if (!rc)
                StopMonitor();

            // Spawn the monitor socket endpoint
            rc = m_monitorSocket.Bind(addr);
            if (!rc)
                StopMonitor();
            return rc;
        }