Beispiel #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
                }
            }
Beispiel #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));
         }
     }
 }
Beispiel #3
0
            /// <summary>
            /// gets the signatures for the given expression
            /// </summary>
            private void CmdSigs()
            {
                string expression = this.ReadString();
                object sigs       = null;

                try
                {
                    // TODO
                    sigs = this.GetSignatures();
                }
                catch (Exception ex)
                {
                    this.Send("SERR");
                    ReplProcessor.DebugWrite("error in eval");
                    ReplProcessor.DebugWrite(ex.ToString());
                    return;
                }
                using (new SendLock(this))
                {
                    this._stream.Write(ReplBackend._SRES);
                    // TODO
                }
            }
Beispiel #4
0
            /// <summary>
            /// gets the list of members available for the given expression
            /// </summary>
            private void CmdMems()
            {
                string      expression = this.ReadString();
                MemberTuple memberTuple;

                try
                {
                    memberTuple = this.GetMembers(expression);
                }
                catch (Exception ex)
                {
                    this.Send("MERR");
                    ReplProcessor.DebugWrite("error in eval");
                    ReplProcessor.DebugWrite(ex.ToString());
                    return;
                }
                using (new SendLock(this))
                {
                    this._stream.Write(ReplBackend._MRES);
                    this.WriteString(memberTuple.Name);
                    this.WriteMemberDict(memberTuple.InstMembers);
                    this.WriteMemberDict(memberTuple.TypeMembers);
                }
            }