+ name, code = r.split(/\s+/, 2)
+ if @thr.include?(name) && @thr[name].alive?
+ puts("ERR 105 Parameter error: \"#{name}\" is already in use\r\n")
+ return
+ end
+ code = deq_data unless code
+ puts("OK\r\n")
+ @thr[name] = Thread.current
+ Thread.current[:rubyserv_name] = name
+ begin
+ Thread.current[:rubyserv_error] = false
+ Thread.current[:rubyserv_response] = eval(code)
+ rescue Exception => e
+ Thread.current[:rubyserv_error] = true
+ Thread.current[:rubyserv_response] = e
+ end
+ puts("# exited #{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\n")
+ puts("OK\r\n")
+ else
+ @thr.delete(r)
+ if thr[:rubyserv_error]
+ puts("S exited\r\n")