Objects of class Ctx are intended to encapsulate all of the global state associated with the NetMQ library. This contains the sockets, and manages interaction between them.
Internal analog of the public NetMQContext class.
コード例 #1
0
ファイル: NetMQConfig.cs プロジェクト: hdxhan/netmq
        static NetMQConfig()
        {
            s_ctx = new Ctx();
            s_settingsSync = new object();
            s_linger = TimeSpan.Zero;

            // Register to destory the context when application exit
            AppDomain.CurrentDomain.ProcessExit += OnCurrentDomainOnProcessExit;
        }
コード例 #2
0
ファイル: NetMQConfig.cs プロジェクト: cjkao/netmq
        static NetMQConfig()
        {
            s_manualTakeOver = false;
            s_ctx = new Ctx { Block = false };
            s_settingsSync = new object();
            s_linger = TimeSpan.Zero;

            // Register to destroy the context when application exit
            AppDomain.CurrentDomain.ProcessExit += ProcessExitTerminateContext;
        }
コード例 #3
0
ファイル: IOThread.cs プロジェクト: awb99/netmq
        /// <summary>
        /// Create a new IOThread object within the given context (Ctx) and thread.
        /// </summary>
        /// <param name="ctx">the Ctx (context) for this thread to live within</param>
        /// <param name="threadId">the integer thread-id for this new IOThread</param>
        public IOThread( Ctx ctx, int threadId)
            : base(ctx, threadId)
        {
            var name = "iothread-" + threadId;
            m_proactor = new Proactor(name);
            m_mailbox = new IOThreadMailbox(name, m_proactor, this);

#if DEBUG
            m_name = name;
#endif
        }
コード例 #4
0
ファイル: NetMQConfig.cs プロジェクト: NetMQ/NetMQ3-x
 /// <summary>
 /// Cleanup library resources, call this method when your process is shutting-down.
 /// </summary>
 /// <param name="block">Set to true when you want to make sure sockets send all pending messages</param>
 public static void Cleanup(bool block = true)
 {
     lock (s_sync)
     {
         if (s_ctx != null)
         {
             s_ctx.Block = block; 
             s_ctx.Terminate();
             s_ctx = null;
         }
     }
 }
コード例 #5
0
ファイル: Reaper.cs プロジェクト: awb99/netmq
        /// <summary>
        /// Create a new Reaper with the given thread-id.
        /// This will have a new Poller with the name "reaper-" + thread-id, and a Mailbox of that same name.
        /// </summary>
        /// <param name="ctx">the Ctx for this to be in</param>
        /// <param name="threadId">an integer id to give to the thread this will live on</param>
        public Reaper( Ctx ctx, int threadId)
            : base(ctx, threadId)
        {
            m_sockets = 0;
            m_terminating = false;

            string name = "reaper-" + threadId;
            m_poller = new Utils.Poller(name);

            m_mailbox = new Mailbox(name);

            m_mailboxHandle = m_mailbox.Handle;
            m_poller.AddHandle(m_mailboxHandle, this);
            m_poller.SetPollIn(m_mailboxHandle);
        }
コード例 #6
0
ファイル: NetMQConfig.cs プロジェクト: cjkao/netmq
        /// <summary>
        /// For use in testing
        /// </summary>
        internal static void DisableManualTermination()
        {
            if (!s_manualTakeOver) return;
            s_manualTakeOver = false;
            var isTerminated = false;
            try
            {
                s_ctx.CheckDisposed();
            }
            catch (ObjectDisposedException)
            {
                isTerminated = true;
            }

            // Only creates if we don't have a context.
            if (isTerminated)
                s_ctx = new Ctx { Block = false };
        }
コード例 #7
0
ファイル: NetMQContext.cs プロジェクト: hdxhan/netmq
 private NetMQContext([NotNull] Ctx ctx)
 {
     m_ctx = ctx;
 }
コード例 #8
0
ファイル: ZObject.cs プロジェクト: sharpe5/netmq
 /// <summary>
 /// Create a new ZObject with the given context and thread-id.
 /// </summary>
 /// <param name="ctx">the context for the new ZObject to live within</param>
 /// <param name="threadId">the integer thread-id for the new ZObject to be associated with</param>
 protected ZObject([NotNull] Ctx ctx, int threadId)
 {
     m_ctx = ctx;
     m_threadId = threadId;
 }
コード例 #9
0
ファイル: ZObject.cs プロジェクト: awb99/netmq
 protected bool RegisterEndpoint( string addr,  Ctx.Endpoint endpoint)
 {
     return m_ctx.RegisterEndpoint(addr, endpoint);
 }
コード例 #10
0
ファイル: ZObject.cs プロジェクト: awb99/netmq
 /// <summary>
 /// Create a new ZObject with the given context and thread-id.
 /// </summary>
 /// <param name="ctx">the context for the new ZObject to live within</param>
 /// <param name="threadId">the integer thread-id for the new ZObject to be associated with</param>
 protected ZObject( Ctx ctx, int threadId)
 {
     m_ctx = ctx;
     m_threadId = threadId;
 }
コード例 #11
0
ファイル: NetMQConfig.cs プロジェクト: cjkao/netmq
        /// <summary>
        /// Create a context, if needed.
        /// </summary>
        /// <param name="block">Should the context block the thread while terminating.</param>
        public static void ContextCreate(bool block=false)
        {
            // Move along, nothing to see here :)
            if (!s_manualTakeOver) return;

            var isTerminated = false;
            try
            {
                s_ctx.CheckDisposed();
            }
            catch (ObjectDisposedException)
            {
                isTerminated = true;
            }

            // Only creates if we don't have a context.
            if(isTerminated)
                s_ctx = new Ctx { Block = block };
        }
コード例 #12
0
ファイル: Own.cs プロジェクト: awb99/netmq
 /// <summary>
 /// Initializes a new instance of the <see cref="Own" /> class that is running on a thread outside of 0MQ infrastructure.
 /// </summary>
 /// <param name="parent">The parent context.</param>
 /// <param name="threadId">The thread id.</param>
 /// <remarks>
 /// Note that the owner is unspecified in the constructor. It'll be assigned later on using <see cref="SetOwner"/>
 /// when the object is plugged in.
 /// </remarks>
 protected Own( Ctx parent, int threadId)
     : base(parent, threadId)
 {
     m_options = new Options();
 }
コード例 #13
0
 /// <summary>
 /// Create a new ZObject with the given context and thread-id.
 /// </summary>
 /// <param name="ctx">the context for the new ZObject to live within</param>
 /// <param name="threadId">the integer thread-id for the new ZObject to be associated with</param>
 protected ZObject([NotNull] Ctx ctx, int threadId)
 {
     m_ctx      = ctx;
     m_threadId = threadId;
 }
コード例 #14
0
ファイル: NetMQContext.cs プロジェクト: awb99/netmq
 private NetMQContext( Ctx ctx)
 {
     m_ctx = ctx;
 }
コード例 #15
0
ファイル: SocketBase.cs プロジェクト: awb99/netmq
 /// <summary>
 /// Create a socket of a specified type.
 /// </summary>
 /// <param name="type">a ZmqSocketType specifying the type of socket to create</param>
 /// <param name="parent">the parent context</param>
 /// <param name="threadId">the thread for this new socket to run on</param>
 /// <param name="socketId">an integer id for this socket</param>
 /// <exception cref="InvalidException">The socket type must be valid.</exception>
 
 public static SocketBase Create(ZmqSocketType type,  Ctx parent, int threadId, int socketId)
 {
     switch (type)
     {
         case ZmqSocketType.Pair:
             return new Pair(parent, threadId, socketId);
         case ZmqSocketType.Pub:
             return new Pub(parent, threadId, socketId);
         case ZmqSocketType.Sub:
             return new Sub(parent, threadId, socketId);
         case ZmqSocketType.Req:
             return new Req(parent, threadId, socketId);
         case ZmqSocketType.Rep:
             return new Rep(parent, threadId, socketId);
         case ZmqSocketType.Dealer:
             return new Dealer(parent, threadId, socketId);
         case ZmqSocketType.Router:
             return new Router(parent, threadId, socketId);
         case ZmqSocketType.Pull:
             return new Pull(parent, threadId, socketId);
         case ZmqSocketType.Push:
             return new Push(parent, threadId, socketId);
         case ZmqSocketType.Xpub:
             return new XPub(parent, threadId, socketId);
         case ZmqSocketType.Xsub:
             return new XSub(parent, threadId, socketId);
         case ZmqSocketType.Stream:
             return new Stream(parent, threadId, socketId);
         default:
             throw new InvalidException("SocketBase.Create called with invalid type of " + type);
     }
 }
コード例 #16
0
ファイル: SocketBase.cs プロジェクト: awb99/netmq
 /// <summary>
 /// Create a new SocketBase within the given Ctx, with the specified thread-id and socket-id.
 /// </summary>
 /// <param name="parent">the Ctx context that this socket will live within</param>
 /// <param name="threadId">the id of the thread upon which this socket will execute</param>
 /// <param name="socketId">the integer id for the new socket</param>
 protected SocketBase( Ctx parent, int threadId, int socketId)
     : base(parent, threadId)
 {
     m_options.SocketId = socketId;
     m_mailbox = new Mailbox("socket-" + socketId);
 }