bayserver-docker-terminal 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03b60838ef6d8e24f144d1b95af21ecfd7979442205196045780044c94a0fd3f
4
- data.tar.gz: 1e140bc00581b6b418083145b1f6618a58ac31e374620e69401869d81270573f
3
+ metadata.gz: 1d0422892db504256f119338d783f258d696e1cca90fa79a7549ea835f4b21d3
4
+ data.tar.gz: 6dfeb2da9c9eec3ad56fa74c2b4f109f6e03c0a941a2be89a37a39621ac90282
5
5
  SHA512:
6
- metadata.gz: e689e7a26ce083097cb2349772dfaad3bfad47df437b91abf2861ebf92e81dc0e81c4dcce14225aef37c61e8f85d2e1de41af2a207082bdc909df391814f451b
7
- data.tar.gz: a58d1246208e2e3ab947a7f41bdf0a7207c9732c5e25e3923b46e22369c70bf589979ca77856dbee40904fcaa0cb03b877d1f9289e9a79cfae869e446d870a30
6
+ metadata.gz: ea80ce79c1c69923f0b2d3c2c9bbd9a12d9240e91b14489d6072a4f50869ba531713c844a7c60dc79f9aae544f1973d539fe8c0685bb43a75613eb1a2dadaa07
7
+ data.tar.gz: 2d0df64d8804a2a3efdb393350d662574283c0ea521c5f3584310f4e4c4a5a6a6b4b1fa82eb8f30c0b08dec4b80afec2110e5665f2e2e694823d88b3e68859a1
@@ -1,9 +1,9 @@
1
1
  require 'baykit/bayserver/agent/next_socket_action'
2
- require 'baykit/bayserver/watercraft/yacht'
2
+ require 'baykit/bayserver/protocol/package'
3
3
  require 'baykit/bayserver/util/string_util'
4
4
  require 'baykit/bayserver/util/reusable'
5
5
 
6
- require 'baykit/bayserver/docker/terminal/hijackers_yacht'
6
+ require 'baykit/bayserver/docker/terminal/hijackers_ship'
7
7
 
8
8
  require 'baykit/bayserver/docker/http/h1/h1_command_handler'
9
9
 
@@ -11,7 +11,7 @@ module Baykit
11
11
  module BayServer
12
12
  module Docker
13
13
  module Terminal
14
- class FullyHijackersYacht < HijackersYacht
14
+ class FullyHijackersShip < HijackersShip
15
15
  include Baykit::BayServer::Docker::Http::H1::H1CommandHandler # implements
16
16
 
17
17
  include Baykit::BayServer::Util
@@ -35,7 +35,7 @@ module Baykit
35
35
  # Init method
36
36
  ######################################################
37
37
  #
38
- def init(tur, io, tp)
38
+ def init(tur, rd, tp)
39
39
  super
40
40
  @packet_store = PacketStore.new(tur.ship, H1PacketFactory.new)
41
41
  @command_unpacker = H1CommandUnPacker.new(self, false)
@@ -56,7 +56,7 @@ module Baykit
56
56
  ######################################################
57
57
 
58
58
  # Override
59
- def notify_read(buf, adr)
59
+ def notify_read(buf)
60
60
  @file_wrote_len += buf.length
61
61
 
62
62
  BayLog.debug "#{self} read hijack #{buf.length} bytes: total=#{@file_wrote_len}"
@@ -65,7 +65,6 @@ module Baykit
65
65
 
66
66
  end
67
67
 
68
-
69
68
  ######################################################
70
69
  # Implements H1CommandHandler
71
70
  ######################################################
@@ -76,16 +75,16 @@ module Baykit
76
75
  end
77
76
 
78
77
  if @state != STATE_READ_HEADER
79
- raise ProtocolException("Header command not expected: state=%d", @state)
78
+ raise ProtocolException.new("Header command not expected: state=%d", @state)
80
79
  end
81
80
 
82
- if BayServer.harbor.trace_header?
81
+ if BayServer.harbor.trace_header
83
82
  BayLog.info("%s hijack: resStatus: %d", self, cmd.status)
84
83
  end
85
84
 
86
85
  cmd.headers.each do |nv|
87
86
  @tour.res.headers.add(nv[0], nv[1])
88
- if BayServer.harbor.trace_header?
87
+ if BayServer.harbor.trace_header
89
88
  BayLog.info("%s hijack: resHeader: %s=%s", self, nv[0], nv[1]);
90
89
  end
91
90
  end
@@ -103,7 +102,7 @@ module Baykit
103
102
  sid = @tour.ship.id()
104
103
  @tour.res.set_consume_listener do |len, resume|
105
104
  if resume
106
- @tour.ship.resume(sid)
105
+ @tour.ship.resume_read(sid)
107
106
  end
108
107
  end
109
108
  end
@@ -116,7 +115,7 @@ module Baykit
116
115
  raise ProtocolException.new("Content command not expected")
117
116
  end
118
117
 
119
- available = @tour.res.send_content(@tour_id, cmd.buf, cmd.start, cmd.len)
118
+ available = @tour.res.send_res_content(@tour_id, cmd.buf, cmd.start, cmd.len)
120
119
  if @tour.res.bytes_posted == @tour.res.bytes_limit
121
120
  end_res_content(@tour)
122
121
  return NextSocketAction::CONTINUE
@@ -132,7 +131,7 @@ module Baykit
132
131
  raise Sink.new()
133
132
  end
134
133
 
135
- def finished()
134
+ def req_finished()
136
135
  return @state == STATE_FINISHED
137
136
  end
138
137
 
@@ -140,7 +139,7 @@ module Baykit
140
139
  private
141
140
 
142
141
  def end_res_content(tur)
143
- tur.res.end_content(Tour::TOUR_ID_NOCHECK)
142
+ tur.res.end_res_content(Tour::TOUR_ID_NOCHECK)
144
143
  reset()
145
144
  end
146
145
 
@@ -1,5 +1,4 @@
1
1
  require 'baykit/bayserver/agent/next_socket_action'
2
- require 'baykit/bayserver/watercraft/yacht'
3
2
  require 'baykit/bayserver/util/string_util'
4
3
  require 'baykit/bayserver/util/reusable'
5
4
 
@@ -9,7 +8,7 @@ module Baykit
9
8
  module BayServer
10
9
  module Docker
11
10
  module Terminal
12
- class HijackersYacht < Baykit::BayServer::WaterCraft::Yacht
11
+ class HijackersShip < Baykit::BayServer::Common::ReadOnlyShip
13
12
  include Baykit::BayServer::Docker::Http::H1::H1CommandHandler # implements
14
13
 
15
14
  include Baykit::BayServer::Util
@@ -21,7 +20,6 @@ module Baykit
21
20
  attr :tour_id
22
21
 
23
22
  attr :file_wrote_len
24
- attr :pipe_io
25
23
 
26
24
  attr :packet_store
27
25
  attr :packet_unpacker
@@ -39,20 +37,12 @@ module Baykit
39
37
  ######################################################
40
38
  # Init method
41
39
  ######################################################
40
+ def init(tur, rd, tp)
41
+ super(tur.ship.agent_id, rd, tp)
42
42
 
43
- def init(tur, io, tp)
44
- init_yacht()
45
43
  @tour = tur
46
- @tour_id = @tour.tour_id
47
-
48
- tur.res.set_consume_listener do |len, resume|
49
- if resume
50
- tp.open_valve();
51
- end
52
- end
53
- @pipe_io = io
44
+ @tour_id = tur.tour_id
54
45
  @file_wrote_len = 0
55
- @tour.ship.agent.non_blocking_handler.ask_to_read(@pipe_io)
56
46
  end
57
47
 
58
48
 
@@ -71,12 +61,12 @@ module Baykit
71
61
  # implements Yacht
72
62
  ######################################################
73
63
 
74
- def notify_read(buf, adr)
64
+ def notify_read(buf)
75
65
  @file_wrote_len += buf.length
76
66
 
77
67
  BayLog.debug "#{self} read hijack #{buf.length} bytes: total=#{@file_wrote_len}"
78
68
 
79
- available = @tour.res.send_content(@tour_id, buf, 0, buf.length)
69
+ available = @tour.res.send_res_content(@tour_id, buf, 0, buf.length)
80
70
  if !available
81
71
  return NextSocketAction::SUSPEND
82
72
  else
@@ -84,9 +74,23 @@ module Baykit
84
74
  end
85
75
  end
86
76
 
77
+ def notify_error(e)
78
+ BayLog.debug_e(e, "%s Hijack Error", self)
79
+ begin
80
+ @tour.res.send_error(@tour_id, HttpStatus::INTERNAL_SERVER_ERROR, nil, e)
81
+ rescue IOError => ex
82
+ BayLog.debug_e(ex)
83
+ end
84
+ end
85
+
87
86
  def notify_eof()
88
87
  BayLog.debug "#{self} Hijack EOF"
89
- @tour.res.end_content(@tour_id)
88
+ BayLog.debug("%s EOF", self)
89
+ begin
90
+ @tour.res.end_res_content(@tour_id)
91
+ rescue IOError => e
92
+ BayLog.debug_e(ex)
93
+ end
90
94
  return NextSocketAction::CLOSE
91
95
  end
92
96
 
@@ -1,8 +1,10 @@
1
- require 'baykit/bayserver/agent/transporter/plain_transporter'
1
+ require 'baykit/bayserver/agent/grand_agent'
2
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
3
+ require 'baykit/bayserver/rudders/io_rudder'
2
4
  require 'baykit/bayserver/docker/base/port_base'
3
5
  require 'baykit/bayserver/tours/content_consume_listener'
4
6
 
5
- require 'baykit/bayserver/docker/terminal/fully_hijackers_yacht'
7
+ require 'baykit/bayserver/docker/terminal/fully_hijackers_ship'
6
8
  require 'baykit/bayserver/docker/terminal/terminal_train'
7
9
 
8
10
  module Baykit
@@ -12,7 +14,9 @@ module Baykit
12
14
  class TerminalDocker < Baykit::BayServer::Docker::Base::ClubBase
13
15
  include Baykit::BayServer::Bcf
14
16
  include Baykit::BayServer::Util
15
- include Baykit::BayServer::Agent::Transporter
17
+ include Baykit::BayServer::Agent
18
+ include Baykit::BayServer::Agent::Multiplexer
19
+ include Baykit::BayServer::Rudders
16
20
  include Baykit::BayServer::Tours
17
21
 
18
22
  RACK_TERMINAL_PIPE = "rack.terminal.pipe"
@@ -104,8 +108,8 @@ module Baykit
104
108
  tur.res.headers.set_content_type("text/plain")
105
109
  tur.res.set_consume_listener(&ContentConsumeListener::DEV_NULL)
106
110
  tur.res.send_headers(tur.id)
107
- tur.res.send_content(tur.id, RACK_ERR, 0, RACK_ERR.length)
108
- tur.res.end_content(tur.id)
111
+ tur.res.send_res_content(tur.id, RACK_ERR, 0, RACK_ERR.length)
112
+ tur.res.end_res_content(tur.id)
109
113
  return
110
114
  end
111
115
 
@@ -168,7 +172,7 @@ module Baykit
168
172
  env[Rack::RACK_ERRORS] = STDERR
169
173
  env[Rack::RACK_INPUT] = nil
170
174
  env[RACK_MULTITHREAD] = true
171
- env[RACK_MULTIPROCESS] = BayServer.harbor.multi_core?
175
+ env[RACK_MULTIPROCESS] = BayServer.harbor.multi_core
172
176
  env[RACK_RUNONCE] = false
173
177
  env[Rack::RACK_URL_SCHEME] = tur.is_secure ? "https" : "http"
174
178
  env[Rack::RACK_IS_HIJACK] = true
@@ -181,13 +185,25 @@ module Baykit
181
185
 
182
186
  env[RACK_HIJACK_IO] = w_pipe
183
187
 
184
- yat = FullyHijackersYacht.new()
188
+ agt = GrandAgent.get(tur.ship.agent_id)
189
+ mpx = agt.net_multiplexer
190
+ rd_read = IORudder.new(pip[0])
191
+ sip = FullyHijackersShip.new()
185
192
  bufsize = tur.ship.protocol_handler.max_res_packet_data_size()
186
- tp = PlainTransporter.new(false, bufsize)
187
193
 
188
- yat.init(tur, pip[0], tp)
189
- tp.init(tur.ship.agent.non_blocking_handler, pip[0], yat)
190
- tur.ship.resume(tur.ship_id)
194
+ tp = PlainTransporter.new(mpx, sip, false, bufsize, false)
195
+
196
+ sip.init(tur, rd_read, tp)
197
+ sid = sip.ship_id
198
+
199
+ tur.res.set_consume_listener do |len, resume|
200
+ if resume
201
+ sip.resume_read(sid)
202
+ end
203
+ end
204
+
205
+ mpx.add_rudder_state(rd_read, RudderState.new(rd_read, tp))
206
+ mpx.req_read(rd_read)
191
207
 
192
208
  w_pipe
193
209
  end
@@ -1,4 +1,7 @@
1
- require 'baykit/bayserver/agent/transporter/plain_transporter'
1
+ require 'baykit/bayserver/agent/grand_agent'
2
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
3
+ require 'baykit/bayserver/common/read_only_ship'
4
+ require 'baykit/bayserver/rudders/io_rudder'
2
5
  require 'baykit/bayserver/train/train'
3
6
  require 'baykit/bayserver/train/train_runner'
4
7
  require 'baykit/bayserver/tours/tour'
@@ -7,7 +10,7 @@ require 'baykit/bayserver/tours/req_content_handler'
7
10
  require 'baykit/bayserver/util/string_util'
8
11
  require 'baykit/bayserver/util/http_status'
9
12
 
10
- require 'baykit/bayserver/docker/terminal/hijackers_yacht'
13
+ require 'baykit/bayserver/docker/terminal/hijackers_ship'
11
14
 
12
15
  module Baykit
13
16
  module BayServer
@@ -16,7 +19,9 @@ module Baykit
16
19
  class TerminalTrain < Baykit::BayServer::Train::Train
17
20
  include Baykit::BayServer::Tours::ReqContentHandler # implements
18
21
 
19
- include Baykit::BayServer::Agent::Transporter
22
+ include Baykit::BayServer::Agent
23
+ include Baykit::BayServer::Agent::Multiplexer
24
+ include Baykit::BayServer::Rudders
20
25
  include Baykit::BayServer::Util
21
26
  include Baykit::BayServer::Train
22
27
  include Baykit::BayServer::Tours
@@ -75,7 +80,7 @@ module Baykit
75
80
  end
76
81
 
77
82
 
78
- if BayServer.harbor.trace_header?
83
+ if BayServer.harbor.trace_header
79
84
  @env.keys.each do |key|
80
85
  value = @env[key]
81
86
  BayLog.info("%s Terminal: env:%s=%s", @tour, key, value)
@@ -109,15 +114,25 @@ module Baykit
109
114
  if hijack != nil
110
115
  # Partially hijacked
111
116
  BayLog.debug("%s Tour is partially hijacked", @tour)
112
-
117
+ agt = GrandAgent.get(@tour.ship.agent_id)
118
+ mpx = agt.net_multiplexer
113
119
  pip = IO.pipe
114
- yat = HijackersYacht.new()
120
+ rd_read = IORudder.new(pip[0])
121
+ sip = HijackersShip.new()
115
122
  bufsize = @tour.ship.protocol_handler.max_res_packet_data_size()
116
- tp = PlainTransporter.new(false, bufsize)
123
+ tp = PlainTransporter.new(mpx, sip, false, bufsize, false)
124
+
125
+ sip.init(@tour, rd_read, tp)
126
+ sid = sip.ship_id
117
127
 
118
- yat.init(@tour, pip[0], tp)
119
- tp.init(@tour.ship.agent.non_blocking_handler, pip[0], yat)
120
- @tour.ship.resume(@tour.ship_id)
128
+ @tour.res.set_consume_listener do |len, resume|
129
+ if resume
130
+ sip.resume_read(sid)
131
+ end
132
+ end
133
+
134
+ mpx.add_rudder_state(rd_read, RudderState.new(rd_read, tp))
135
+ mpx.req_read(rd_read)
121
136
 
122
137
  hijack.call pip[1]
123
138
 
@@ -135,13 +150,13 @@ module Baykit
135
150
  body.each do | str |
136
151
  bstr = StringUtil.to_bytes(str)
137
152
  BayLog.trace("%s TerminalTask: read body: len=%d", @tour, bstr.length)
138
- @available = @tour.res.send_content(@tour_id, bstr, 0, bstr.length)
153
+ @available = @tour.res.send_res_content(@tour_id, bstr, 0, bstr.length)
139
154
  while !@available
140
155
  sleep 0.1
141
156
  end
142
157
  end
143
158
 
144
- @tour.res.end_content(@tour_id)
159
+ @tour.res.end_res_content(@tour_id)
145
160
 
146
161
  end
147
162
  end
@@ -157,7 +172,7 @@ module Baykit
157
172
  end
158
173
  end
159
174
 
160
- def on_read_content(tur, buf, start, len)
175
+ def on_read_req_content(tur, buf, start, len, &lis)
161
176
  BayLog.trace("%s TerminalTask:onReadContent: len=%d", @tour, len)
162
177
 
163
178
  if @req_cont != nil
@@ -168,11 +183,11 @@ module Baykit
168
183
  @tmpfile.write(buf[start, len])
169
184
  end
170
185
 
171
- tur.req.consumed(Tour::TOUR_ID_NOCHECK, len)
186
+ tur.req.consumed(Tour::TOUR_ID_NOCHECK, len, &lis)
172
187
  true
173
188
  end
174
189
 
175
- def on_end_content(tur)
190
+ def on_end_req_content(tur)
176
191
  BayLog.trace("%s TerminalTask:endContent", @tour)
177
192
 
178
193
  if @req_cont != nil
@@ -185,12 +200,12 @@ module Baykit
185
200
  end
186
201
  env[Rack::RACK_INPUT] = rack_input
187
202
 
188
- if !TrainRunner.post(self)
203
+ if !TrainRunner.post(tur.ship.agent_id, self)
189
204
  raise HttpException.new(HttpStatus::SERVICE_UNAVAILABLE, "TrainRunner is busy")
190
205
  end
191
206
  end
192
207
 
193
- def on_abort(tur)
208
+ def on_abort_req(tur)
194
209
  BayLog.trace("%s TerminalTask:abort", @tour)
195
210
  if @tmpfile
196
211
  @tmpfile.close()
@@ -199,6 +214,10 @@ module Baykit
199
214
  return false
200
215
  end
201
216
 
217
+ def on_timer
218
+ BayLog.debug("%s TerminalTask:timer", @tour)
219
+ end
220
+
202
221
  def inspect
203
222
  "TerminalTask #{@tour}"
204
223
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bayserver-docker-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michisuke-P
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-23 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bayserver-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.2
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.2
26
+ version: 3.0.0
27
27
  description: BayServer is one of the high-speed web servers. It operates as a single-threaded,
28
28
  asynchronous server, which makes it exceptionally fast. It also supports multi-core
29
29
  processors, harnessing the full potential of the CPU's capabilities.
@@ -34,9 +34,8 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - LICENSE.BAYKIT
36
36
  - README.md
37
- - lib/baykit/bayserver/docker/terminal/fully_hijackers_yacht.rb
38
- - lib/baykit/bayserver/docker/terminal/hijacked_data_sender.rb
39
- - lib/baykit/bayserver/docker/terminal/hijackers_yacht.rb
37
+ - lib/baykit/bayserver/docker/terminal/fully_hijackers_ship.rb
38
+ - lib/baykit/bayserver/docker/terminal/hijackers_ship.rb
40
39
  - lib/baykit/bayserver/docker/terminal/terminal_docker.rb
41
40
  - lib/baykit/bayserver/docker/terminal/terminal_train.rb
42
41
  - lib/rack/handler/bayserver.rb
@@ -1,170 +0,0 @@
1
- require 'baykit/bayserver/agent/next_socket_action'
2
- require 'baykit/bayserver/protocol/packet_store'
3
- require 'baykit/bayserver/docker/http/h1/h1_packet_unpacker'
4
- require 'baykit/bayserver/docker/http/h1/h1_command_unpacker'
5
- require 'baykit/bayserver/util/string_util'
6
- require 'baykit/bayserver/util/http_status'
7
-
8
-
9
- module Baykit
10
- module BayServer
11
- module Docker
12
- module Terminal
13
- #
14
- # Send data of hijacked response
15
- #
16
- class HijackedDataSender
17
- include Baykit::BayServer::Agent::NonBlockingHandler::ChannelListener # implements
18
- include Baykit::BayServer::Util
19
- include Baykit::BayServer::Agent
20
- include Baykit::BayServer::Protocol
21
- include Baykit::BayServer::Docker::Http::H1
22
-
23
- attr :tour
24
- attr :tour_id
25
- attr :fully
26
-
27
- attr :file_wrote_len
28
- attr :file_buf_list
29
- attr :cur_file_idx
30
- attr :read_buf_size
31
- attr :cur_file_idx
32
- attr :pipe_io
33
-
34
- attr :packet_store
35
- attr :packet_unpacker
36
- attr :command_unpacker
37
-
38
- DEFAULT_FREAD_BUF_SIZE = 8192
39
-
40
- def initialize(tur, fully)
41
- @tour = tur
42
- @tour_id = @tour.tour_id
43
- @fully = fully
44
- @file_buf_list = []
45
- @read_buf_size = tour.ship.protocol_handler.max_res_packet_data_size
46
-
47
- if @fully
48
- @packet_store = PacketStore.new(tur.ship, H1PacketFactory.new)
49
- @command_unpacker = H1CommandUnPacker.new(self, false)
50
- @packet_unpacker = H1PacketUnPacker.new(@command_unpacker, @packet_store)
51
- end
52
- reset
53
- end
54
-
55
- def reset
56
- @file_wrote_len = 0
57
- @cur_file_idx = -1
58
- end
59
-
60
- def ship
61
- @tour.ship
62
- end
63
-
64
- def on_readable(chk_fd)
65
- BayLog.debug "#{self} Hijack Readable"
66
- check_socket(chk_fd)
67
-
68
- buf = new_file_buffer
69
- begin
70
- @pipe_io.read_nonblock(@read_buf_size, buf)
71
- rescue EOFError => e
72
- BayLog.debug "#{self} Hijack EOF"
73
- @tour.res.end_content(@tour_id)
74
- return NextSocketAction::CLOSE
75
- end
76
-
77
- @file_wrote_len += buf.length
78
-
79
- BayLog.debug "#{self} read hijack #{buf.length} bytes: total=#{@file_wrote_len}"
80
-
81
- if @fully
82
- return @packet_unpacker.bytes_received(buf)
83
- else
84
- available = @tour.res.send_content(@tour_id, buf, 0, buf.length)
85
- if !available
86
- NextSocketAction::SUSPEND
87
- else
88
- NextSocketAction::CONTINUE
89
- end
90
- end
91
-
92
- end
93
-
94
- def check_timeout(chk_fd, duration)
95
- BayLog.debug "#{self} Hijack timeout(Ignore)"
96
- end
97
-
98
- def on_error(chk_fd, e)
99
- BayLog.debug "#{self} Hijack Error"
100
- check_socket(chk_fd)
101
-
102
- BayLog.error_e e
103
- end
104
-
105
- def on_closed(chk_fd)
106
- BayLog.debug "#{self} Hijack Closed(Ignore)"
107
- check_socket(chk_fd)
108
- end
109
-
110
-
111
- def send_pipe_data(io)
112
- BayLog.debug("#{self} Send hijacked data #{io.inspect}")
113
- @pipe_io = io
114
- @file_wrote_len = 0
115
- @tour.ship.agent.non_blocking_handler.ask_to_read(@pipe_io)
116
- end
117
-
118
- # Implements H1CommandHandler
119
- # Fully hijacked mode
120
- def handle_header(cmd)
121
- cmd.headers.each do |nv|
122
- @tour.res.headers.add(nv[0], nv[1])
123
- end
124
-
125
- @tour.res.headers.status = cmd.status != nil ? cmd.status : HttpStatus::OK
126
- @tour.send_headers(@tour_id)
127
-
128
- return NextSocketAction::CONTINUE
129
- end
130
-
131
- # Implements H1CommandHandler
132
- # Fully hijacked mode
133
- def handle_content(cmd)
134
- available = @tour.res.send_content(@tour_id, cmd.buf, cmd.start, cmd.len)
135
- if !available
136
- NextSocketAction::SUSPEND
137
- else
138
- NextSocketAction::CONTINUE
139
- end
140
- end
141
-
142
- def resume
143
- BayLog.debug("#{self} resume")
144
- @tour.ship.agent.non_blocking_handler.ask_to_read(@pipe_io)
145
- end
146
-
147
- def to_s
148
- "hijack[#{@pipe_io.inspect}]"
149
- end
150
-
151
- private
152
- def check_socket(chk_fd)
153
- if chk_fd != @pipe_io
154
- raise RuntimeError.new("BUG: Invalid hijacked data sender instance (file was returned?): #{chk_fd}")
155
- end
156
- end
157
-
158
- def new_file_buffer
159
- @cur_file_idx += 1
160
- if @file_buf_list.length == @cur_file_idx
161
- @file_buf_list << StringUtil.alloc(@read_buf_size)
162
- end
163
- @file_buf_list[@cur_file_idx]
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
170
-