1 # A simple IPC server executing Ruby programs.
23 d = "dispatch_#{c.downcase}"
24 if respond_to?(d, true)
29 puts("ERR 103 Unknown command\r\n")
34 def dispatch_cancel(c, r)
35 puts("ERR 100 Not implemented\r\n")
38 def dispatch_bye(c, r)
39 puts("ERR 100 Not implemented\r\n")
42 def dispatch_auth(c, r)
43 puts("ERR 100 Not implemented\r\n")
46 def dispatch_reset(c, r)
47 puts("ERR 100 Not implemented\r\n")
50 def dispatch_end(c, r)
54 def dispatch_help(c, r)
55 puts("ERR 100 Not implemented\r\n")
58 def dispatch_quit(c, r)
59 puts("ERR 100 Not implemented\r\n")
62 def dispatch_eval(c, r)
63 r = deq_data if r.empty?
66 while @thr.include?(name = @cnt.to_s)
69 @thr[name] = Thread.current
71 puts("S name #{name}\r\n")
73 Thread.current[:rubyserv_name] = name
75 Thread.current[:rubyserv_error] = false
76 Thread.current[:rubyserv_response] = eval(r, B.module_eval('binding()'))
78 Thread.current[:rubyserv_error] = true
79 Thread.current[:rubyserv_response] = e
81 puts("# exit #{name}\r\n")
84 def dispatch_poll(c, r)
87 puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n")
89 puts("S running #{r}\r\n")
92 if thr[:rubyserv_error]
93 puts("S exited #{r}\r\n")
95 puts("S finished #{r}\r\n")
97 if d = thr[:rubyserv_response]
104 def dispatch_exit(c, r)
107 puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n")
110 thr.kill if thr.alive?
116 s.gsub(/[%\r\n]/) {|m| '%%%02X' % m[0]}
120 s.gsub(/%([0-9A-Z][0-9A-Z])/, ['\1'].pack('H*'))
124 puts("# output #{Thread.current[:rubyserv_name]} #{s}\r\n")
130 len = [d.length, 998].min # 998 = 1000 - "D "
131 puts("D #{d[0 ... len]}\r\n")