diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-06-14 09:25:06 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-06-14 09:25:06 +0000 |
commit | 3676a70e7b0fcee8a956c6ac8922744a82860876 (patch) | |
tree | ee9ec5b7e909fbddc0fb8a0a972864c7aa4a24a9 /ext/tk | |
parent | db71ceb9c09d555015f9c632dd04b6b2bcaf4914 (diff) | |
download | ruby-3676a70e7b0fcee8a956c6ac8922744a82860876.tar.gz |
* ext/tk/lib/remote-tk.rb: bug fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/lib/remote-tk.rb | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb index 79fb20380c..bdee25e060 100644 --- a/ext/tk/lib/remote-tk.rb +++ b/ext/tk/lib/remote-tk.rb @@ -11,11 +11,11 @@ class RemoteTkIp < MultiTkIp; end class MultiTkIp @@IP_TABLE = {}.taint unless defined?(@@IP_TABLE) - @@TK_TABLE_LIST = {}.taint unless defined?(@@TK_TABLE_LIST) + @@TK_TABLE_LIST = [].taint unless defined?(@@TK_TABLE_LIST) def self._IP_TABLE; @@IP_TABLE; end def self._TK_TABLE_LIST; @@TK_TABLE_LIST; end end -class RemoteTkIp < MultiTkIp +class RemoteTkIp @@IP_TABLE = MultiTkIp._IP_TABLE unless defined?(@@IP_TABLE) @@TK_TABLE_LIST = MultiTkIp._TK_TABLE_LIST unless defined?(@@TK_TABLE_LIST) end @@ -28,10 +28,21 @@ require 'multi-tk' ############################### -class RemoteTkIp < MultiTkIp +class << RemoteTkIp + undef new_master, new_slave, new_safe_slave + undef new_trusted_slave, new_safeTk + + def new(*args, &b) + ip = __new(*args) + ip.eval_proc(&b) if b + ip + end +end + +class RemoteTkIp include TkUtil - def initialize(remote_ip, displayof=nil) + def initialize(remote_ip, displayof=nil, timeout=5) if $SAFE >= 4 fail SecurityError, "cannot access another interpreter at level #{$SAFE}" end @@ -77,6 +88,10 @@ class RemoteTkIp < MultiTkIp @tk_table_list << tbl } + @ret_val = TkVariable.new + if timeout > 0 && ! _available_check(timeout) + fail RuntimeError, "cannot create connection" + end @ip_id = _create_connection self.freeze # defend against modification @@ -86,6 +101,24 @@ class RemoteTkIp < MultiTkIp @ip_id end + def _available_check(timeout = 5) + return nil if timeout < 1 + @ret_val.value = '' + @interp._invoke('send', '-async', @remote, + 'send', '-async', Tk.appname, + "set #{@ret_val.id} ready") + Tk.update + if @ret_val != 'ready' + (1..(timeout*5)).each{ + sleep 0.2 + Tk.update + break if @ret_val == 'ready' + } + end + @ret_val.value == 'ready' + end + private :_available_check + def _create_connection ip_id = '_' + @interp._invoke('send', @remote, <<-'EOS') + '_' if {[catch {set _rubytk_control_ip_id_} ret] != 0} { @@ -133,12 +166,17 @@ class RemoteTkIp < MultiTkIp end private :_appsend - def is_rubytk? - if _appsend(false, false, 'info', 'command', 'ruby') == "" - false - else - true + def ready?(timeout=5) + if timeout < 0 + fail ArgumentError, "timeout must be positive number" end + _available_check(timeout) + end + + def is_rubytk? + return false if _appsend(false, false, 'info', 'command', 'ruby') == "" + [ _appsend(false, false, 'ruby', 'RUBY_VERSION'), + _appsend(false, false, 'set', 'tk_patchLevel') ] end def appsend(async, *args) @@ -350,17 +388,6 @@ class RemoteTkIp < MultiTkIp end class << RemoteTkIp - undef new_master, new_slave, new_safe_slave - undef new_trusted_slave, new_safeTk - - def new(ip_name, displayof=nil, &b) - ip = __new(ip_name, displayof) - ip.eval_proc(&b) if b - ip - end -end - -class << RemoteTkIp def mainloop fail RuntimeError, 'not support "mainloop" on the remote interpreter' end |