lib/include/class_customio.rb in knjappserver-0.0.15 vs lib/include/class_customio.rb in knjappserver-0.0.16
- old
+ new
@@ -1,21 +1,35 @@
class Knjappserver::CustomIO < StringIO
def print(str)
thread = Thread.current
+ str = str.to_s
- if thread and thread[:knjappserver] and thread[:knjappserver][:stringio] and !thread[:knjappserver][:stringio].closed?
- return thread[:knjappserver][:stringio].print(str)
- elsif thread and thread[:knjappserver] and thread[:knjappserver][:httpsession] and thread[:knjappserver][:httpsession].out and !thread[:knjappserver][:httpsession].out.closed?
- return thread[:knjappserver][:httpsession].out.print(str)
+ if thread and thread[:knjappserver] and thread[:knjappserver][:contentgroup]
+ httpsession = thread[:knjappserver][:httpsession]
+
+ if httpsession
+ wsize = httpsession.written_size
+ wsize += str.size
+
+ if wsize >= httpsession.size_send
+ httpsession.cgroup.write_output
+ end
+ end
+
+ thread[:knjappserver][:contentgroup].write(str)
else
- return STDOUT.print(str) if !STDOUT.closed?
+ STDOUT.print(str) if !STDOUT.closed?
end
end
def <<(str)
self.print(str)
end
def write(str)
self.print(str)
+ end
+
+ def p(str)
+ self.print(str)
end
end
\ No newline at end of file