Class: Baykit::BayServer::Tours::SendFileTrain
- Inherits:
-
Baykit::BayServer::Train::Train
- Object
- Baykit::BayServer::Train::Train
- Baykit::BayServer::Tours::SendFileTrain
- Includes:
- Util
- Defined in:
- lib/baykit/bayserver/tours/send_file_train.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Attributes inherited from Baykit::BayServer::Train::Train
Instance Method Summary collapse
-
#initialize(tur, file) ⇒ SendFileTrain
constructor
A new instance of SendFileTrain.
-
#run ⇒ Object
implements Train.
Methods inherited from Baykit::BayServer::Train::Train
Constructor Details
#initialize(tur, file) ⇒ SendFileTrain
Returns a new instance of SendFileTrain.
17 18 19 20 |
# File 'lib/baykit/bayserver/tours/send_file_train.rb', line 17 def initialize(tur, file) super(tur) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/baykit/bayserver/tours/send_file_train.rb', line 15 def file @file end |
Instance Method Details
#run ⇒ Object
implements Train
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/baykit/bayserver/tours/send_file_train.rb', line 26 def run() @tour.res.set_consume_listener do |len, resume| end size = @tour.ship.protocol_handler.max_packet_data_size buf = StringUtil.alloc(size) File.open(file, "r") do |fd| begin while true while !@tour.res.available sleep(0.1) end begin fd.sysread(size, buf); rescue EOFError => e break rescue Exception => e @tour.res.send_error(@tour_id, HttpStatus::INTERNAL_SERVER_ERROR, e) break end @tour.res.send_content(@tour_id, buf, 0, buf.length); while !@tour.res.available sleep(0.1) end end @tour.res.end_content(@tour_id) rescue Exception => e BayLog.error_e(e); end end end |