Class: Falcon::Adapters::Hijack

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/adapters/hijack.rb

Overview

This is used for implementing partial hijack.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ Hijack

Returns a new instance of Hijack.



45
46
47
48
# File 'lib/falcon/adapters/hijack.rb', line 45

def initialize(input, output)
	@input = input
	@output = output
end

Class Method Details

.for(env, block, socket = nil, task: Async::Task.current) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/falcon/adapters/hijack.rb', line 28

def self.for(env, block, socket = nil, task: Async::Task.current)
	input = socket || env[Rack::RACK_INPUT]
	output = Async::HTTP::Body::Writable.new
	
	stream = Hijack.new(input, output)
	
	task.async do
		begin
			block.call(stream)
		ensure
			output.close
		end
	end
	
	return output
end

Instance Method Details

#closeObject



67
68
69
# File 'lib/falcon/adapters/hijack.rb', line 67

def close
	@output.close
end

#close_readObject



71
72
73
74
75
76
77
# File 'lib/falcon/adapters/hijack.rb', line 71

def close_read
	if @input.respond_to?(:close_read)
		@input.close_read
	else
		@input.close
	end
end

#close_writeObject



79
80
81
# File 'lib/falcon/adapters/hijack.rb', line 79

def close_write
	@output.close
end

#flushObject



64
65
# File 'lib/falcon/adapters/hijack.rb', line 64

def flush
end

#read(length = nil, buffer = nil) ⇒ Object



50
51
52
# File 'lib/falcon/adapters/hijack.rb', line 50

def read(length = nil, buffer = nil)
	@input.read(length, buffer)
end

#read_nonblock(length, buffer = nil) ⇒ Object



54
55
56
# File 'lib/falcon/adapters/hijack.rb', line 54

def read_nonblock(length, buffer = nil)
	@input.read(length, buffer)
end

#write(buffer) ⇒ Object Also known as: write_nonblock



58
59
60
# File 'lib/falcon/adapters/hijack.rb', line 58

def write(buffer)
	@output.write(buffer)
end