Esempio n. 1
0
 private void WritePipe()
 {
     while (IsConnected && m_StreamWrapper.CanWrite)
     {
         m_WriteSignal.WaitOne();
         while (m_WriteQueue.Count > 0)
         {
             m_StreamWrapper.WriteMessage(m_WriteQueue.Dequeue());
             m_StreamWrapper.WaitForPipeDrain();
         }
     }
 }
Esempio n. 2
0
        private void WaitForConnection(string p_PipeName)
        {
            NamedPipeServerStream s_HandshakePipe = null;
            NamedPipeServerStream s_DataPipe      = null;
            PipeConnection        s_Connection    = null;

            var s_ConnectionPipeName = GetNextConnectionPipeName(p_PipeName);

            try
            {
                s_HandshakePipe = PipeServerFactory.CreateAndConnectPipe(p_PipeName);
                var s_HandshakeWrapper = new PipeStreamWrapper(s_HandshakePipe);
                s_HandshakeWrapper.WriteMessage(new PipeMessage()
                {
                    Module = "SM", Type = "HS", Content = s_ConnectionPipeName
                });
                s_HandshakeWrapper.WaitForPipeDrain();
                s_HandshakeWrapper.Close();

                s_DataPipe = PipeServerFactory.CreatePipe(s_ConnectionPipeName);
                s_DataPipe.WaitForConnection();

                s_Connection = ConnectionFactory.CreateConnection(s_DataPipe);
                s_Connection.ReceiveMessage += ClientOnReceiveMessage;
                s_Connection.Disconnected   += ClientOnDisconnected;
                s_Connection.Open();

                lock (m_Connections)
                    m_Connections.Add(s_Connection);

                ClientOnConnected(s_Connection);
            }
            catch (Exception)
            {
                Cleanup(s_HandshakePipe);
                Cleanup(s_DataPipe);
                ClientOnDisconnected(s_Connection);
            }
        }