예제 #1
0
            /// <summary>
            /// loop on created thread which processes communicates with the REPL window
            /// </summary>
            private void ReplLoop()
            {
                try
                {
                    byte[] inp  = new byte[4];
                    int    size = 0;
                    while (true)
                    {
                        if (this.CheckForExitReplLoop())
                        {
                            break;
                        }

                        /* we receive a series of 4 byte commands. Each command then has it's
                         * own format which we must parse before continuing to the next command. */
                        this.Flush();
                        this._stream.ReadTimeout = 10000; // 10 sec
                        try
                        {
                            size = this._stream.Read(inp, 0, 4);
                        }
                        catch (IOException ex)
                        {
                            SocketException se = null;
                            if (null != ex.InnerException && null != (se = ex.InnerException as SocketException) && SocketError.TimedOut == se.SocketErrorCode)
                            {
#if DEBUG
                                ReplProcessor.DebugWrite("Time out reading from server.");
#endif
                                continue;
                            }
                            throw;
                        }
                        this._stream.ReadTimeout = Timeout.Infinite;

                        if (size < 1)
                        {
                            break;
                        }
                        this.Flush();
                        Action cmd = null;
                        if (this._COMMANDS.TryGetValue(ReplProcessor.Cmd(inp), out cmd))
                        {
                            cmd();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ReplProcessor.DebugWrite("Error in ReplLoop");
                    ReplProcessor.DebugWrite(ex.ToString());
                    this.ExitProcess();
                    Thread.Sleep(2000);   // try and exit gracefully, then interrupt main if necessary
                    Environment.Exit(1);
                    this.InterruptMain(); // will never happen
                }
            }
예제 #2
0
 private void Send(params string[] data)
 {
     if (null == data || 0 == data.Length)
     {
         return;
     }
     using (new SendLock(this))
     {
         foreach (var d in data)
         {
             ReplProcessor.DebugWrite(d + '\n');
             this._stream.Write(ReplProcessor.Cmd(d));
         }
     }
 }
예제 #3
0
 static ReplBackend()
 {
     _MRES           = ReplProcessor.Cmd("MRES");
     _SRES           = ReplProcessor.Cmd("SRES");
     _LOCS           = ReplProcessor.Cmd("LOCS");
     _IMGD           = ReplProcessor.Cmd("IMGD");
     _PRPC           = ReplProcessor.Cmd("PRPC");
     _RDLN           = ReplProcessor.Cmd("RDLN");
     _STDO           = ReplProcessor.Cmd("STDO");
     _STDE           = ReplProcessor.Cmd("STDE");
     _DBGA           = ReplProcessor.Cmd("DBGA");
     _DETC           = ReplProcessor.Cmd("DETC");
     _DPNG           = ReplProcessor.Cmd("DPNG");
     _UNICODE_PREFIX = ReplProcessor.Cmd("U");
     _ASCII_PREFIX   = ReplProcessor.Cmd("A");
 }