Exemplo n.º 1
0
        /// <summary>
        /// Creates a socket within the current context.
        /// </summary>
        /// <param name="type">The socket type.</param>
        /// <param name="lingerTime">Linger period for socket shutdown, in ms, or <see cref="System.Threading.Timeout.Infinite"/> for no linger.</param>
        /// <returns>An unbound socket.</returns>
        public Socket CreateSocket( SocketType type, int lingerTime = DEFAULT_LINGER )
        {
            Contract.Requires( !Disposed );
            Contract.Ensures( Contract.Result<Socket>() != null );

            IntPtr socket = C.zmq_socket( m_ptr, (int)type );

            if( socket == IntPtr.Zero )
            {
                throw ZeroMQException.CurrentError();
            }
            
            Socket sock = new Socket( socket );

            if( lingerTime >= 0 )
            {
                sock.SetOption( SocketOption.Linger, lingerTime );
            }

            return sock;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new stream of the specified type for the specified context.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="socketType"></param>
        /// <param name="lingerTime">Linger period for socket shutdown, in ms, or <see cref="Timeout.Infinite"/> for no linger.</param>
        protected ZMQStream( Context context, SocketType socketType, int lingerTime = Context.DEFAULT_LINGER )
            : base()
        {
            Contract.Requires( context != null );
            Contract.Requires( lingerTime >= 0 || lingerTime == Timeout.Infinite );

            Disposed = false;

            m_context = context;
            m_socket = m_context.CreateSocket( socketType );

            if( lingerTime >= 0 )
            {
                m_socket.SetOption( SocketOption.Linger, lingerTime );
            }
        }