Class: Baykit::BayServer::Tours::SendFileYacht
- Inherits:
-
WaterCraft::Yacht
- Object
- WaterCraft::Yacht
- Baykit::BayServer::Tours::SendFileYacht
- Defined in:
- lib/baykit/bayserver/tours/send_file_yacht.rb
Constant Summary
Constants inherited from WaterCraft::Yacht
WaterCraft::Yacht::INVALID_YACHT_ID, WaterCraft::Yacht::YACHT_ID_NOCHECK
Instance Attribute Summary collapse
-
#file_len ⇒ Object
readonly
Returns the value of attribute file_len.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_wrote_len ⇒ Object
readonly
Returns the value of attribute file_wrote_len.
-
#tour ⇒ Object
readonly
Returns the value of attribute tour.
-
#tour_id ⇒ Object
readonly
Returns the value of attribute tour_id.
Attributes inherited from WaterCraft::Yacht
Instance Method Summary collapse
- #check_timeout(duration) ⇒ Object
-
#init(tur, file_name, tp) ⇒ Object
Custom methods.
-
#initialize ⇒ SendFileYacht
constructor
A new instance of SendFileYacht.
- #notify_close ⇒ Object
- #notify_eof ⇒ Object
-
#notify_read(buf, adr) ⇒ Object
implements Yacht.
-
#reset ⇒ Object
implements Reusable.
- #to_s ⇒ Object
Methods inherited from WaterCraft::Yacht
Methods included from Agent::Transporter::DataListener
#notify_connect, #notify_handshake_done, #notify_protocol_error
Constructor Details
#initialize ⇒ SendFileYacht
Returns a new instance of SendFileYacht.
21 22 23 24 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 21 def initialize super reset() end |
Instance Attribute Details
#file_len ⇒ Object (readonly)
Returns the value of attribute file_len.
18 19 20 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 18 def file_len @file_len end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
17 18 19 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 17 def file_name @file_name end |
#file_wrote_len ⇒ Object (readonly)
Returns the value of attribute file_wrote_len.
19 20 21 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 19 def file_wrote_len @file_wrote_len end |
#tour ⇒ Object (readonly)
Returns the value of attribute tour.
14 15 16 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 14 def tour @tour end |
#tour_id ⇒ Object (readonly)
Returns the value of attribute tour_id.
15 16 17 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 15 def tour_id @tour_id end |
Instance Method Details
#check_timeout(duration) ⇒ Object
72 73 74 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 72 def check_timeout(duration) BayLog.trace("Check timeout: %s", @file_name) end |
#init(tur, file_name, tp) ⇒ Object
Custom methods
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 80 def init(tur, file_name, tp) init_yacht() @tour = tur @tour_id = tur.id() @file_name = file_name @file_len = File.size(file_name) #file = File.open(file_name, "rb") tur.res.set_consume_listener do |len, resume| if resume tp.open_valve(); end end end |
#notify_close ⇒ Object
68 69 70 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 68 def notify_close() BayLog.trace("File closed: %s", @file_name) end |
#notify_eof ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 58 def notify_eof() BayLog.trace("%s EOF(^o^) %s", self, @file_name) begin @tour.res.end_content(@tour_id) rescue IOError => e BayLog.debug_e(e) end return NextSocketAction::CLOSE end |
#notify_read(buf, adr) ⇒ Object
implements Yacht
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 45 def notify_read(buf, adr) @file_wrote_len += buf.length BayLog.trace("%s read file %d bytes: total=%d/%d", self, buf.length, @file_wrote_len, @file_len) available = @tour.res.send_content(@tour_id, buf, 0, buf.length) if available return NextSocketAction::CONTINUE; else return NextSocketAction::SUSPEND; end end |
#reset ⇒ Object
implements Reusable
34 35 36 37 38 39 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 34 def reset() @file_wrote_len = 0 @file_len = 0 @tour = nil @tour_id = 0 end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 26 def to_s() return "filyt##{@yacht_id}/#{@object_id} tour=#{@tour} id=#{@tour_id}"; end |