Example #1
0
        protected override void XSetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                throw InvalidException.Create();
            }

            byte[] val;

            if (optval is String)
                val =  Encoding.ASCII.GetBytes ((String)optval);
            else if (optval is byte[])
                val = (byte[]) optval;
            else
                throw InvalidException.Create();

            //  Create the subscription message.
            Msg msg = new Msg(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put((byte)1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put((byte)0);
            msg.Put (val,1);

            //  Pass it further on in the stack.
            base.XSend (msg, 0);
        }
Example #2
0
        protected override bool XSetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                ZError.ErrorNumber = (ErrorNumber.EINVAL);
                return false;
            }

            byte[] val;

            if (optval is String)
                val =  Encoding.ASCII.GetBytes ((String)optval);
            else if (optval is byte[])
                val = (byte[]) optval;
            else
                throw new ArgumentException();

            //  Create the subscription message.
            Msg msg = new Msg(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put((byte)1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put((byte)0);
            msg.Put (val,1);

            //  Pass it further on in the stack.
            bool rc = base.XSend (msg, 0);
            return rc;
        }
Example #3
0
        protected override bool XSetSocketOption(ZmqSocketOptions option, Object optionValue)
        {
            if (option != ZmqSocketOptions.Subscribe && option != ZmqSocketOptions.Unsubscribe)
            {
                return false;
            }

            byte[] val;

            if (optionValue is string)
                val = Encoding.ASCII.GetBytes((string)optionValue);
            else if (optionValue is byte[])
                val = (byte[])optionValue;
            else
                throw new InvalidException(string.Format("In Sub.XSetSocketOption({0},{1}), optionValue must be either a string or a byte-array.", option, (optionValue == null ? "null" : optionValue.ToString())));

            //  Create the subscription message.
            var msg = new Msg();
            msg.InitPool(val.Length + 1);
            if (option == ZmqSocketOptions.Subscribe)
                msg.Put(1);
            else if (option == ZmqSocketOptions.Unsubscribe)
                msg.Put(0);
            msg.Put(val, 1, val.Length);

            try
            {
                //  Pass it further on in the stack.
                bool isMessageSent = base.XSend(ref msg);

                if (!isMessageSent)
                {
                    string xMsg = string.Format("in Sub.XSetSocketOption({0}, {1}), XSend returned false.", option, optionValue);
                    throw new AgainException(innerException: null, message: xMsg);
                }
            }
            finally
            {
                msg.Close();
            }

            return true;
        }
Example #4
0
 //  The default implementation assumes there are no specific socket
 //  options for the particular socket type. If not so, overload this
 //  method.
 protected virtual bool XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     ZError.ErrorNumber = (ErrorNumber.EINVAL);
     return false;
 }
Example #5
0
        public static Object GetSocketOptionX(SocketBase s, ZmqSocketOptions option)
        {
            if (s == null || !s.CheckTag())
            {
                throw NetMQException.Create(ErrorCode.EFAULT);
            }

            return s.GetSocketOptionX(option);
        }
Example #6
0
        /// <summary>
        /// Get the value of the specified option.
        /// </summary>
        /// <param name="option">a ZmqSocketOptions that specifies what to get</param>
        /// <returns>an Object that is the value of that option</returns>
        public Object GetSocketOption(ZmqSocketOptions option)
        {
            switch (option)
            {
            case ZmqSocketOptions.SendHighWatermark:
                return(SendHighWatermark);

            case ZmqSocketOptions.ReceiveHighWatermark:
                return(ReceiveHighWatermark);

            case ZmqSocketOptions.Affinity:
                return(Affinity);

            case ZmqSocketOptions.Identity:
                return(Identity);

            case ZmqSocketOptions.Rate:
                return(Rate);

            case ZmqSocketOptions.RecoveryIvl:
                return(RecoveryIvl);

            case ZmqSocketOptions.SendBuffer:
                return(SendBuffer);

            case ZmqSocketOptions.ReceiveBuffer:
                return(ReceiveBuffer);

            case ZmqSocketOptions.Type:
                return(SocketType);

            case ZmqSocketOptions.Linger:
                return(Linger);

            case ZmqSocketOptions.ReconnectIvl:
                return(ReconnectIvl);

            case ZmqSocketOptions.ReconnectIvlMax:
                return(ReconnectIvlMax);

            case ZmqSocketOptions.Backlog:
                return(Backlog);

            case ZmqSocketOptions.Maxmsgsize:
                return(MaxMessageSize);

            case ZmqSocketOptions.MulticastHops:
                return(MulticastHops);

            case ZmqSocketOptions.ReceiveTimeout:
                return(ReceiveTimeout);

            case ZmqSocketOptions.SendTimeout:
                return(SendTimeout);

            case ZmqSocketOptions.IPv4Only:
                return(IPv4Only);

            case ZmqSocketOptions.TcpKeepalive:
                return(TcpKeepalive);

            case ZmqSocketOptions.DelayAttachOnConnect:
                return(DelayAttachOnConnect);

            case ZmqSocketOptions.TcpKeepaliveIdle:
                return(TcpKeepaliveIdle);

            case ZmqSocketOptions.TcpKeepaliveIntvl:
                return(TcpKeepaliveIntvl);

            case ZmqSocketOptions.LastEndpoint:
                return(LastEndpoint);

            case ZmqSocketOptions.Endian:
                return(Endian);

            default:
                throw new InvalidException("GetSocketOption called with invalid ZmqSocketOptions of " + option);
            }
        }
Example #7
0
 protected override bool XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     if (option != ZmqSocketOptions.RouterMandatory)
     {
         ZError.ErrorNumber = (ErrorNumber.EINVAL);
         return false;
     }
     m_mandatory = (int) optval == 1;
     return true;
 }
Example #8
0
        public void SetSocketOption(ZmqSocketOptions option, Object optval)
        {
            switch (option)
            {
                case ZmqSocketOptions.SendHighWatermark:
                    SendHighWatermark = (int) optval;
                    break;
                case ZmqSocketOptions.ReceivevHighWatermark:
                    ReceiveHighWatermark = (int) optval;
                    break;

                case ZmqSocketOptions.Affinity:
                    Affinity = (long) optval;
                    break;
                case ZmqSocketOptions.Identity:
                    byte[] val;

                    if (optval is String)
                        val = Encoding.ASCII.GetBytes((String) optval);
                    else if (optval is byte[])
                        val = (byte[]) optval;
                    else
                    {
                        throw InvalidException.Create();
                    }

                    if (val.Length ==0 || val.Length > 255)
                    {
                        throw InvalidException.Create();
                    }
                    Identity = new byte[val.Length];
                    val.CopyTo(Identity, 0);
                    IdentitySize = (byte) Identity.Length;
                    break;
                case ZmqSocketOptions.Rate:
                    Rate = (int) optval;
                    break;
                case ZmqSocketOptions.RecoveryIvl:
                    RecoveryIvl = (int) optval;
                    break;
                case ZmqSocketOptions.SendBuffer:
                    SendBuffer = (int) optval;
                    break;
                case ZmqSocketOptions.ReceivevBuffer:
                    ReceiveBuffer = (int) optval;
                    break;
                case ZmqSocketOptions.Linger:
                    Linger = (int) optval;
                    break;
                case ZmqSocketOptions.ReconnectIvl:
                    ReconnectIvl = (int) optval;

                    if (ReconnectIvl < -1)
                    {
                        throw InvalidException.Create();
                    }

                    break;
                case ZmqSocketOptions.ReconnectIvlMax:
                    ReconnectIvlMax = (int) optval;

                    if (ReconnectIvlMax < 0)
                    {
                        throw InvalidException.Create();
                    }

                    break;
                case ZmqSocketOptions.Backlog:
                    Backlog = (int) optval;
                    break;

                case ZmqSocketOptions.Maxmsgsize:
                    Maxmsgsize = (long) optval;
                    break;
                case ZmqSocketOptions.MulticastHops:
                    MulticastHops = (int) optval;
                    break;
                case ZmqSocketOptions.ReceiveTimeout:
                    ReceiveTimeout = (int) optval;
                    break;
                case ZmqSocketOptions.SendTimeout:
                    SendTimeout = (int) optval;
                    break;
                case ZmqSocketOptions.IPv4Only:

                    IPv4Only = (bool)optval;

                    break;
                case ZmqSocketOptions.TcpKeepalive:

                    TcpKeepalive = (int) optval;
                    if (TcpKeepalive != -1 && TcpKeepalive != 0 && TcpKeepalive != 1)
                    {
                        throw InvalidException.Create();
                    }
                    break;
                case ZmqSocketOptions.DelayAttachOnConnect:

                    DelayAttachOnConnect = (bool) optval;

                    break;
                case ZmqSocketOptions.TcpKeepaliveCnt:
                    // not supported
                    break;
                case ZmqSocketOptions.TcpKeepaliveIdle:
                    TcpKeepaliveIdle = (int) optval;
                    break;
                case ZmqSocketOptions.TcpKeepaliveIntvl:
                    TcpKeepaliveIntvl = (int) optval;
                    break;
                case ZmqSocketOptions.TcpAcceptFilter:
                    String filterStr = (String) optval;
                    if (filterStr == null)
                    {
                        TcpAcceptFilters.Clear();
                    }
                    else if (filterStr.Length == 0 || filterStr.Length > 255)
                    {
                        throw InvalidException.Create();
                    }
                    else
                    {
                        TcpAddress.TcpAddressMask filter = new TcpAddress.TcpAddressMask();
                        filter.Resolve(filterStr, IPv4Only);
                        TcpAcceptFilters.Add(filter);
                    }
                    break;
                default:
                    throw InvalidException.Create();
            }
        }
Example #9
0
        public void SetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

            //  First, check whether specific socket type overloads the option.

            try
            {
                XSetSocketOption(option, optval);
                return;
            }
            catch (InvalidException)
            {
            }

            //  If the socket type doesn't support the option, pass it to
            //  the generic option parser.
            m_options.SetSocketOption(option, optval);
        }
Example #10
0
 //  The default implementation assumes there are no specific socket
 //  options for the particular socket type. If not so, overload this
 //  method.
 protected virtual void XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     throw InvalidException.Create();
 }
Example #11
0
        public bool SetSocketOption(ZmqSocketOptions option, Object optval)
        {
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = ErrorNumber.ETERM;
                return false;
            }

            //  First, check whether specific socket type overloads the option.
            bool rc = XSetSocketOption(option, optval);
            if (rc || !ZError.IsError(ErrorNumber.EINVAL))
                return false;

            //  If the socket type doesn't support the option, pass it to
            //  the generic option parser.
            ZError.Clear();
            return m_options.SetSocketOption(option, optval);
        }
Example #12
0
        public int GetSocketOption(ZmqSocketOptions option)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore ? 1 : 0;
            }
            if (option == ZmqSocketOptions.Events)
            {
                try
                {
                    ProcessCommands(0, false);
                }
                catch (NetMQException ex)
                {
                    if (ex.ErrorCode == ErrorCode.EINTR || ex.ErrorCode == ErrorCode.ETERM)
                    {
                        return -1;
                    }
                    else
                    {
                        Debug.Assert(false);

                        throw;
                    }
                }

                PollEvents val = 0;
                if (HasOut())
                    val |= PollEvents.PollOut;
                if (HasIn())
                    val |= PollEvents.PollIn;
                return (int)val;
            }

            return (int)GetSocketOptionX(option);
        }
Example #13
0
File: XPub.cs Project: knocte/netmq
 protected override bool XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     if (option != ZmqSocketOptions.XpubVerbose) {
         ZError.ErrorNumber = (ErrorNumber.EINVAL);
         return false;
     }
     m_verbose = (int) optval == 1;
     return true;
 }
Example #14
0
        public int GetSocketOption(ZmqSocketOptions option)
        {
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = (ErrorNumber.ETERM);
                return -1;
            }

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore ? 1 : 0;
            }
            if (option == ZmqSocketOptions.Events)
            {
                bool rc = ProcessCommands(0, false);
                if (!rc && (ZError.IsError(ErrorNumber.EINTR) || ZError.IsError(ErrorNumber.ETERM)))
                    return -1;
                Debug.Assert(rc);
                PollEvents val = 0;
                if (HasOut())
                    val |= PollEvents.PollOut;
                if (HasIn())
                    val |= PollEvents.PollIn;
                return (int)val;
            }

            return (int)GetSocketOptionX(option);
        }
Example #15
0
        /// <summary>
        /// Assign the given optionValue to the specified option.
        /// </summary>
        /// <param name="option">a ZmqSocketOptions that specifies what to set</param>
        /// <param name="optionValue">an Object that is the value to set that option to</param>
        public void SetSocketOption(ZmqSocketOptions option, Object optionValue)
        {
            switch (option)
            {
                case ZmqSocketOptions.SendHighWatermark:
                    SendHighWatermark = (int)optionValue;
                    break;

                case ZmqSocketOptions.ReceiveHighWatermark:
                    ReceiveHighWatermark = (int)optionValue;
                    break;

                case ZmqSocketOptions.Affinity:
                    Affinity = (long)optionValue;
                    break;

                case ZmqSocketOptions.Identity:
                    byte[] val;

                    if (optionValue is string)
                        val = Encoding.ASCII.GetBytes((string)optionValue);
                    else if (optionValue is byte[])
                        val = (byte[])optionValue;
                    else
                    {
                        string xMsg = string.Format("In Options.SetSocketOption(Identity, {0}) optionValue must be a string or byte-array.", optionValue == null ? "null" : optionValue.ToString());
                        throw new InvalidException(xMsg);
                    }

                    if (val.Length == 0 || val.Length > 255)
                    {
                        string xMsg = string.Format("In Options.SetSocketOption(Identity,) optionValue yielded a byte-array of length {0}, should be 1..255.", val.Length);
                        throw new InvalidException(xMsg);
                    }
                    Identity = new byte[val.Length];
                    val.CopyTo(Identity, 0);
                    IdentitySize = (byte)Identity.Length;
                    break;

                case ZmqSocketOptions.Rate:
                    Rate = (int)optionValue;
                    break;

                case ZmqSocketOptions.RecoveryIvl:
                    RecoveryIvl = (int)optionValue;
                    break;

                case ZmqSocketOptions.SendBuffer:
                    SendBuffer = (int)optionValue;
                    break;

                case ZmqSocketOptions.ReceiveBuffer:
                    ReceiveBuffer = (int)optionValue;
                    break;

                case ZmqSocketOptions.Linger:
                    Linger = (int)optionValue;
                    break;

                case ZmqSocketOptions.ReconnectIvl:
                    ReconnectIvl = (int)optionValue;
                    if (ReconnectIvl < -1)
                    {
                        throw new InvalidException(string.Format("Options.SetSocketOption(ReconnectIvl, {0}) optionValue must be >= -1.", ReconnectIvl));
                    }
                    break;

                case ZmqSocketOptions.ReconnectIvlMax:
                    ReconnectIvlMax = (int)optionValue;
                    if (ReconnectIvlMax < 0)
                    {
                        throw new InvalidException(string.Format("Options.SetSocketOption(ReconnectIvlMax, {0}) optionValue must be non-negative.", ReconnectIvlMax));
                    }
                    break;

                case ZmqSocketOptions.Backlog:
                    Backlog = (int)optionValue;
                    break;

                case ZmqSocketOptions.MaxMessageSize:
                    MaxMessageSize = (long)optionValue;
                    break;

                case ZmqSocketOptions.MulticastHops:
                    MulticastHops = (int)optionValue;
                    break;

                case ZmqSocketOptions.ReceiveTimeout:
                    ReceiveTimeout = (int)optionValue;
                    break;

                case ZmqSocketOptions.SendTimeout:
                    SendTimeout = (int)optionValue;
                    break;

                case ZmqSocketOptions.IPv4Only:
                    IPv4Only = (bool)optionValue;
                    break;

                case ZmqSocketOptions.TcpKeepalive:
                    TcpKeepalive = (int)optionValue;
                    if (TcpKeepalive != -1 && TcpKeepalive != 0 && TcpKeepalive != 1)
                    {
                        throw new InvalidException(string.Format("Options.SetSocketOption(TcpKeepalive, {0}) optionValue is neither -1, 0, nor 1.", TcpKeepalive));
                    }
                    break;

                case ZmqSocketOptions.DelayAttachOnConnect:
                    DelayAttachOnConnect = (bool)optionValue;
                    break;

                case ZmqSocketOptions.TcpKeepaliveIdle:
                    TcpKeepaliveIdle = (int)optionValue;
                    break;

                case ZmqSocketOptions.TcpKeepaliveIntvl:
                    TcpKeepaliveIntvl = (int)optionValue;
                    break;

                case ZmqSocketOptions.TcpAcceptFilter:
                    string filterStr = (string)optionValue;
                    if (filterStr == null)
                    {
                        TcpAcceptFilters.Clear();
                    }
                    else if (filterStr.Length == 0 || filterStr.Length > 255)
                    {
                        throw new InvalidException(string.Format("Options.SetSocketOption(TcpAcceptFilter,{0}), optionValue has invalid length of {1) but must be 1..255", filterStr, filterStr.Length));
                    }
                    else
                    {
                        TcpAddress.TcpAddressMask filter = new TcpAddress.TcpAddressMask();
                        filter.Resolve(filterStr, IPv4Only);
                        TcpAcceptFilters.Add(filter);
                    }
                    break;

                case ZmqSocketOptions.Endian:
                    Endian = (Endianness)optionValue;
                    break;

                default:
                    throw new InvalidException("Options.SetSocketOption called with invalid ZmqSocketOptions of " + option);
            }
        }
Example #16
0
        /// <summary>
        /// Get the value of the specified option.
        /// </summary>
        /// <param name="option">a ZmqSocketOptions that specifies what to get</param>
        /// <returns>an Object that is the value of that option</returns>
        public Object GetSocketOption(ZmqSocketOptions option)
        {
            switch (option)
            {
                case ZmqSocketOptions.SendHighWatermark:
                    return SendHighWatermark;

                case ZmqSocketOptions.ReceiveHighWatermark:
                    return ReceiveHighWatermark;

                case ZmqSocketOptions.Affinity:
                    return Affinity;

                case ZmqSocketOptions.Identity:
                    return Identity;

                case ZmqSocketOptions.Rate:
                    return Rate;

                case ZmqSocketOptions.RecoveryIvl:
                    return RecoveryIvl;

                case ZmqSocketOptions.SendBuffer:
                    return SendBuffer;

                case ZmqSocketOptions.ReceiveBuffer:
                    return ReceiveBuffer;

                case ZmqSocketOptions.Type:
                    return SocketType;

                case ZmqSocketOptions.Linger:
                    return Linger;

                case ZmqSocketOptions.ReconnectIvl:
                    return ReconnectIvl;

                case ZmqSocketOptions.ReconnectIvlMax:
                    return ReconnectIvlMax;

                case ZmqSocketOptions.Backlog:
                    return Backlog;

                case ZmqSocketOptions.MaxMessageSize:
                    return MaxMessageSize;

                case ZmqSocketOptions.MulticastHops:
                    return MulticastHops;

                case ZmqSocketOptions.ReceiveTimeout:
                    return ReceiveTimeout;

                case ZmqSocketOptions.SendTimeout:
                    return SendTimeout;

                case ZmqSocketOptions.IPv4Only:
                    return IPv4Only;

                case ZmqSocketOptions.TcpKeepalive:
                    return TcpKeepalive;

                case ZmqSocketOptions.DelayAttachOnConnect:
                    return DelayAttachOnConnect;

                case ZmqSocketOptions.TcpKeepaliveIdle:
                    return TcpKeepaliveIdle;

                case ZmqSocketOptions.TcpKeepaliveIntvl:
                    return TcpKeepaliveIntvl;

                case ZmqSocketOptions.LastEndpoint:
                    return LastEndpoint;

                case ZmqSocketOptions.Endian:
                    return Endian;

                default:
                    throw new InvalidException("GetSocketOption called with invalid ZmqSocketOptions of " + option);
            }
        }
Example #17
0
 protected override void XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     if (option != ZmqSocketOptions.RouterMandatory)
     {
         throw InvalidException.Create();
     }
     m_mandatory = (bool)optval;
 }
Example #18
0
 internal TimeSpan GetSocketOptionTimeSpan(ZmqSocketOptions socketOptions)
 {
     return(TimeSpan.FromMilliseconds(ZMQ.GetSocketOption(m_socketHandle, socketOptions)));
 }
Example #19
0
 internal int GetSocketOption(ZmqSocketOptions socketOptions)
 {
     return(ZMQ.GetSocketOption(m_socketHandle, socketOptions));
 }
Example #20
0
        public Object GetSocketOptionX(ZmqSocketOptions option)
        {
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = (ErrorNumber.ETERM);
                return null;
            }

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore ? 1 : 0;
            }

            if (option == ZmqSocketOptions.FD)
            {
                return m_mailbox.FD;
            }

            if (option == ZmqSocketOptions.Events)
            {
                bool rc = ProcessCommands(0, false);
                if (!rc && (ZError.IsError(ErrorNumber.EINTR) || ZError.IsError(ErrorNumber.ETERM)))
                    return -1;
                Debug.Assert(rc);
                int val = 0;
                if (HasOut())
                    val |= ZMQ.ZmqPollout;
                if (HasIn())
                    val |= ZMQ.ZmqPollin;
                return val;
            }
            //  If the socket type doesn't support the option, pass it to
            //  the generic option parser.
            return m_options.GetSocketOption(option);
        }
Example #21
0
        protected override bool XSetSocketOption(ZmqSocketOptions option, Object optionValue)
        {
            if (option == ZmqSocketOptions.XpubVerbose)
            {
                m_verbose = (bool)optionValue;
                return true;
            }
            else if (option == ZmqSocketOptions.XPublisherManual)
            {
                m_manual = true;
                return true;
            }
            else if (option == ZmqSocketOptions.Subscribe && m_manual && m_lastPipe != null)
            {
                byte[] subscription;

                if (optionValue is byte[])
                {
                    subscription = optionValue as byte[];
                }
                else
                {
                    subscription = Encoding.ASCII.GetBytes((string)optionValue);
                }

                m_subscriptions.Add(subscription, 0, subscription.Length, m_lastPipe);
                return true;
            }
            else if (option == ZmqSocketOptions.Unsubscribe && m_manual && m_lastPipe != null)
            {
                byte[] subscription;

                if (optionValue is byte[])
                {
                    subscription = optionValue as byte[];
                }
                else
                {
                    subscription = Encoding.ASCII.GetBytes((string)optionValue);
                }

                m_subscriptions.Remove(subscription, 0, subscription.Length, m_lastPipe);
                return true;
            }
            else if (option == ZmqSocketOptions.XPublisherWelcomeMessage)
            {
                m_welcomeMessage.Close();

                if (optionValue != null)
                {
                    if (optionValue is byte[])
                    {
                        var value = (byte[])optionValue;

                        var welcomeBytes = new byte[value.Length];
                        value.CopyTo(welcomeBytes, 0);

                        m_welcomeMessage.InitGC(welcomeBytes, welcomeBytes.Length);
                    }
                    else
                    {
                        throw new InvalidException(string.Format("In XPub.XSetSocketOption({0},{1}), optionValue must be a byte-array.", option, optionValue));
                    }
                }
                else
                {
                    m_welcomeMessage.InitEmpty();
                }

                return true;
            }

            return false;
        }
Example #22
0
 //  The default implementation assumes there are no specific socket
 //  options for the particular socket type. If not so, overload this
 //  method.
 protected virtual void XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     throw InvalidException.Create();
 }
Example #23
0
 protected override void XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     if (option != ZmqSocketOptions.RouterMandatory && option != ZmqSocketOptions.RouterRawSocket)
     {
         throw InvalidException.Create();
     }
     if (option == ZmqSocketOptions.RouterRawSocket)
     {
         m_rawSocket = (bool)optval;
         if (m_rawSocket)
         {
             m_options.RecvIdentity = false;
             m_options.RawSocket = true;
         }
     }
     else
     {
         m_mandatory = (bool)optval;
     }
 }
Example #24
0
        public Object GetSocketOptionX(ZmqSocketOptions option)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore ? 1 : 0;
            }

            if (option == ZmqSocketOptions.FD)
            {
                return m_mailbox.FD;
            }

            if (option == ZmqSocketOptions.Events)
            {
                try
                {
                    ProcessCommands(0, false);
                }
                catch (NetMQException ex)
                {
                    Debug.Assert(false);

                    if (ex.ErrorCode == ErrorCode.EINTR || ex.ErrorCode == ErrorCode.ETERM)
                    {
                        return -1;
                    }
                    else
                    {
                        throw;
                    }
                }

                int val = 0;
                if (HasOut())
                    val |= ZMQ.ZmqPollout;
                if (HasIn())
                    val |= ZMQ.ZmqPollin;
                return val;
            }
            //  If the socket type doesn't support the option, pass it to
            //  the generic option parser.
            return m_options.GetSocketOption(option);
        }
Example #25
0
 /// <summary>
 /// The default implementation assumes there are no specific socket
 /// options for the particular socket type. If not so, overload this
 /// method.
 /// </summary>
 /// <param name="option">a ZmqSocketOptions specifying which option to set</param>
 /// <param name="optionValue">an Object that is the value to set the option to</param>
 protected virtual bool XSetSocketOption(ZmqSocketOptions option, [CanBeNull] Object optionValue)
 {
     return false;
 }
Example #26
0
        public int GetSocketOption(ZmqSocketOptions option)
        {
            CheckContextTerminated();

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore ? 1 : 0;
            }
            if (option == ZmqSocketOptions.Events)
            {
                try
                {
                    ProcessCommands(0, false);
                }
                catch (TerminatingException)
                {
                    return -1;
                }

                PollEvents val = 0;
                if (HasOut())
                    val |= PollEvents.PollOut;
                if (HasIn())
                    val |= PollEvents.PollIn;
                return (int)val;
            }

            return (int)GetSocketOptionX(option);
        }
Example #27
0
        public Object GetSocketOptionX(ZmqSocketOptions option)
        {
            CheckContextTerminated();

            if (option == ZmqSocketOptions.ReceiveMore)
            {
                return m_rcvMore;
            }

            if (option == ZmqSocketOptions.Handle)
            {
                return m_mailbox.Handle;
            }

            if (option == ZmqSocketOptions.Events)
            {
                try
                {
                    ProcessCommands(0, false);
                }
                catch (TerminatingException)
                {
                    return -1;
                }

                PollEvents val = 0;
                if (HasOut())
                    val |= PollEvents.PollOut;
                if (HasIn())
                    val |= PollEvents.PollIn;
                return val;
            }
            //  If the socket type doesn't support the option, pass it to
            //  the generic option parser.
            return m_options.GetSocketOption(option);
        }
Example #28
0
 protected override void XSetSocketOption(ZmqSocketOptions option, Object optval)
 {
     if (option != ZmqSocketOptions.XpubVerbose)
     {
         throw InvalidException.Create();
     }
     m_verbose = (int)optval == 1;
 }
Example #29
0
        public void SetSocketOption(ZmqSocketOptions option, Object optval)
        {
            CheckContextTerminated();

            //  First, check whether specific socket type overloads the option.
            if (!XSetSocketOption(option, optval))
            {
                //  If the socket type doesn't support the option, pass it to
                //  the generic option parser.
                m_options.SetSocketOption(option, optval);
            }
        }
Example #30
0
        public Object GetSocketOption(ZmqSocketOptions option)
        {
            switch (option)
            {
                case ZmqSocketOptions.SendHighWatermark:
                    return SendHighWatermark;

                case ZmqSocketOptions.ReceivevHighWatermark:
                    return ReceiveHighWatermark;

                case ZmqSocketOptions.Affinity:
                    return Affinity;

                case ZmqSocketOptions.Identity:
                    return Identity;

                case ZmqSocketOptions.Rate:
                    return Rate;

                case ZmqSocketOptions.RecoveryIvl:
                    return RecoveryIvl;

                case ZmqSocketOptions.SendBuffer:
                    return SendBuffer;

                case ZmqSocketOptions.ReceivevBuffer:
                    return ReceiveBuffer;

                case ZmqSocketOptions.Type:
                    return SocketType;

                case ZmqSocketOptions.Linger:
                    return Linger;

                case ZmqSocketOptions.ReconnectIvl:
                    return ReconnectIvl;

                case ZmqSocketOptions.ReconnectIvlMax:
                    return ReconnectIvlMax;

                case ZmqSocketOptions.Backlog:
                    return Backlog;

                case ZmqSocketOptions.Maxmsgsize:
                    return Maxmsgsize;

                case ZmqSocketOptions.MulticastHops:
                    return MulticastHops;

                case ZmqSocketOptions.ReceiveTimeout:
                    return ReceiveTimeout;

                case ZmqSocketOptions.SendTimeout:
                    return SendTimeout;

                case ZmqSocketOptions.IPv4Only:
                    return IPv4Only;

                case ZmqSocketOptions.TcpKeepalive:
                    return TcpKeepalive;

                case ZmqSocketOptions.DelayAttachOnConnect:
                    return DelayAttachOnConnect;

                case ZmqSocketOptions.TcpKeepaliveCnt:
                    // not supported
                    return 0;
                case ZmqSocketOptions.TcpKeepaliveIdle:
                    return TcpKeepaliveIdle;
                case ZmqSocketOptions.TcpKeepaliveIntvl:
                    return TcpKeepaliveIntvl;

                case ZmqSocketOptions.LastEndpoint:
                    return LastEndpoint;

                default:
                    throw InvalidException.Create();
            }
        }
Example #31
0
File: ZMQ.cs Project: knocte/netmq
        public static Object GetSocketOptionX(SocketBase s, ZmqSocketOptions option)
        {
            if (s == null || !s.CheckTag())
            {
                throw new InvalidOperationException();
            }

            return s.GetSocketOptionX(option);
        }
Example #32
0
 public static int GetSocketOption(SocketBase s, ZmqSocketOptions opt)
 {
     return s.GetSocketOption(opt);
 }
Example #33
0
File: ZMQ.cs Project: knocte/netmq
        public static void SetSocketOption(SocketBase s, ZmqSocketOptions option, Object optval)
        {
            if (s == null || !s.CheckTag())
            {
                throw new InvalidOperationException();
            }

            s.SetSocketOption(option, optval);
        }
Example #34
0
        public static void SetSocketOption(SocketBase s, ZmqSocketOptions option, Object optval)
        {
            if (s == null || !s.CheckTag())
            {
                throw NetMQException.Create(ErrorCode.EFAULT);
            }

            s.SetSocketOption(option, optval);
        }
Example #35
0
        /// <summary>
        /// Assign the given optionValue to the specified option.
        /// </summary>
        /// <param name="option">a ZmqSocketOptions that specifies what to set</param>
        /// <param name="optionValue">an Object that is the value to set that option to</param>
        public void SetSocketOption(ZmqSocketOptions option, Object optionValue)
        {
            switch (option)
            {
            case ZmqSocketOptions.SendHighWatermark:
                SendHighWatermark = (int)optionValue;
                break;

            case ZmqSocketOptions.ReceiveHighWatermark:
                ReceiveHighWatermark = (int)optionValue;
                break;

            case ZmqSocketOptions.Affinity:
                Affinity = (long)optionValue;
                break;

            case ZmqSocketOptions.Identity:
                byte[] val;

                if (optionValue is String)
                {
                    val = Encoding.ASCII.GetBytes((String)optionValue);
                }
                else if (optionValue is byte[])
                {
                    val = (byte[])optionValue;
                }
                else
                {
                    String xMsg = String.Format("In Options.SetSocketOption(Identity, {0}) optionValue must be a String or byte-array.", optionValue == null ? "null" : optionValue.ToString());
                    throw new InvalidException(xMsg);
                }

                if (val.Length == 0 || val.Length > 255)
                {
                    String xMsg = String.Format("In Options.SetSocketOption(Identity,) optionValue yielded a byte-array of length {0}, should be 1..255.", val.Length);
                    throw new InvalidException(xMsg);
                }
                Identity = new byte[val.Length];
                val.CopyTo(Identity, 0);
                IdentitySize = (byte)Identity.Length;
                break;

            case ZmqSocketOptions.Rate:
                Rate = (int)optionValue;
                break;

            case ZmqSocketOptions.RecoveryIvl:
                RecoveryIvl = (int)optionValue;
                break;

            case ZmqSocketOptions.SendBuffer:
                SendBuffer = (int)optionValue;
                break;

            case ZmqSocketOptions.ReceiveBuffer:
                ReceiveBuffer = (int)optionValue;
                break;

            case ZmqSocketOptions.Linger:
                Linger = (int)optionValue;
                break;

            case ZmqSocketOptions.ReconnectIvl:
                ReconnectIvl = (int)optionValue;
                if (ReconnectIvl < -1)
                {
                    throw new InvalidException(String.Format("Options.SetSocketOption(ReconnectIvl, {0}) optionValue must be >= -1.", ReconnectIvl));
                }
                break;

            case ZmqSocketOptions.ReconnectIvlMax:
                ReconnectIvlMax = (int)optionValue;
                if (ReconnectIvlMax < 0)
                {
                    throw new InvalidException(String.Format("Options.SetSocketOption(ReconnectIvlMax, {0}) optionValue must be non-negative.", ReconnectIvlMax));
                }
                break;

            case ZmqSocketOptions.Backlog:
                Backlog = (int)optionValue;
                break;

            case ZmqSocketOptions.Maxmsgsize:
                MaxMessageSize = (long)optionValue;
                break;

            case ZmqSocketOptions.MulticastHops:
                MulticastHops = (int)optionValue;
                break;

            case ZmqSocketOptions.ReceiveTimeout:
                ReceiveTimeout = (int)optionValue;
                break;

            case ZmqSocketOptions.SendTimeout:
                SendTimeout = (int)optionValue;
                break;

            case ZmqSocketOptions.IPv4Only:
                IPv4Only = (bool)optionValue;
                break;

            case ZmqSocketOptions.TcpKeepalive:
                TcpKeepalive = (int)optionValue;
                if (TcpKeepalive != -1 && TcpKeepalive != 0 && TcpKeepalive != 1)
                {
                    throw new InvalidException(String.Format("Options.SetSocketOption(TcpKeepalive, {0}) optionValue is neither -1, 0, nor 1.", TcpKeepalive));
                }
                break;

            case ZmqSocketOptions.DelayAttachOnConnect:
                DelayAttachOnConnect = (bool)optionValue;
                break;

            case ZmqSocketOptions.TcpKeepaliveIdle:
                TcpKeepaliveIdle = (int)optionValue;
                break;

            case ZmqSocketOptions.TcpKeepaliveIntvl:
                TcpKeepaliveIntvl = (int)optionValue;
                break;

            case ZmqSocketOptions.TcpAcceptFilter:
                String filterStr = (String)optionValue;
                if (filterStr == null)
                {
                    TcpAcceptFilters.Clear();
                }
                else if (filterStr.Length == 0 || filterStr.Length > 255)
                {
                    throw new InvalidException(String.Format("Options.SetSocketOption(TcpAcceptFilter,{0}), optionValue has invalid length of {1) but must be 1..255", filterStr, filterStr.Length));
                }
                else
                {
                    TcpAddress.TcpAddressMask filter = new TcpAddress.TcpAddressMask();
                    filter.Resolve(filterStr, IPv4Only);
                    TcpAcceptFilters.Add(filter);
                }
                break;

            case ZmqSocketOptions.Endian:
                Endian = (Endianness)optionValue;
                break;

            default:
                throw new InvalidException("Options.SetSocketOption called with invalid ZmqSocketOptions of " + option);
            }
        }