Esempio n. 1
0
        //  When migrating an object from one I/O thread to another, first
        //  unplug it, then migrate it, then plug it to the new thread.
        public void Plug(IOThread ioThread)
        {
            Debug.Assert(ioThread != null);
            Debug.Assert(m_poller == null);

            //  Retrieve the poller from the thread we are running in.
            m_poller = ioThread.GetPoller ();
        }
Esempio n. 2
0
File: Own.cs Progetto: knocte/netmq
        //  The object is living within I/O thread.
        public Own(IOThread ioThread, Options options)
            : base(ioThread)
        {
            m_options = options;
            m_terminating = false;
            m_sentSeqnum = new AtomicLong(0);
            m_processedSeqnum = 0;
            m_owner = null;
            m_termAcks = 0;

            owned = new HashSet<Own>();
        }
Esempio n. 3
0
        public TcpConnecter(IOThread ioThread,
            SessionBase session, Options options,
            Address addr, bool delayedStart)
            : base(ioThread, options)
        {
            m_ioObject = new IOObject(ioThread);
            m_addr = addr;
            m_handle = null;
            m_handleValid = false;
            m_delayedStart = delayedStart;
            m_timerStarted = false;
            m_session = session;
            m_currentReconnectIvl = m_options.ReconnectIvl;

            Debug.Assert(m_addr != null);
            m_endpoint = m_addr.ToString();
            m_socket = session.Socket;
        }
Esempio n. 4
0
        public SessionBase(IOThread ioThread, bool connect,
            SocketBase socket, Options options, Address addr)
            : base(ioThread, options)
        {
            m_ioObject = new IOObject(ioThread);

            m_connect = connect;
            m_pipe = null;
            m_incompleteIn = false;
            m_pending = false;
            m_engine = null;
            m_socket = socket;
            m_ioThread = ioThread;
            m_hasLingerTimer = false;
            m_identitySent = false;
            m_identityReceived = false;
            m_addr = addr;

            m_terminatingPipes = new HashSet <Pipe> ();
        }
Esempio n. 5
0
 public RouterSession(IOThread ioThread, bool connect,
     SocketBase socket, Options options,
     Address addr)
     : base(ioThread, connect, socket, options, addr)
 {
 }
Esempio n. 6
0
 public IpcListener(IOThread ioThread, SocketBase socket, Options options)
     : base(ioThread, socket, options)
 {
     m_address = new IpcAddress();
 }
Esempio n. 7
0
File: Req.cs Progetto: knocte/netmq
 public ReqSession(IOThread ioThread, bool connect,
     SocketBase socket, Options options,
     Address addr)
     : base(ioThread, connect, socket, options, addr)
 {
     m_state = State.Identity;
 }
Esempio n. 8
0
 public IOObject(IOThread ioThread)
 {
     if (ioThread != null) {
         Plug(ioThread);
     }
 }
Esempio n. 9
0
        public static SessionBase Create(IOThread ioThread, bool connect,
            SocketBase socket, Options options, Address addr)
        {
            SessionBase s;
            switch (options.SocketType) {
                case ZmqSocketType.Req:
                    s = new  Req.ReqSession (ioThread, connect,
                                             socket, options, addr);
                    break;
                case ZmqSocketType.Dealer:
                    s = new Dealer.DealerSession (ioThread, connect,
                                                  socket, options, addr);
                    break;
                case ZmqSocketType.Rep:
                    s = new Rep.RepSession (ioThread, connect,
                                            socket, options, addr);
                    break;
                case ZmqSocketType.Router:
                    s = new Router.RouterSession (ioThread, connect,
                                                  socket, options, addr);
                    break;
                case ZmqSocketType.Pub:
                    s = new Pub.PubSession (ioThread, connect,
                                            socket, options, addr);
                    break;
                case ZmqSocketType.Xpub:
                    s = new XPub.XPubSession(ioThread, connect,
                                             socket, options, addr);
                    break;
                case ZmqSocketType.Sub:
                    s = new  Sub.SubSession (ioThread, connect,
                                             socket, options, addr);
                    break;
                case ZmqSocketType.Xsub:
                    s = new XSub.XSubSession (ioThread, connect,
                                              socket, options, addr);
                    break;

                case ZmqSocketType.Push:
                    s = new Push.PushSession (ioThread, connect,
                                              socket, options, addr);
                    break;
                case ZmqSocketType.Pull:
                    s = new Pull.PullSession (ioThread, connect,
                                              socket, options, addr);
                    break;
                case ZmqSocketType.Pair:
                    s = new Pair.PairSession (ioThread, connect,
                                              socket, options, addr);
                    break;
                default:
                    throw new ArgumentException("type=" + options.SocketType);
            }
            return s;
        }
Esempio n. 10
0
File: Ctx.cs Progetto: knocte/netmq
        public SocketBase CreateSocket(ZmqSocketType type)
        {
            SocketBase s = null;
            lock (slot_sync)
            {
                if (m_starting)
                {

                    m_starting = false;
                    //  Initialise the array of mailboxes. Additional three slots are for
                    //  zmq_term thread and reaper thread.

                    int ios;
                    int mazmq;

                    lock (m_optSync)
                    {
                        mazmq = m_maxSockets;
                        ios = m_ioThreadCount;
                    }
                    m_slotCount = mazmq + ios + 2;
                    m_slots = new Mailbox[m_slotCount];
                    //alloc_Debug.Assert(slots);

                    //  Initialise the infrastructure for zmq_term thread.
                    m_slots[TermTid] = term_mailbox;

                    //  Create the reaper thread.
                    m_reaper = new Reaper(this, ReaperTid);
                    //alloc_Debug.Assert(reaper);
                    m_slots[ReaperTid] = m_reaper.Mailbox;
                    m_reaper.Start();

                    //  Create I/O thread objects and launch them.
                    for (int i = 2; i != ios + 2; i++)
                    {
                        IOThread ioThread = new IOThread(this, i);
                        //alloc_Debug.Assert(io_thread);
                        m_ioThreads.Add(ioThread);
                        m_slots[i] = ioThread.Mailbox;
                        ioThread.Start();
                    }

                    //  In the unused part of the slot array, create a list of empty slots.
                    for (int i = (int)m_slotCount - 1;
                         i >= (int)ios + 2; i--)
                    {
                        empty_slots.AddToBack(i);
                        m_slots[i] = null;
                    }

                }

                //  Once zmq_term() was called, we can't create new sockets.
                if (m_terminating)
                {
                    ZError.ErrorNumber = ErrorNumber.ETERM;
                    return null;
                }

                //  If max_sockets limit was reached, return error.
                if (empty_slots.Count == 0)
                {
                    ZError.ErrorNumber = ErrorNumber.EMFILE;
                    return null;
                }

                //  Choose a slot for the socket.
                int slot = empty_slots.RemoveFromBack();

                //  Generate new unique socket ID.
                int sid = s_maxSocketId.IncrementAndGet();

                //  Create the socket and register its mailbox.
                s = SocketBase.Create(type, this, slot, sid);
                if (s == null)
                {
                    empty_slots.AddToBack(slot);
                    return null;
                }
                sockets.Add(s);
                m_slots[slot] = s.Mailbox;

                //LOG.debug("NEW Slot [" + slot + "] " + s);
            }

            return s;
        }
Esempio n. 11
0
        public void Plug(IOThread ioThread,
            SessionBase session)
        {
            Debug.Assert(!m_plugged);
            m_plugged = true;

            //  Connect to session object.
            Debug.Assert(m_session == null);
            Debug.Assert(session != null);
            m_session = session;
            m_socket = m_session.Socket;

            m_ioObject = new IOObject(null);
            m_ioObject.SetHandler(this);
            //  Connect to I/O threads poller object.
            m_ioObject.Plug(ioThread);
            m_ioObject.AddFd(m_handle);

            //  Send the 'length' and 'flags' fields of the identity message.
            //  The 'length' field is encoded in the long format.

            m_greetingOutputBuffer[m_outsize++] = ((byte) 0xff);
            m_greetingOutputBuffer.PutLong((long) m_options.IdentitySize + 1, 1);
            m_outsize += 8;
            m_greetingOutputBuffer[m_outsize++] = ((byte) 0x7f);

            m_outpos = new ByteArraySegment(m_greetingOutputBuffer);

            m_ioObject.SetPollin(m_handle);
            m_ioObject.SetPollout(m_handle);

            //  Flush all the data that may have been already received downstream.
            InEvent();
        }