Esempio n. 1
0
        string ReadLineSub()
        {
            List <byte> rv;

            for (int i = 0; i < StdOutputBuf.Count; ++i)
            {
                byte b;
                b = StdOutputBuf[i];
                if (b == '\r' || b == '\n')
                {
                    var j = i;
                    if (b == '\r')
                    {
                        if (i + 1 < StdOutputBuf.Count && StdOutputBuf[i + 1] == '\n')
                        {
                            ++i;
                        }
                    }
                    lock (lockObj) {
                        rv = StdOutputBuf.GetRange(0, j);
                        StdOutputBuf.RemoveRange(0, i + 1);
                    }
                    string buf = Encoding.UTF8.GetString(rv.ToArray());
                    return(buf);
                    //return Encoding.UTF8.GetString(rv.ToArray());
                }
            }
            return(null);
        }
Esempio n. 2
0
        string ReadString()
        {
            int size = Int32.Parse(ReadLine(), enUS);

            for (int i = 0; i < 15; ++i)
            {
                if (StdOutputBuf.Count >= size)
                {
                    System.Diagnostics.Debug.WriteLine(i);
                    break;
                }
                System.Threading.Thread.Sleep(i < 5 ? 1 : (i < 10 ? 10 : 100));
            }
            if (StdOutputBuf.Count < size)
            {
                System.Threading.Thread.Sleep(100);
            }
            if (StdOutputBuf.Count < size)
            {
                throw new TimeoutException();
            }
            ;
            List <byte> buf;

            lock (lockObj) {
                buf = StdOutputBuf.GetRange(0, size);
                StdOutputBuf.RemoveRange(0, size);
            }
            ReadLine();
            return(Encoding.UTF8.GetString(buf.ToArray()));
        }