DIY-pcap 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,14 +45,15 @@ module DIY
45
45
  DIY::Logger.info @offline.mac_learner.dump
46
46
  break
47
47
  end
48
- #~ begin
49
- #~ @offline.next_pcap
50
- #~ server.terminal
51
- #~ rescue EOFError
52
- #~ client.terminal
53
- #~ server.terminal
54
- #~ break
55
- #~ end
48
+ begin
49
+ @offline.next_pcap
50
+ client.terminal
51
+ server.terminal
52
+ rescue EOFError
53
+ client.terminal
54
+ server.terminal
55
+ break
56
+ end
56
57
  #~ client,server = @client, @server
57
58
  rescue EOFError
58
59
  client.terminal
@@ -90,8 +91,9 @@ module DIY
90
91
  end
91
92
 
92
93
  recv_pkt_proc_set( pkts )
94
+ @ready = false
93
95
  server.ready(&@recv_pkt_proc)
94
-
96
+ @ready = true
95
97
  client_send(client, pkts)
96
98
  wait_recv_ok(pkts)
97
99
  server.terminal
@@ -103,6 +105,7 @@ module DIY
103
105
  # 不重新赋值, 防止 DRb 回收
104
106
  @recv_pkt_proc ||= lambda do |recv_pkt|
105
107
  begin
108
+ next unless @ready # strip this recv pkt unless it's ready to.
106
109
  next if @error_flag # error accur waiting other thread do with it
107
110
  @recv_pkt_keeper = Packet.new(recv_pkt)
108
111
  @strategy.call(@queue_keeper.first, @recv_pkt_keeper, @queue_keeper)
@@ -45,7 +45,7 @@ module DIY
45
45
  timeout(timeout) do
46
46
  loop do
47
47
  break if block.call
48
- sleep 0.01
48
+ sleep 0.001
49
49
  end
50
50
  end
51
51
  end
@@ -1,5 +1,5 @@
1
1
  module DIY
2
2
  class PCAP
3
- VERSION = "0.3.6"
3
+ VERSION = "0.3.8"
4
4
  end
5
5
  end
@@ -30,7 +30,10 @@ module DIY
30
30
  @recv_t = Thread.new do
31
31
  DIY::Logger.info "start thread recving pkt..."
32
32
  @live.loop do |this, pkt|
33
- next unless @start
33
+ if ! @start
34
+ @recv_stop_flag = true
35
+ next
36
+ end
34
37
  @queue.push(pkt.body)
35
38
  end
36
39
  DIY::Logger.debug "worker: stopped loop recv"
@@ -45,7 +48,15 @@ module DIY
45
48
  begin
46
49
  pkt = @queue.pop
47
50
  #~ DIY::Logger.info "callback: #{pkt}"
48
- @block.call(pkt) if @start and @block
51
+
52
+ if ! @start
53
+ @callback_stop_flag = true
54
+ next
55
+ end
56
+
57
+ if @block and pkt
58
+ @block.call(pkt)
59
+ end
49
60
  rescue DRb::DRbConnError
50
61
  DIY::Logger.info "closed connection by controller"
51
62
  @start = false
@@ -61,24 +72,22 @@ module DIY
61
72
 
62
73
  #收包
63
74
  def ready(&block)
64
- @start = false
75
+ stopping
65
76
  DIY::Logger.info("start recv pkt")
66
77
  @block = block
67
- @queue.clear
68
- @start = true
78
+ start
69
79
  end
70
80
 
71
81
  # 停止收发
72
82
  def terminal
73
83
  DIY::Logger.info("stop recv pkt")
74
- @start = false
75
- @queue.clear
84
+ pause
76
85
  end
77
86
 
78
87
  # 停止线程
79
88
  def stop
80
89
  @running = false
81
- @queue.push nil
90
+ pause
82
91
  @live.break
83
92
  Utils.wait_until { @recv_t && ! @recv_t.alive? }
84
93
  Utils.wait_until { @callback_t && ! @callback_t.alive? }
@@ -92,6 +101,45 @@ module DIY
92
101
  def inspect
93
102
  "<Worker: #{@live.net}>"
94
103
  end
104
+
105
+ private
106
+ def stopping
107
+ pause
108
+ while ! paused?
109
+ end
110
+ end
111
+
112
+ def pause
113
+ @start = false
114
+ @recv_stop_flag = false
115
+ @callback_stop_flag = false
116
+ @queue.clear
117
+ @queue.push nil
118
+ end
119
+
120
+ def start
121
+ @start = true
122
+ end
123
+
124
+ def paused?
125
+ ! @start and recv_stop? and callback_stop?
126
+ end
127
+
128
+ def recv_stop
129
+ @recv_stop_flag = true
130
+ end
131
+
132
+ def recv_stop?
133
+ @recv_stop_flag
134
+ end
135
+
136
+ def callback_stop
137
+ @callback_stop_flag = true
138
+ end
139
+
140
+ def callback_stop?
141
+ @callback_stop_flag
142
+ end
95
143
 
96
144
  end
97
145
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: DIY-pcap
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 3
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 3
8
- - 6
9
- version: 0.3.6
9
+ - 8
10
+ version: 0.3.8
10
11
  platform: ruby
11
12
  authors:
12
13
  - yafei Lee
@@ -14,8 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2012-10-22 00:00:00 +08:00
18
- default_executable:
18
+ date: 2012-10-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi-pcap
@@ -25,6 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
+ hash: 23
28
29
  segments:
29
30
  - 0
30
31
  - 2
@@ -149,7 +150,6 @@ files:
149
150
  - spec/spec_helper.rb
150
151
  - spec/utils_spec.rb
151
152
  - spec/worker_spec.rb
152
- has_rdoc: true
153
153
  homepage: ""
154
154
  licenses: []
155
155
 
@@ -163,6 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
+ hash: 3
166
167
  segments:
167
168
  - 0
168
169
  version: "0"
@@ -171,13 +172,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - ">="
173
174
  - !ruby/object:Gem::Version
175
+ hash: 3
174
176
  segments:
175
177
  - 0
176
178
  version: "0"
177
179
  requirements: []
178
180
 
179
181
  rubyforge_project:
180
- rubygems_version: 1.3.7
182
+ rubygems_version: 1.8.24
181
183
  signing_key:
182
184
  specification_version: 3
183
185
  summary: DIY pcap send and recv