yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob a997a76e7b87e3e773d7d604c6bb31440b184d1b 1061 bytes (raw)
$ git show opt-case:lib/yahns/wbuf_str.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
# -*- encoding: binary -*-
# Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require_relative 'wbuf_common'

# we only use this for buffering the tiniest responses (which are already
# strings in memory and a handful of bytes).
#
#   "HTTP", "/1.1 "
#   "HTTP/1.1 100 Continue\r\n\r\n"
#   "100 Continue\r\n\r\nHTTP/1.1 "
#
# This is very, very rarely triggered.
# 1) check_client_connection is enabled
# 2) the client sent an "Expect: 100-continue" header
#
# Most output buffering goes through
# the normal Yahns::Wbuf class which uses a temporary file as a buffer
# (suitable for sendfile())
class Yahns::WbufStr # :nodoc:
  include Yahns::WbufCommon

  def initialize(str, next_state)
    @str = str
    @next = next_state # :ccc_done, :r100_done
  end

  def wbuf_flush(client)
    case rv = client.kgio_trywrite(@str)
    when :wait_writable, :wait_readable
      return rv
    when nil
      return @next
    else # String
      @str = rv
    end while true
  end
end

git clone git://yhbt.net/yahns.git
git clone https://yhbt.net/yahns.git