1 # A simple IPC server executing Ruby programs.
19 d = "dispatch_#{c.downcase}"
20 if respond_to?(d, true)
25 puts("ERR 103 Unknown command\r\n")
30 def dispatch_cancel(c, r)
31 puts("ERR 100 Not implemented\r\n")
34 def dispatch_bye(c, r)
35 puts("ERR 100 Not implemented\r\n")
38 def dispatch_auth(c, r)
39 puts("ERR 100 Not implemented\r\n")
42 def dispatch_reset(c, r)
43 puts("ERR 100 Not implemented\r\n")
46 def dispatch_end(c, r)
50 def dispatch_help(c, r)
51 puts("ERR 100 Not implemented\r\n")
54 def dispatch_quit(c, r)
55 puts("ERR 100 Not implemented\r\n")
58 def dispatch_eval(c, r)
59 name, code = r.split(/\s+/, 2)
60 if @thr.include?(name) && @thr[name].alive?
61 puts("ERR 105 Parameter error: \"#{name}\" is already in use\r\n")
64 code = deq_data unless code
67 @thr[name] = Thread.current
68 Thread.current[:rubyserv_name] = name
70 Thread.current[:rubyserv_error] = false
71 Thread.current[:rubyserv_response] = eval(code)
73 Thread.current[:rubyserv_error] = true
74 Thread.current[:rubyserv_response] = e
76 puts("# exit #{name}\r\n")
79 def dispatch_poll(c, r)
82 puts("ERR 105 Parameter error: no such name \"#{r}\"\r\n")
84 puts("S program running\r\n")
88 if thr[:rubyserv_error]
89 puts("S program exited\r\n")
91 puts("S program finished\r\n")
93 if d = thr[:rubyserv_response]
101 s.gsub(/[%\r\n]/) {|m| '%%%02X' % m[0]}
105 s.gsub(/%([0-9A-Z][0-9A-Z])/, ['\1'].pack('H*'))
109 puts("# output #{Thread.current[:rubyserv_name]} #{s}\r\n")
115 len = [d.length, 998].min # 998 = 1000 - "D "
116 puts("D #{d[0 ... len]}\r\n")