Ejemplo n.º 1
0
 public DtpNodeSessionFrameProcessor(
     DtpNode node,
     DtpNodeSession session,
     Action <DtpNodeSessionFrameProcessor, byte[]> onFrameProcessed)
 {
     m_node             = node;
     m_session          = session;
     m_onFrameProcessed = onFrameProcessed;
     m_thread           = new Thread(ThreadStart)
     {
         IsBackground = true
     };
     m_thread.Start();
 }
        internal DtpNodeSession(DtpNode node, Stream connection, NodeRole localRole)
        {
            Trace.Assert(localRole.HasFlag(NodeRole.Client) != localRole.HasFlag(NodeRole.Server));

            aliveCancellationToken = aliveCancellationTokenSource.Token;

            m_node       = node;
            m_connection = connection;
            m_localRole  = localRole;

            if (m_localRole == NodeRole.Client)
            {
                m_locallyInitiatedUidSet = new UniqueIdentificationSet(kClientLitIdLow, kClientLitIdHigh);
            }
            else // Server
            {
                m_locallyInitiatedUidSet = new UniqueIdentificationSet(kServerLitIdLow, kServerLitIdHigh);
            }

            // - Setup Frame Processing --------------------------------------------------------------
            // : Setup Frame Processors :
            InitializeFrameProcessors(Environment.ProcessorCount);

            // : Setup Reader/Writer Workers :
            m_reader            = new BinaryReader(m_connection, Encoding.Default, true);
            m_frameReaderThread = new Thread(FrameReaderThreadStart)
            {
                IsBackground = true
            };
            m_frameReaderThread.Start();

            m_writer            = new BinaryWriter(m_connection, Encoding.Default, true);
            m_frameWriterThread = new Thread(FrameWriterThreadStart)
            {
                IsBackground = true
            };
            m_frameWriterThread.Start();

            // If we're the client, Send DSP_EX_INIT to elevate from DSP to DSPEx
            // If we're the server, the DSP_EX_INIT opcode will be read by the frame reader thread.
            if (m_localRole == NodeRole.Client)
            {
                m_writer.Write((byte)DTP.DSPEX_INIT);
            }
        }