Class: Baykit::BayServer::Docker::Cgi::CgiStdOutShip
- Inherits:
-
Common::ReadOnlyShip
- Object
- Common::ReadOnlyShip
- Baykit::BayServer::Docker::Cgi::CgiStdOutShip
- Includes:
- Agent, Util
- Defined in:
- lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb
Instance Attribute Summary collapse
-
#file_wrote_len ⇒ Object
readonly
Returns the value of attribute file_wrote_len.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#header_reading ⇒ Object
readonly
Returns the value of attribute header_reading.
-
#remain ⇒ Object
readonly
Returns the value of attribute remain.
-
#tour ⇒ Object
readonly
Returns the value of attribute tour.
-
#tour_id ⇒ Object
readonly
Returns the value of attribute tour_id.
Instance Method Summary collapse
- #check_timeout(duration_sec) ⇒ Object
- #init_std_out(rd, agent_id, tur, tp, handler) ⇒ Object
-
#initialize ⇒ CgiStdOutShip
constructor
A new instance of CgiStdOutShip.
- #notify_close ⇒ Object
- #notify_eof ⇒ Object
- #notify_error(e) ⇒ Object
-
#notify_read(buf) ⇒ Object
implements ReadOnlyShip.
-
#reset ⇒ Object
implements Reusable.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CgiStdOutShip
Returns a new instance of CgiStdOutShip.
24 25 26 27 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 24 def initialize super reset() end |
Instance Attribute Details
#file_wrote_len ⇒ Object (readonly)
Returns the value of attribute file_wrote_len.
15 16 17 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 15 def file_wrote_len @file_wrote_len end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
22 23 24 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 22 def handler @handler end |
#header_reading ⇒ Object (readonly)
Returns the value of attribute header_reading.
21 22 23 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 21 def header_reading @header_reading end |
#remain ⇒ Object (readonly)
Returns the value of attribute remain.
20 21 22 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 20 def remain @remain end |
#tour ⇒ Object (readonly)
Returns the value of attribute tour.
17 18 19 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 17 def tour @tour end |
#tour_id ⇒ Object (readonly)
Returns the value of attribute tour_id.
18 19 20 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 18 def tour_id @tour_id end |
Instance Method Details
#check_timeout(duration_sec) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 148 def check_timeout(duration_sec) BayLog.debug("%s Check StdOut timeout: tur=%s dur=%d", self, @tour, duration_sec) if @handler.timed_out() # Kill cgi process instead of handing timeout BayLog.warn("%s Process timed out! Kill process!: tur=%s pid=%d", self, @tour, @handler.pid) Process.kill("KILL", @handler.pid) return true end return false end |
#init_std_out(rd, agent_id, tur, tp, handler) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 29 def init_std_out(rd, agent_id, tur, tp, handler) init(agent_id, rd, tp) @handler = handler @tour = tur @tour_id = tur.tour_id @header_reading = true end |
#notify_close ⇒ Object
143 144 145 146 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 143 def notify_close() BayLog.debug("%s stdout notifyClose tur=%s", self, @tour) @handler.std_out_closed() end |
#notify_eof ⇒ Object
138 139 140 141 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 138 def notify_eof() BayLog.debug("%s stdout EOF(^o^) tur=%s", self, @tour) return NextSocketAction::CLOSE end |
#notify_error(e) ⇒ Object
134 135 136 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 134 def notify_error(e) BayLog.debug_e(e, "%s CGI notifyError tur=%s", self, @tour) end |
#notify_read(buf) ⇒ Object
implements ReadOnlyShip
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 58 def notify_read(buf) @file_wrote_len += buf.length BayLog.debug("%s on read (len=%d total=%d)", self, buf.length, @file_wrote_len) pos = 0 if @header_reading while true p = buf.index("\n", pos) #BayLog.debug("pos: %d", pos) if p == nil break end line = buf[pos .. p] pos = p + 1 if @remain.length > 0 line = @remain + line end @remain = "" line = line.strip() # if line is empty ("\r\n") # finish header reading. if StringUtil.empty?(line) @header_reading = false @tour.res.send_headers(@tour_id) break else if BayServer.harbor.trace_header() BayLog.info("%s CGI: res header line: %s", tour, line); end sep_pos = line.index(':') if sep_pos != nil key = line[0 .. sep_pos - 1].strip() val = line[sep_pos + 1 .. -1].strip() if key.downcase() == "status" begin val = val.split(" ")[0] @tour.res.headers.status = val.to_i() rescue => e BayLog.error_e(e) end else @tour.res.headers.add(key, val); end end end end end available = true if @header_reading @remain += buf[pos .. -1] else if buf.length - pos > 0 available = @tour.res.send_res_content(@tour_id, buf, pos, buf.length - pos); end end @handler.access() if available return NextSocketAction::CONTINUE; else return NextSocketAction::SUSPEND; end end |
#reset ⇒ Object
implements Reusable
45 46 47 48 49 50 51 52 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 45 def reset() @file_wrote_len = 0 @tour = nil @tour_id = 0 @header_reading = true @remain = "" @handler = nil end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/baykit/bayserver/docker/cgi/cgi_std_out_ship.rb', line 37 def to_s() return "agt##{@agent_id} out_ship#{@ship_id}/#{@object_id}"; end |