bayserver-docker-cgi 2.3.1 → 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: fda7c0ee6d619c8923d135d4c7030cbba18c36ec391902d824ca13ddecb49c64
4
- data.tar.gz: 7452ae253e80294c4630d23fccfceb9aaae53b65cc1f7ca70f49b8e70b39194f
3
+ metadata.gz: '089b472c6337c1d1fd5ad7ceb32aef640d25e5f10f24b6bc664a8ce07f6dc712'
4
+ data.tar.gz: cafcd01d757b59b35ddfd524de0d99410b5ce99e8279f0be0867824137df2b02
5
5
  SHA512:
6
- metadata.gz: 7da38c14259fc887d0640d39bef18a8e21fbf4b712866462c0c7704cb14e561d59053a88519f791739b3e01ef489c919b806b8dae7afb839b8f938a671bd9f74
7
- data.tar.gz: b17d43db6d1dc1d02bd7c82d5c09f7ec65604c4aa4a974e71418efc9d2582f0e0cfa26e64eee30820900e9fa20924bcaf0ccb2d2dc575eec29c357b86d50ce8b
6
+ metadata.gz: 4377dd1a66ebb4336e0f0cf935a88862d1bc6b580344e7e5727808e0edf963862b8533e5fb1ffea56ab84b39094d716968ae140fdee3ec58c6a27d8f6eee5c26
7
+ data.tar.gz: e8e6a74006b99e8db55f924280d92670e4205994cd29b79a3f4184ed3082ec4a2ecd50535b94228b75e6aa9addb23301ca9c38c65f2b1b9ac17e1c75bbc2fafb
@@ -1,13 +1,13 @@
1
1
  require 'baykit/bayserver/bcf/package'
2
- require 'baykit/bayserver/agent/transporter/plain_transporter'
2
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
3
3
  require 'baykit/bayserver/agent/transporter/spin_read_transporter'
4
4
  require 'baykit/bayserver/tours/tour'
5
5
  require 'baykit/bayserver/tours/read_file_taxi'
6
6
  require 'baykit/bayserver/docker/base/club_base'
7
7
  require 'baykit/bayserver/docker/harbor'
8
8
  require 'baykit/bayserver/docker/cgi/cgi_req_content_handler'
9
- require 'baykit/bayserver/docker/cgi/cgi_std_out_yacht'
10
- require 'baykit/bayserver/docker/cgi/cgi_std_err_yacht'
9
+ require 'baykit/bayserver/docker/cgi/cgi_std_out_ship'
10
+ require 'baykit/bayserver/docker/cgi/cgi_std_err_ship'
11
11
  require 'baykit/bayserver/docker/cgi/cgi_message'
12
12
  require 'baykit/bayserver/taxi/taxi_runner'
13
13
  require 'baykit/bayserver/util/http_status'
@@ -22,30 +22,33 @@ module Baykit
22
22
  include Baykit::BayServer::Bcf
23
23
  include Baykit::BayServer::Util
24
24
  include Baykit::BayServer::Agent
25
- include Baykit::BayServer::Agent::Transporter
25
+ include Baykit::BayServer::Agent::Multiplexer
26
26
  include Baykit::BayServer::Docker
27
27
  include Baykit::BayServer::Docker::Cgi
28
28
  include Baykit::BayServer::Tours
29
29
  include Baykit::BayServer::Taxi
30
+ include Baykit::BayServer::Rudders
30
31
 
31
- DEFAULT_PROC_READ_METHOD = Harbor::FILE_SEND_METHOD_TAXI
32
32
  DEFAULT_TIMEOUT_SEC = 0
33
33
 
34
34
  attr :interpreter
35
35
  attr :script_base
36
36
  attr :doc_root
37
37
  attr :timeout_sec
38
+ attr :max_processes
39
+ attr :process_count
40
+ attr :wait_count
38
41
 
39
- # Method to read stdin/stderr
40
- attr :proc_read_method
41
42
 
42
43
  def initialize()
43
44
  super
44
45
  @interpreter = nil
45
46
  @script_base = nil
46
47
  @doc_root = nil
47
- @proc_read_method = CgiDocker::DEFAULT_PROC_READ_METHOD
48
48
  @timeout_sec = CgiDocker::DEFAULT_TIMEOUT_SEC
49
+ @max_processes = -1
50
+ @process_count = 0
51
+ @wait_count = 0
49
52
  end
50
53
 
51
54
  ######################################################
@@ -54,16 +57,6 @@ module Baykit
54
57
 
55
58
  def init(elm, parent)
56
59
  super
57
-
58
- if @proc_read_method == Harbor::FILE_SEND_METHOD_SELECT and !SysUtil.support_select_pipe()
59
- BayLog.warn(BayMessage.get(:CGI_PROC_READ_METHOD_SELECT_NOT_SUPPORTED))
60
- @proc_read_method = Harbor::FILE_SEND_METHOD_TAXI
61
- end
62
-
63
- if @proc_read_method == Harbor::FILE_SEND_METHOD_SPIN and !SysUtil.support_nonblock_pipe_read()
64
- BayLog.warn(BayMessage.get(:CGI_PROC_READ_METHOD_SPIN_NOT_SUPPORTED))
65
- @proc_read_method = Harbor::FILE_SEND_METHOD_TAXI
66
- end
67
60
  end
68
61
 
69
62
 
@@ -82,25 +75,12 @@ module Baykit
82
75
  when "docroot"
83
76
  @doc_root = kv.value
84
77
 
85
- when "processreadmethod"
86
- case kv.value.downcase()
87
-
88
- when "select"
89
- @proc_read_method = Harbor::FILE_SEND_METHOD_SELECT
90
-
91
- when "spin"
92
- @proc_read_method = Harbor::FILE_SEND_METHOD_SPIN
93
-
94
- when "taxi"
95
- @proc_read_method = Harbor::FILE_SEND_METHOD_TAXI
96
-
97
- else
98
- raise ConfigException.new(kv.file_name, kv.line_no, BayMessage.get(:CFG_INVALID_PARAMETER_VALUE, kv.value))
99
- end
100
-
101
78
  when "timeout"
102
79
  @timeout_sec = kv.value.to_i
103
80
 
81
+ when "maxprocesses"
82
+ @max_processes = kv.value.to_i
83
+
104
84
  else
105
85
  return super
106
86
  end
@@ -137,7 +117,7 @@ module Baykit
137
117
  end
138
118
 
139
119
  env = CgiUtil.get_env_hash(tur.town.name, root, base, tur)
140
- if BayServer.harbor.trace_header?
120
+ if BayServer.harbor.trace_header
141
121
  env.keys.each do |name|
142
122
  value = env[name]
143
123
  BayLog.info("%s cgi: env: %s=%s", tur, name, value)
@@ -149,67 +129,9 @@ module Baykit
149
129
  raise HttpException.new(HttpStatus::NOT_FOUND, file_name)
150
130
  end
151
131
 
152
- bufsize = 8192;
153
- handler = CgiReqContentHandler.new(self, tur)
132
+ handler = CgiReqContentHandler.new(self, tur, env)
154
133
  tur.req.set_content_handler(handler)
155
- handler.start_tour(env)
156
- fname = "cgi#"
157
-
158
- out_yat = CgiStdOutYacht.new()
159
- err_yat = CgiStdErrYacht.new()
160
-
161
- case(@proc_read_method)
162
- when Harbor::FILE_SEND_METHOD_SELECT
163
- out_tp = PlainTransporter.new(false, bufsize)
164
- out_yat.init(tur, out_tp, handler)
165
- out_tp.init(tur.ship.agent.non_blocking_handler, handler.std_out[0], out_yat)
166
- out_tp.open_valve()
167
-
168
- err_tp = PlainTransporter.new(false, bufsize)
169
- err_yat.init(tur, handler)
170
- err_tp.init(tur.ship.agent.non_blocking_handler, handler.std_err[0], err_yat)
171
- err_tp.open_valve()
172
-
173
- when Harbor::FILE_SEND_METHOD_SPIN
174
-
175
- def eof_checker()
176
- begin
177
- pid = Process.wait(handler.pid, Process::WNOHANG)
178
- return pid != nil
179
- rescue Errno::ECHILD => e
180
- BayLog.error_e(e)
181
- return true
182
- end
183
- end
184
-
185
- out_tp = SpinReadTransporter.new(bufsize)
186
- out_yat.init(tur, out_tp, handler)
187
- out_tp.init(tur.ship.agent.spin_handler, out_yat, handler.std_out[0], -1, @timeout_sec, eof_checker)
188
- out_tp.open_valve()
189
-
190
- err_tp = SpinReadTransporter.new(bufsize)
191
- err_yat.init(tur, handler)
192
- err_tp.init(tur.ship.agent.spin_handler, err_yat, handler.std_out[0], -1, @timeout_sec, eof_checker)
193
- err_tp.open_valve()
194
-
195
- when Harbor::FILE_SEND_METHOD_TAXI
196
- out_txi = ReadFileTaxi.new(tur.ship.agent.agent_id, bufsize)
197
- out_yat.init(tur, out_txi, handler)
198
- out_txi.init(handler.std_out[0], out_yat)
199
- if !TaxiRunner.post(tur.ship.agent.agent_id, out_txi)
200
- raise HttpException.new(HttpStatus.SERVICE_UNAVAILABLE, "Taxi is busy!")
201
- end
202
-
203
- err_txi = ReadFileTaxi.new(tur.ship.agent.agent_id, bufsize)
204
- err_yat.init(tur, @timeout_sec)
205
- err_txi.init(handler.std_err[0], err_yat)
206
- if !TaxiRunner.post(tur.ship.agent.agent_id, err_txi)
207
- raise HttpException.new(HttpStatus.SERVICE_UNAVAILABLE, "Taxi is busy!")
208
- end
209
-
210
- else
211
- raise Sink.new();
212
- end
134
+ handler.req_start_tour()
213
135
  end
214
136
 
215
137
  def create_command(env)
@@ -221,6 +143,33 @@ module Baykit
221
143
  end
222
144
  command
223
145
  end
146
+
147
+ ######################################################
148
+ # Other methods
149
+ ######################################################
150
+
151
+ def get_wait_count
152
+ @wait_count
153
+ end
154
+
155
+ def add_process_count
156
+ if @max_processes <= 0 || @process_count < @max_processes
157
+ @process_count += 1
158
+ BayLog.debug("%s Process count: %d", self, @process_count)
159
+ return true
160
+ end
161
+
162
+ @wait_count += 1
163
+ return false
164
+ end
165
+
166
+ def sub_process_count
167
+ return @process_count -= 1
168
+ end
169
+
170
+ def sub_wait_count
171
+ return @wait_count -= 1
172
+ end
224
173
  end
225
174
  end
226
175
  end
@@ -1,6 +1,10 @@
1
+ require 'baykit/bayserver/agent/grand_agent'
2
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
3
+ require 'baykit/bayserver/common/postpone'
1
4
  require 'baykit/bayserver/train/train'
2
5
  require 'baykit/bayserver/tours/req_content_handler'
3
6
 
7
+ require 'baykit/bayserver/rudders/io_rudder'
4
8
  require 'baykit/bayserver/util/string_util'
5
9
  require 'baykit/bayserver/util/http_status'
6
10
 
@@ -10,10 +14,13 @@ module Baykit
10
14
  module Cgi
11
15
  class CgiReqContentHandler
12
16
  include Baykit::BayServer::Tours::ReqContentHandler # implements
17
+ include Baykit::BayServer::Common::Postpone # implements
13
18
 
14
19
  include Baykit::BayServer::Agent
20
+ include Baykit::BayServer::Agent::Multiplexer
15
21
  include Baykit::BayServer::Train
16
22
  include Baykit::BayServer::Tours
23
+ include Baykit::BayServer::Rudders
17
24
  include Baykit::BayServer::Util
18
25
 
19
26
  READ_CHUNK_SIZE = 8192
@@ -23,50 +30,67 @@ module Baykit
23
30
  attr :tour_id
24
31
  attr :available
25
32
  attr :pid
26
- attr :std_in
27
- attr :std_out
28
- attr :std_err
33
+ attr :std_in_rd
34
+ attr :std_out_rd
35
+ attr :std_err_rd
29
36
  attr :std_out_closed
30
37
  attr :std_err_closed
31
38
  attr :last_access
39
+ attr_accessor :multiplexer
40
+ attr :env
32
41
 
33
- def initialize(cgi_docker, tur)
42
+ def initialize(cgi_docker, tur, env)
34
43
  @cgi_docker = cgi_docker
35
44
  @tour = tur
36
45
  @tour_id = tur.tour_id
46
+ @env = env
37
47
  @std_out_closed = true
38
48
  @std_err_closed = true
39
49
  end
40
50
 
51
+ ######################################################
52
+ # Implements Postpone
53
+ ######################################################
54
+ def run
55
+ @cgi_docker.sub_wait_count
56
+ BayLog.info("%s challenge postponed tour", @tour, @cgi_docker.get_wait_count)
57
+ req_start_tour
58
+ end
59
+
41
60
  ######################################################
42
61
  # Implements ReqContentHandler
43
62
  ######################################################
44
63
 
45
- def on_read_content(tur, buf, start, len)
64
+ def on_read_req_content(tur, buf, start, len, &callback)
46
65
  BayLog.debug("%s CGI:onReadReqContent: len=%d", tur, len)
47
66
 
48
- wrote_len = @std_in[1].write(buf[start, len])
67
+ wrote_len = @std_in_rd.write(buf[start, len])
49
68
  BayLog.debug("%s CGI:onReadReqContent: wrote=%d", tur, wrote_len)
50
- tur.req.consumed(Tour::TOUR_ID_NOCHECK, len)
69
+ tur.req.consumed(Tour::TOUR_ID_NOCHECK, len, &callback)
51
70
  access()
52
71
  end
53
72
 
54
- def on_end_content(tur)
73
+ def on_end_req_content(tur)
55
74
  BayLog.trace("%s CGI:endReqContent", tur)
56
75
  access()
57
76
  end
58
77
 
59
- def on_abort(tur)
78
+ def on_abort_req(tur)
60
79
  BayLog.debug("%s CGI:abortReq", tur)
80
+
61
81
  if !@std_out_closed
62
- @tour.ship.agent.non_blocking_handler.ask_to_close(@std_out[0])
82
+ @multiplexer.req_close(@std_out_rd)
63
83
  end
64
84
  if !@std_err_closed
65
- @tour.ship.agent.non_blocking_handler.ask_to_close(@std_err[0])
85
+ @multiplexer.req_close(@std_err_rd)
66
86
  end
67
87
 
68
- BayLog.debug("%s KILL PROCESS!: %d", tur, @pid)
69
- Process.kill('KILL', @pid)
88
+ if @pid == nil
89
+ BayLog.warn("%s Cannot kill process (pid is null)", tur)
90
+ else
91
+ BayLog.debug("%s KILL PROCESS!: %d", tur, @pid)
92
+ Process.kill('KILL', @pid)
93
+ end
70
94
 
71
95
  return false # not aborted immediately
72
96
  end
@@ -75,29 +99,110 @@ module Baykit
75
99
  # Other methods
76
100
  ######################################################
77
101
 
78
- def start_tour(env)
102
+ def req_start_tour
103
+ if @cgi_docker.add_process_count
104
+ BayLog.info("%s start tour: wait count=%d", @tour, @cgi_docker.get_wait_count)
105
+ start_tour
106
+ else
107
+ BayLog.warn("%s Cannot start tour: wait count=%d", @tour, @cgi_docker.get_wait_count)
108
+ agt = GrandAgent.get(@tour.ship.agent_id)
109
+ agt.add_postpone(self)
110
+ end
111
+ access()
112
+ end
113
+
114
+ def start_tour
79
115
  @available = false
80
116
 
81
- @std_in = IO.pipe()
82
- @std_out = IO.pipe()
83
- @std_err = IO.pipe()
84
- @std_in[1].set_encoding("ASCII-8BIT")
85
- @std_out[0].set_encoding("ASCII-8BIT")
86
- @std_err[0].set_encoding("ASCII-8BIT")
117
+ std_in = IO.pipe()
118
+ std_out = IO.pipe()
119
+ std_err = IO.pipe()
120
+ std_in[1].set_encoding("ASCII-8BIT")
121
+ std_out[0].set_encoding("ASCII-8BIT")
122
+ std_err[0].set_encoding("ASCII-8BIT")
87
123
 
88
- command = @cgi_docker.create_command(env)
124
+ command = @cgi_docker.create_command(@env)
89
125
  BayLog.debug("%s Spawn: %s", @tour, command)
90
- @pid = Process.spawn(env, command, :in => @std_in[0], :out => @std_out[1], :err => @std_err[1])
126
+ @pid = Process.spawn(env, command, :in => std_in[0], :out => std_out[1], :err => std_err[1])
91
127
  BayLog.debug("%s created process; %s", @tour, @pid)
92
128
 
93
- @std_in[0].close()
94
- @std_out[1].close()
95
- @std_err[1].close()
129
+ std_in[0].close()
130
+ std_out[1].close()
131
+ std_err[1].close()
132
+
133
+ @std_in_rd = IORudder.new(std_in[1])
134
+ @std_out_rd = IORudder.new(std_out[0])
135
+ @std_err_rd = IORudder.new(std_err[0])
96
136
  BayLog.debug("#{@tour} PID: #{pid}")
97
137
 
98
138
  @std_out_closed = false
99
139
  @std_err_closed = false
100
- access()
140
+
141
+ bufsize = 8192
142
+
143
+ agt = GrandAgent.get(@tour.ship.agent_id)
144
+
145
+ case(BayServer.harbor.cgi_multiplexer)
146
+ when Harbor::MULTIPLEXER_TYPE_SPIDER
147
+ mpx = agt.spider_multiplexer
148
+ @std_out_rd.set_non_blocking
149
+ @std_err_rd.set_non_blocking
150
+
151
+ when Harbor::MULTIPLEXER_TYPE_SPIN
152
+
153
+ def eof_checker()
154
+ begin
155
+ pid = Process.wait(handler.pid, Process::WNOHANG)
156
+ return pid != nil
157
+ rescue Errno::ECHILD => e
158
+ BayLog.error_e(e)
159
+ return true
160
+ end
161
+ end
162
+ mpx = agt.spin_multiplexer
163
+ @std_out_rd.set_non_blocking
164
+ @std_err_rd.set_non_blocking
165
+
166
+ when Harbor::MULTIPLEXER_TYPE_TAXI
167
+ mpx = agt.taxi_multiplexer
168
+
169
+ when Harbor::MULTIPLEXER_TYPE_JOB
170
+ mpx = agt.job_multiplexer
171
+
172
+ else
173
+ raise Sink.new();
174
+ end
175
+
176
+ if mpx != nil
177
+ @multiplexer = mpx
178
+ out_ship = CgiStdOutShip.new
179
+ out_tp = PlainTransporter.new(agt.net_multiplexer, out_ship, false, bufsize, false)
180
+
181
+ out_ship.init_std_out(@std_out_rd, @tour.ship.agent_id, @tour, out_tp, self)
182
+
183
+ mpx.add_rudder_state(
184
+ @std_out_rd,
185
+ RudderState.new(@std_out_rd, out_tp)
186
+ )
187
+
188
+ ship_id = @tour.ship.ship_id
189
+ @tour.res.set_consume_listener do |len, resume|
190
+ if resume
191
+ out_ship.resume_read(ship_id)
192
+ end
193
+ end
194
+
195
+ err_ship = CgiStdErrShip.new
196
+ err_tp = PlainTransporter.new(agt.net_multiplexer, err_ship, false, bufsize, false)
197
+ err_ship.init_std_err(@std_err_rd, @tour.ship.agent_id, self)
198
+ mpx.add_rudder_state(
199
+ @std_err_rd,
200
+ RudderState.new(@std_err_rd, err_tp)
201
+ )
202
+
203
+ mpx.req_read(@std_out_rd)
204
+ mpx.req_read(@std_err_rd)
205
+ end
101
206
  end
102
207
 
103
208
  def std_out_closed()
@@ -115,7 +220,7 @@ module Baykit
115
220
  end
116
221
 
117
222
  def access()
118
- @last_access = Time.now.to_i
223
+ @last_access = Time.now.tv_sec
119
224
  end
120
225
 
121
226
  def timed_out()
@@ -123,7 +228,7 @@ module Baykit
123
228
  return false
124
229
  end
125
230
 
126
- duration_sec = Time.now.to_i - @last_access
231
+ duration_sec = Time.now.tv_sec - @last_access
127
232
  BayLog.debug("%s Check CGI timeout: dur=%d, timeout=%d", @tour, duration_sec, @cgi_docker.timeout_sec)
128
233
  return duration_sec > @cgi_docker.timeout_sec
129
234
  end
@@ -132,9 +237,8 @@ module Baykit
132
237
  BayLog.debug("%s CGI Process finished: pid=%s", @tour, @pid)
133
238
 
134
239
  pid, stat = Process.wait2(@pid)
135
- print(stat)
136
-
137
240
  BayLog.debug("%s CGI Process finished: pid=%s code=%s", @tour, pid, stat.exitstatus)
241
+ agt_id = @tour.ship.agent_id
138
242
 
139
243
  begin
140
244
  if stat.exitstatus != 0
@@ -142,11 +246,18 @@ module Baykit
142
246
  BayLog.error("%s CGI Invalid exit status pid=%d code=%s", @tour, @pid, stat.exitstatus)
143
247
  @tour.res.send_error(@tour_id, HttpStatus::INTERNAL_SERVER_ERROR, "Invalid exit Status")
144
248
  else
145
- @tour.res.end_content(@tour_id)
249
+ @tour.res.end_res_content(@tour_id)
146
250
  end
147
251
  rescue IOError => e
148
252
  BayLog.error_e(e)
149
253
  end
254
+
255
+ @cgi_docker.sub_process_count
256
+ if @cgi_docker.get_wait_count > 0
257
+ BayLog.warn("agt#%d Catch up postponed process: process wait count=%d", agt_id, @cgi_docker.get_wait_count)
258
+ agt = GrandAgent.get(agt_id)
259
+ agt.req_catch_up
260
+ end
150
261
  end
151
262
  end
152
263
  end
@@ -1,5 +1,5 @@
1
1
  require 'baykit/bayserver/agent/next_socket_action'
2
- require 'baykit/bayserver/watercraft/yacht'
2
+ require 'baykit/bayserver/common/read_only_ship'
3
3
  require 'baykit/bayserver/util/string_util'
4
4
  require 'baykit/bayserver/util/reusable'
5
5
 
@@ -7,13 +7,11 @@ module Baykit
7
7
  module BayServer
8
8
  module Docker
9
9
  module Cgi
10
- class CgiStdErrYacht < Baykit::BayServer::WaterCraft::Yacht
10
+ class CgiStdErrShip < Baykit::BayServer::Common::ReadOnlyShip
11
11
 
12
12
  include Baykit::BayServer::Agent
13
13
  include Baykit::BayServer::Util
14
14
 
15
- attr :tour
16
- attr :tour_id
17
15
  attr :handler
18
16
 
19
17
  def initialize
@@ -21,8 +19,13 @@ module Baykit
21
19
  reset()
22
20
  end
23
21
 
22
+ def init_std_err(rd, agt_id, handler)
23
+ init(agt_id, rd, nil)
24
+ @handler = handler
25
+ end
26
+
24
27
  def to_s()
25
- return "CGIErrYat##{@yacht_id}/#{@object_id} tour=#{@tour} id=#{@tour_id}";
28
+ return "agt#{@agent_id} err_ship#{@ship_id}/#{@object_id}";
26
29
  end
27
30
 
28
31
  ######################################################
@@ -30,16 +33,15 @@ module Baykit
30
33
  ######################################################
31
34
 
32
35
  def reset()
33
- @tour = nil
34
- @tour_id = 0
35
- @timeout_sec = 0
36
+ super
37
+ @handler = nil
36
38
  end
37
39
 
38
40
  ######################################################
39
- # implements Yacht
41
+ # implements ReadOnlyShip
40
42
  ######################################################
41
43
 
42
- def notify_read(buf, adr)
44
+ def notify_read(buf)
43
45
 
44
46
  BayLog.debug("%s CGI StdErr %d bytesd", self, buf.length)
45
47
  if(buf.length() > 0)
@@ -50,18 +52,22 @@ module Baykit
50
52
 
51
53
  end
52
54
 
55
+ def notify_error(e)
56
+ BayLog.debug_e(e)
57
+ end
58
+
53
59
  def notify_eof()
54
- BayLog.debug("%s stderr EOF\\(^o^)/", @tour)
60
+ BayLog.debug("agt#%d CGI stderr EOF\\(^o^)/", @agent_id)
55
61
  return NextSocketAction::CLOSE
56
62
  end
57
63
 
58
64
  def notify_close()
59
- BayLog.debug("%s stderr notifyClose", @tour)
60
- @tour.req.content_handler.std_err_closed()
65
+ BayLog.debug("agt#%d CGI stderr notifyClose", @agent_id)
66
+ @handler.std_err_closed()
61
67
  end
62
68
 
63
69
  def check_timeout(duration_sec)
64
- BayLog.debug("%s stderr Check timeout: dur=%d, timeout=%d", @tour, duration_sec, @timeout_sec)
70
+ BayLog.debug("%s stderr Check timeout: dur=%d", @tour, duration_sec)
65
71
  return @handler.timed_out()
66
72
  end
67
73
 
@@ -69,12 +75,6 @@ module Baykit
69
75
  # Custom methods
70
76
  ######################################################
71
77
 
72
- def init(tur, handler)
73
- init_yacht()
74
- @tour = tur
75
- @tour_id = tur.tour_id
76
- @handler = handler
77
- end
78
78
  end
79
79
  end
80
80
  end
@@ -1,5 +1,5 @@
1
1
  require 'baykit/bayserver/agent/next_socket_action'
2
- require 'baykit/bayserver/watercraft/yacht'
2
+ require 'baykit/bayserver/common/read_only_ship'
3
3
  require 'baykit/bayserver/util/string_util'
4
4
  require 'baykit/bayserver/util/reusable'
5
5
 
@@ -7,7 +7,7 @@ module Baykit
7
7
  module BayServer
8
8
  module Docker
9
9
  module Cgi
10
- class CgiStdOutYacht < Baykit::BayServer::WaterCraft::Yacht
10
+ class CgiStdOutShip < Baykit::BayServer::Common::ReadOnlyShip
11
11
 
12
12
  include Baykit::BayServer::Agent
13
13
  include Baykit::BayServer::Util
@@ -26,8 +26,16 @@ module Baykit
26
26
  reset()
27
27
  end
28
28
 
29
+ def init_std_out(rd, agent_id, tur, tp, handler)
30
+ init(agent_id, rd, tp)
31
+ @handler = handler
32
+ @tour = tur
33
+ @tour_id = tur.tour_id
34
+ @header_reading = true
35
+ end
36
+
29
37
  def to_s()
30
- return "CGIYat##{@yacht_id}/#{@object_id} tour=#{@tour} id=#{@tour_id}";
38
+ return "agt##{@agent_id} out_ship#{@ship_id}/#{@object_id}";
31
39
  end
32
40
 
33
41
  ######################################################
@@ -44,10 +52,10 @@ module Baykit
44
52
  end
45
53
 
46
54
  ######################################################
47
- # implements Yacht
55
+ # implements ReadOnlyShip
48
56
  ######################################################
49
57
 
50
- def notify_read(buf, adr)
58
+ def notify_read(buf)
51
59
  @file_wrote_len += buf.length
52
60
  BayLog.trace("%s read file %d bytes: total=%d", self, buf.length, @file_wrote_len)
53
61
 
@@ -110,7 +118,7 @@ module Baykit
110
118
  @remain += buf[pos .. -1]
111
119
  else
112
120
  if buf.length - pos > 0
113
- available = @tour.res.send_content(@tour_id, buf, pos, buf.length - pos);
121
+ available = @tour.res.send_res_content(@tour_id, buf, pos, buf.length - pos);
114
122
  end
115
123
  end
116
124
 
@@ -123,6 +131,10 @@ module Baykit
123
131
 
124
132
  end
125
133
 
134
+ def notify_error(e)
135
+ BayLog.debug_e(e, "%s CGI notifyError", self)
136
+ end
137
+
126
138
  def notify_eof()
127
139
  BayLog.debug("%s stdout EOF(^o^)", @tour)
128
140
  return NextSocketAction::CLOSE
@@ -130,7 +142,7 @@ module Baykit
130
142
 
131
143
  def notify_close()
132
144
  BayLog.debug("%s stdout notifyClose", @tour)
133
- @tour.req.content_handler.std_out_closed()
145
+ @handler.std_out_closed()
134
146
  end
135
147
 
136
148
  def check_timeout(duration_sec)
@@ -150,17 +162,6 @@ module Baykit
150
162
  # Custom methods
151
163
  ######################################################
152
164
 
153
- def init(tur, valve, handler)
154
- init_yacht()
155
- @handler = handler
156
- @tour = tur
157
- @tour_id = tur.tour_id
158
- tur.res.set_consume_listener do |len, resume|
159
- if resume
160
- valve.open_valve();
161
- end
162
- end
163
- end
164
165
  end
165
166
  end
166
167
  end
@@ -64,7 +64,7 @@ module Baykit
64
64
  # Handle StdOut
65
65
  HttpUtil.parse_message_headers(@std_out[0], @tour.res.headers)
66
66
 
67
- if BayServer.harbor.trace_header?
67
+ if BayServer.harbor.trace_header
68
68
  @tour.res.headers.names.each do |name|
69
69
  @tour.res.headers.values(name).each do |value|
70
70
  BayLog.info("%s CGI: resHeader: %s=%s", @tour, name, value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bayserver-docker-cgi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
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-04 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.1
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.1
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.
@@ -37,8 +37,8 @@ files:
37
37
  - lib/baykit/bayserver/docker/cgi/cgi_docker.rb
38
38
  - lib/baykit/bayserver/docker/cgi/cgi_message.rb
39
39
  - lib/baykit/bayserver/docker/cgi/cgi_req_content_handler.rb
40
- - lib/baykit/bayserver/docker/cgi/cgi_std_err_yacht.rb
41
- - lib/baykit/bayserver/docker/cgi/cgi_std_out_yacht.rb
40
+ - lib/baykit/bayserver/docker/cgi/cgi_std_err_ship.rb
41
+ - lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb
42
42
  - lib/baykit/bayserver/docker/cgi/cgi_train.rb
43
43
  - lib/baykit/bayserver/docker/cgi/php_cgi_docker.rb
44
44
  homepage: https://baykit.yokohama