about summary refs log tree commit homepage
path: root/lib/yahns/wbuf_str.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-26 01:13:29 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-26 02:00:17 +0000
commitf38e54f8d54f8cdfdc15f43b2394f0acfff5d413 (patch)
tree5a26e626a3fcee6787f62d1dd885137604db97c5 /lib/yahns/wbuf_str.rb
parent8671b632849216476305573e87b5626bc34fedf1 (diff)
downloadyahns-f38e54f8d54f8cdfdc15f43b2394f0acfff5d413.tar.gz
The tiny responses for check_client_connection and "100-Continue"
responses may occasionally fail with EAGAIN.  We must be prepared
for those corner cases and buffer the output appropriately.  We can
safely use a string for buffering here (for once(!)), since the
buffer sizes are bounded and known at buffer time, unlike the
response headers/bodies sent by the Rack application.
Diffstat (limited to 'lib/yahns/wbuf_str.rb')
-rw-r--r--lib/yahns/wbuf_str.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/yahns/wbuf_str.rb b/lib/yahns/wbuf_str.rb
new file mode 100644
index 0000000..414f3d5
--- /dev/null
+++ b/lib/yahns/wbuf_str.rb
@@ -0,0 +1,24 @@
+# -*- encoding: binary -*-
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> et. al.
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative 'wbuf_common'
+
+class Yahns::WbufStr # :nodoc:
+  include Yahns::WbufCommon
+
+  def initialize(str, next_state)
+    @str = str
+    @next = next_state # :check_client_connection, :http_100_response
+  end
+
+  def wbuf_flush(client)
+    case rv = client.kgio_trywrite(@str)
+    when String
+      @str = rv
+    when :wait_writable, :wait_readable
+      return rv
+    when nil
+      return @next
+    end while true
+  end
+end