From: ueno Date: Thu, 11 Aug 2005 03:58:23 +0000 (+0000) Subject: * server.rb: Renamed from rubyserv.rb. X-Git-Tag: channel-coding-branchpoint~169 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=ea796f717bd096934ae6ed811a904fc5aae66102;p=elisp%2Friece.git * server.rb: Renamed from rubyserv.rb. * riece-ruby.el (riece-ruby-server-program): Follow the filename change. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6bbb578..0c498b8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2005-08-11 Daiki Ueno + * server.rb: Renamed from rubyserv.rb. + * riece-ruby.el (riece-ruby-server-program): Follow the filename + change. + +2005-08-11 Daiki Ueno + * riece-ruby.el: Fixed example. (riece-ruby-server-program): New variable. (riece-ruby-status-alist): New variable. diff --git a/lisp/riece-ruby.el b/lisp/riece-ruby.el index db1bcbc..4759f10 100644 --- a/lisp/riece-ruby.el +++ b/lisp/riece-ruby.el @@ -51,7 +51,7 @@ (defvar riece-ruby-command "ruby" "Command name for Ruby interpreter.") -(defvar riece-ruby-server-program "rubyserv.rb") +(defvar riece-ruby-server-program "server.rb") (defvar riece-ruby-process nil) diff --git a/lisp/rubyserv.rb b/lisp/rubyserv.rb deleted file mode 100644 index cc29694..0000000 --- a/lisp/rubyserv.rb +++ /dev/null @@ -1,152 +0,0 @@ -# A simple IPC server executing Ruby programs. - -require 'thread' - -class RubyServ - module C - end - - def initialize - @buf = '' - @que = Queue.new - @thr = Hash.new - @cnt = 0 - end - - def dispatch(line) - case line.chomp - when /\AD / - @buf << $' - when /\A(\S+)\s*/ - c = $1 - r = $' - d = "dispatch_#{c.downcase}" - if respond_to?(d, true) - Thread.start do - self.send(d, c, r) - end - else - puts("ERR 103 Unknown command\r\n") - end - end - end - - def dispatch_cancel(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_bye(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_auth(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_reset(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_end(c, r) - enq_data - end - - def dispatch_help(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_quit(c, r) - puts("ERR 100 Not implemented\r\n") - end - - def dispatch_eval(c, r) - r = deq_data if r.empty? - name = nil - Thread.exclusive do - while @thr.include?(name = @cnt.to_s) - @cnt += 1 - end - @thr[name] = Thread.current - end - puts("S name #{name}\r\n") - puts("OK\r\n") - Thread.current[:rubyserv_name] = name - begin - Thread.current[:rubyserv_error] = false - Thread.current[:rubyserv_response] = eval(r, C.module_eval('binding()')) - rescue Exception => e - Thread.current[:rubyserv_error] = true - Thread.current[:rubyserv_response] = e - end - puts("# exit #{name}\r\n") - end - - def dispatch_poll(c, r) - thr = @thr[r] - if !thr - puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n") - elsif thr.alive? - puts("S running #{r}\r\n") - puts("OK\r\n") - else - if thr[:rubyserv_error] - puts("S exited #{r}\r\n") - else - puts("S finished #{r}\r\n") - end - if d = thr[:rubyserv_response] - send_data(d.to_s) - end - puts("OK\r\n") - end - end - - def dispatch_exit(c, r) - thr = @thr[r] - if !thr - puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n") - return - end - thr.kill if thr.alive? - @thr.delete(r) - puts("OK\r\n") - end - - def escape(s) - s.gsub(/[%\r\n]/) {|m| '%%%02X' % m[0]} - end - - def unescape(s) - s.gsub(/%([0-9A-Z][0-9A-Z])/, ['\1'].pack('H*')) - end - - def output(s) - puts("# output #{Thread.current[:rubyserv_name]} #{s}\r\n") - end - - def send_data(d) - d = escape(d) - begin - len = [d.length, 998].min # 998 = 1000 - "D " - puts("D #{d[0 ... len]}\r\n") - d = d[len .. -1] - end until d.empty? - end - - def enq_data - d = unescape(@buf) - @buf = '' - @que.enq(d) - end - - def deq_data - @que.deq - end -end - -if $0 == __FILE__ - serv = RubyServ.new - while gets - serv.dispatch($_) - end -end diff --git a/lisp/server.rb b/lisp/server.rb new file mode 100644 index 0000000..cc29694 --- /dev/null +++ b/lisp/server.rb @@ -0,0 +1,152 @@ +# A simple IPC server executing Ruby programs. + +require 'thread' + +class RubyServ + module C + end + + def initialize + @buf = '' + @que = Queue.new + @thr = Hash.new + @cnt = 0 + end + + def dispatch(line) + case line.chomp + when /\AD / + @buf << $' + when /\A(\S+)\s*/ + c = $1 + r = $' + d = "dispatch_#{c.downcase}" + if respond_to?(d, true) + Thread.start do + self.send(d, c, r) + end + else + puts("ERR 103 Unknown command\r\n") + end + end + end + + def dispatch_cancel(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_bye(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_auth(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_reset(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_end(c, r) + enq_data + end + + def dispatch_help(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_quit(c, r) + puts("ERR 100 Not implemented\r\n") + end + + def dispatch_eval(c, r) + r = deq_data if r.empty? + name = nil + Thread.exclusive do + while @thr.include?(name = @cnt.to_s) + @cnt += 1 + end + @thr[name] = Thread.current + end + puts("S name #{name}\r\n") + puts("OK\r\n") + Thread.current[:rubyserv_name] = name + begin + Thread.current[:rubyserv_error] = false + Thread.current[:rubyserv_response] = eval(r, C.module_eval('binding()')) + rescue Exception => e + Thread.current[:rubyserv_error] = true + Thread.current[:rubyserv_response] = e + end + puts("# exit #{name}\r\n") + end + + def dispatch_poll(c, r) + thr = @thr[r] + if !thr + puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n") + elsif thr.alive? + puts("S running #{r}\r\n") + puts("OK\r\n") + else + if thr[:rubyserv_error] + puts("S exited #{r}\r\n") + else + puts("S finished #{r}\r\n") + end + if d = thr[:rubyserv_response] + send_data(d.to_s) + end + puts("OK\r\n") + end + end + + def dispatch_exit(c, r) + thr = @thr[r] + if !thr + puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n") + return + end + thr.kill if thr.alive? + @thr.delete(r) + puts("OK\r\n") + end + + def escape(s) + s.gsub(/[%\r\n]/) {|m| '%%%02X' % m[0]} + end + + def unescape(s) + s.gsub(/%([0-9A-Z][0-9A-Z])/, ['\1'].pack('H*')) + end + + def output(s) + puts("# output #{Thread.current[:rubyserv_name]} #{s}\r\n") + end + + def send_data(d) + d = escape(d) + begin + len = [d.length, 998].min # 998 = 1000 - "D " + puts("D #{d[0 ... len]}\r\n") + d = d[len .. -1] + end until d.empty? + end + + def enq_data + d = unescape(@buf) + @buf = '' + @que.enq(d) + end + + def deq_data + @que.deq + end +end + +if $0 == __FILE__ + serv = RubyServ.new + while gets + serv.dispatch($_) + end +end