yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
5f25b2e83a7e2ad05ca52519ff4f13d1fbd163e7 blob 1289 bytes (raw)

 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
debug log:

solving 5f25b2e ...
found 5f25b2e in https://yhbt.net/yahns.git

Code repositories for project(s) associated with this inbox:

	../../../yahns.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).