Class: P2p2::P1Worker
- Inherits:
-
Object
- Object
- P2p2::P1Worker
- Defined in:
- lib/p2p2/p1_worker.rb
Instance Method Summary collapse
-
#initialize(paird_host, paird_port, title, appd_host, appd_port) ⇒ P1Worker
constructor
initialize.
-
#looping ⇒ Object
looping.
-
#quit! ⇒ Object
quit!.
Constructor Details
#initialize(paird_host, paird_port, title, appd_host, appd_port) ⇒ P1Worker
initialize
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/p2p2/p1_worker.rb', line 7 def initialize( paird_host, paird_port, title, appd_host, appd_port ) @paird_host = paird_host @paird_port = paird_port @title = title @appd_addr = Socket.sockaddr_in( appd_port, appd_host ) @reads = [] @writes = [] @roles = {} # sock => :dotr / :ctl / :tun / :dst @dst_infos = ConcurrentHash.new @tun_infos = ConcurrentHash.new new_a_pipe new_a_ctl end |
Instance Method Details
#looping ⇒ Object
looping
25 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 62 63 64 65 66 67 68 |
# File 'lib/p2p2/p1_worker.rb', line 25 def looping puts "#{ Time.new } looping" loop_renew_ctl loop_check_state loop do rs, ws = IO.select( @reads, @writes ) rs.each do | sock | role = @roles[ sock ] case role when :dotr then read_dotr( sock ) when :ctl then read_ctl( sock ) when :tun then read_tun( sock ) when :dst then read_dst( sock ) else puts "#{ Time.new } read unknown role #{ role }" close_sock( sock ) end end ws.each do | sock | role = @roles[ sock ] case role when :tun then write_tun( sock ) when :dst then write_dst( sock ) else puts "#{ Time.new } write unknown role #{ role }" close_sock( sock ) end end end rescue Interrupt => e puts e.class quit! end |
#quit! ⇒ Object
quit!
73 74 75 76 |
# File 'lib/p2p2/p1_worker.rb', line 73 def quit! # puts "debug exit" exit end |