summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-14 09:25:06 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-14 09:25:06 +0000
commite961d304689d802a845b35f341c2c8341338026e (patch)
tree3226bdb8f81c81614b4f9c6ed39e024e81053b66
parent084a8c4ecd649f0871c16a596efb767cd8a2534e (diff)
* ext/tk/lib/remote-tk.rb: bug fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/tk/lib/remote-tk.rb67
2 files changed, 51 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index df5a9247f5..19dacb7a18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Jun 14 18:23:27 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/lib/remote-tk.rb: bug fix
+
Sun Jun 13 00:23:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/extconf.rb: [EXPERIMENTAL] MacOS X (darwin) support
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