yahns.git  about / heads / tags
sleepy, multi-threaded, non-blocking application server for Ruby
blob 4828056fa5cc7795366f041c5a535b872d6aa7f0 978 bytes (raw)
$ git show v0.0.1:lib/yahns/wbuf.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
 
# -*- 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::Wbuf # :nodoc:
  include Yahns::WbufCommon

  def initialize(body, persist)
    @tmpio = Yahns::TmpIO.new
    @sf_offset = @sf_count = 0
    @wbuf_persist = persist # whether or not we keep the connection alive
    @body = body
  end

  def wbuf_write(client, buf)
    @sf_count += @tmpio.write(buf)
    case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count)
    when Integer
      @sf_count -= rv
      @sf_offset += rv
    when :wait_writable, :wait_readable
      return rv
    else
      raise "BUG: #{rv.nil ? "EOF" : rv.inspect} on tmpio " \
            "sf_offset=#@sf_offset sf_count=#@sf_count"
    end while @sf_count > 0
    nil
  end

  # called by last wbuf_flush
  def wbuf_close(client)
    @tmpio = @tmpio.close
    wbuf_close_common(client)
  end
end

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