internal void OnClose()
        {
            ClientClosed = true;

            CloseReceived?.Invoke(this, EventArgs.Empty);

            CheckBothClosed();
        }
Example #2
0
        /// <summary>
        /// Start the psuedoconsole and run the process as shown in
        /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#creating-the-pseudoconsole
        /// </summary>
        public void Run()
        {
            // copy all pseudoconsole output to stdout
            Task.Run(() =>
            {
                var proc = System.Diagnostics.Process.GetProcessById(process.ProcessInfo.dwProcessId);

                var buf = new byte[1024];
                while (!proc.HasExited)
                {
                    var length = reader.Read(buf, 0, buf.Length);
                    if (length == 0)
                    {
                        break;
                    }
                    DataReceived?.Invoke(this, buf.Take(length).ToArray());
                }
                CloseReceived?.Invoke(this, 0);
            });
        }
Example #3
0
        private void MessageLoop()
        {
            var bytes = new byte[1024 * 64];

            while (true)
            {
                var len = _process.StandardOutput.BaseStream.Read(bytes, 0, bytes.Length);
                if (len <= 0)
                {
                    break;
                }

                var data = bytes.Length != len
                    ? bytes.Take(len).ToArray()
                    : bytes;

                DataReceived?.Invoke(this, data);
            }
            EofReceived?.Invoke(this, EventArgs.Empty);
            CloseReceived?.Invoke(this, (uint)_process.ExitCode);
        }
        private void MessageLoop()
        {
            _socket.Connect(_host, _port);
            _connected = true;
            OnData(new byte[0]);
            var bytes = new byte[1024 * 64];

            while (true)
            {
                var len = _socket.Receive(bytes);
                if (len <= 0)
                {
                    break;
                }

                var data = bytes.Length != len
                    ? bytes.Take(len).ToArray()
                    : bytes;

                DataReceived?.Invoke(this, data);
            }
            CloseReceived?.Invoke(this, EventArgs.Empty);
        }