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
39
40
41
42
43
44
45
46
47
48
49
50
| | # -*- encoding: binary -*-
# Copyright (C) 2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require_relative 'wbuf_common'
# This is only used for "proxy_buffering: false"
class Yahns::WbufLite # :nodoc:
include Yahns::WbufCommon
attr_reader :busy
def initialize(req_res)
@req_res = req_res
@busy = false
@buf = nil
end
# called only by proxy_write in proxy_http_response
def wbuf_write(client, buf)
buf = buf.join if Array === buf
buf = @buf << buf if @buf # unlikely
do_write(client, buf) # try our best to avoid string copying/appending
end
def do_write(client, buf)
case rv = client.kgio_trywrite(buf)
when String
buf = rv # continue looping
when :wait_writable, :wait_readable
@buf = buf
return @busy = rv
when nil
@buf = nil
return @busy = false
end while true
end
# called by Yahns::HttpClient#step_write
def wbuf_flush(client)
sym = do_write(client, @buf) and return sym # :wait_writable/:wait_readable
# resume reading
client.hijack_cleanup
Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD)
:ignore
rescue
@req_res.close
raise
end
end
|