Esempio n. 1
0
        private void TestHandleBuffer(int rptcnt)
        {
            StringBuilder sb = new StringBuilder();
            string bufcmd = "get bbbbcaacba";
            int cmdcnt = 1024 / (bufcmd.Length + 2);
            for (int i = 0; i < cmdcnt; i++)
            {
                sb.Append(bufcmd + EOL);
            }

            byte[] buffer = Encoding.ASCII.GetBytes(sb.ToString());
            byte[] answer_bytes = null;
            StringBuilder answer = new StringBuilder();
            TransferState testts = new TransferState();
            TimerUtil tu = new TimerUtil();

            for (int hbi = 1; hbi < rptcnt; hbi++)
            {
                HandleBuffer(buffer, buffer.Length, answer, out answer_bytes);
                ts.AddReadBytes(buffer.Length);
                ts.AddWriteBytes(answer_bytes.Length);
            }
            ConsoleLogger.LogMessage(String.Format("TestHandleBuffer Cnt: {0:D} {1:S} {2:S}", rptcnt, tu.GetInterval(), ts.ToStringTS(tu.GetInterval())));
            //throw new Exception("1");
        }
Esempio n. 2
0
        public void DoLoop()
        {
            TimerUtil tu = new TimerUtil();
            TimerUtil tcReadWrite = new TimerUtil();
            tcReadWrite.Stop();
            tcReadWrite.Reset();

            try
            {

                Thread thrReadStream_WriteConsole = new Thread(new ThreadStart(ReadStream_WriteConsole));
                Thread thrReadConsole_WriteStream = new Thread(new ThreadStart(ReadConsole_WriteStream));

                TcpClient client = new TcpClient(hostname, port);
                client.NoDelay = true;

                stream = client.GetStream();

                tcReadWrite.MarkInterval();

                //запускаем потоки
                thrReadStream_WriteConsole.Start();
                thrReadConsole_WriteStream.Start();

                WaitHandle[] wh = new WaitHandle[]
                    {
                        mreServerEndData
                    };
                WaitHandle.WaitAll(wh);
                //server ends data abort thrReadConsoleWriteStream and wait for thrReadStreamWriteConsole
                //thrReadConsole_WriteStream.Abort(); this not work, see http://stackoverflow.com/questions/9479573/interrupt-console-readline

                thrReadStream_WriteConsole.Join();
                thrReadConsole_WriteStream.Join();
            #if VERBOSE

                ConsoleLogger.LogMessage("WaitHandle.WaitAll(wh); exit");
            #endif
            }
            catch (Exception ex)
            {
                ConsoleLogger.LogMessage("Error in DoLoop: "+ex.Message);
            }finally
            {
                ConsoleLogger.LogMessage("TC:" + tu.GetInterval() + " TCReadWrite: " + tcReadWrite.GetInterval());
            }
        }