Class: RuntimeInspection::Thread

Inherits:
Thread
  • Object
show all
Defined in:
lib/rti/thread.rb

Overview

A thread that exposes inspection and debugging functionality over a TCP socket.

Defined Under Namespace

Classes: EvalReturn

Instance Method Summary collapse

Methods inherited from Thread

#inspect_without_name, #to_s_without_name

Constructor Details

#initialize(host = 'localhost', port = 56789, binding = TOPLEVEL_BINDING, prompt_name = File.basename($0,'.rb')) ⇒ Thread

Create a new inspection thread.

host

What address to listen on.

port

What port to listen on.

binding

In what context should the evaluations be run?

prompt_name

What name to use in the prompt.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rti/thread.rb', line 27

def initialize( host='localhost', port=56789, binding=TOPLEVEL_BINDING,
                prompt_name=File.basename($0,'.rb') )

    @server = TCPServer.new( host, port )
    @binding = binding

    OPTS[:dbg_handler].call "Runtime inspection available at " +
        "#{host}:#{port}"

    @breakpoints = {}
    @tracing_proc = method( :handle_tracing ).to_proc

    @clients = []
    @clients_mutex = Mutex.new
    @dead_clients = Queue.new

    run_gc_thread

    super do
        begin
            while sockets = select( [@server] )
                sockets.first.each do |socket|
                    socket = @server.accept
                    def socket.set_peerstr
                        unless closed?
                            peer = peeraddr
                            @peerstr = "#{peer[3]}:#{peer[1]}"
                        end
                    end
                    socket.set_peerstr
                    def socket.to_s
                        @peerstr or super
                    end
                    def socket.inspect
                        super.chop + " #{to_s}>"
                    end

                    OPTS[:dbg_handler].call "Connection established " +
                        "with #{socket}"

                    run_client_thread( prompt_name, socket )
                end
            end
        rescue Object => e
            OPTS[:exc_handler].call( "running inspection thread", e )
        end
    end
end

Instance Method Details

#exitObject

:nodoc:



98
99
100
101
# File 'lib/rti/thread.rb', line 98

def exit # :nodoc:
    super
    cleanup
end

#inspectObject

Remaining functions are just overrides for ::Thread class and then private stuff.



80
81
82
# File 'lib/rti/thread.rb', line 80

def inspect # :nodoc:
    super.chop + " #{@clients.inspect}>"
end

#killObject

:nodoc:



93
94
95
96
# File 'lib/rti/thread.rb', line 93

def kill # :nodoc:
    super
    cleanup
end

#terminateObject

:nodoc:



88
89
90
91
# File 'lib/rti/thread.rb', line 88

def terminate # :nodoc:
    super
    cleanup
end

#to_sObject

:nodoc:



84
85
86
# File 'lib/rti/thread.rb', line 84

def to_s # :nodoc:
    inspect
end