packet 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/TODO +2 -0
- data/examples/netbeans.jpg +0 -0
- data/examples/write_bulk.rb +41 -0
- data/lib/packet.rb +19 -26
- data/lib/{disconnect_error.rb → packet/disconnect_error.rb} +3 -2
- data/lib/{double_keyed_hash.rb → packet/double_keyed_hash.rb} +0 -0
- data/lib/{callback.rb → packet/packet_callback.rb} +0 -0
- data/lib/{connection.rb → packet/packet_connection.rb} +10 -3
- data/lib/{core.rb → packet/packet_core.rb} +84 -40
- data/lib/{event.rb → packet/packet_event.rb} +1 -1
- data/lib/{packet_guid.rb → packet/packet_guid.rb} +0 -0
- data/lib/{class_helpers.rb → packet/packet_helper.rb} +0 -0
- data/lib/{packet_master.rb → packet/packet_master.rb} +18 -10
- data/lib/{meta_pimp.rb → packet/packet_meta_pimp.rb} +1 -1
- data/lib/packet/packet_mongrel.rb +218 -0
- data/lib/{nbio.rb → packet/packet_nbio.rb} +37 -37
- data/lib/{bin_parser.rb → packet/packet_parser.rb} +0 -0
- data/lib/{periodic_event.rb → packet/packet_periodic_event.rb} +0 -0
- data/lib/{pimp.rb → packet/packet_pimp.rb} +3 -1
- data/lib/{worker.rb → packet/packet_worker.rb} +1 -4
- data/lib/{timer_store.rb → packet/timer_store.rb} +26 -18
- data/lib/packet_mongrel.rb +200 -206
- data/spec/spec_helper.rb +10 -0
- data/spec/test_double_keyed_hash.rb +14 -0
- data/spec/test_packet_core.rb +38 -0
- metadata +25 -20
- data/lib/thread_pool.rb +0 -54
- data/lib/worker_pool.rb +0 -10
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hemant Kumar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2008-02-11 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,32 +28,37 @@ files:
|
|
28
28
|
- README
|
29
29
|
- Rakefile
|
30
30
|
- TODO
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- lib/
|
35
|
-
- lib/
|
36
|
-
- lib/
|
37
|
-
- lib/
|
38
|
-
- lib/
|
39
|
-
- lib/
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
31
|
+
- spec/test_double_keyed_hash.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
- spec/test_packet_core.rb
|
34
|
+
- lib/packet
|
35
|
+
- lib/packet/disconnect_error.rb
|
36
|
+
- lib/packet/packet_pimp.rb
|
37
|
+
- lib/packet/packet_connection.rb
|
38
|
+
- lib/packet/packet_guid.rb
|
39
|
+
- lib/packet/double_keyed_hash.rb
|
40
|
+
- lib/packet/packet_master.rb
|
41
|
+
- lib/packet/packet_parser.rb
|
42
|
+
- lib/packet/packet_periodic_event.rb
|
43
|
+
- lib/packet/packet_callback.rb
|
44
|
+
- lib/packet/packet_worker.rb
|
45
|
+
- lib/packet/packet_core.rb
|
46
|
+
- lib/packet/packet_meta_pimp.rb
|
47
|
+
- lib/packet/packet_mongrel.rb
|
48
|
+
- lib/packet/packet_helper.rb
|
49
|
+
- lib/packet/timer_store.rb
|
50
|
+
- lib/packet/packet_event.rb
|
51
|
+
- lib/packet/packet_nbio.rb
|
44
52
|
- lib/packet.rb
|
45
|
-
- lib/event.rb
|
46
|
-
- lib/core.rb
|
47
|
-
- lib/thread_pool.rb
|
48
53
|
- lib/packet_mongrel.rb
|
49
|
-
- lib/timer_store.rb
|
50
|
-
- lib/worker_pool.rb
|
51
54
|
- examples/concurrent_thread.c
|
52
55
|
- examples/sample_server.rb
|
56
|
+
- examples/write_bulk.rb
|
53
57
|
- examples/asteroid.h
|
54
58
|
- examples/persistent_print.rb
|
55
59
|
- examples/use_stuff.rb
|
56
60
|
- examples/extconf.h
|
61
|
+
- examples/netbeans.jpg
|
57
62
|
- examples/asteroid.c
|
58
63
|
- examples/extconf.rb
|
59
64
|
has_rdoc: true
|
data/lib/thread_pool.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Packet
|
2
|
-
class WorkData
|
3
|
-
attr_accessor :data,:block
|
4
|
-
def initialize(args,&block)
|
5
|
-
@data = args
|
6
|
-
@block = block
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class ThreadPool
|
11
|
-
attr_accessor :size
|
12
|
-
attr_accessor :threads
|
13
|
-
attr_accessor :work_queue
|
14
|
-
def initialize(size)
|
15
|
-
@size = size
|
16
|
-
@threads = []
|
17
|
-
@work_queue = Queue.new
|
18
|
-
@running_tasks = Queue.new
|
19
|
-
@size.times { add_thread }
|
20
|
-
end
|
21
|
-
def defer(*args,&block)
|
22
|
-
@work_queue << WorkData.new(args,&block)
|
23
|
-
end
|
24
|
-
|
25
|
-
def add_thread
|
26
|
-
@threads << Thread.new do
|
27
|
-
while true
|
28
|
-
task = @work_queue.pop
|
29
|
-
@running_tasks << task
|
30
|
-
block_arity = task.block.arity
|
31
|
-
begin
|
32
|
-
block_arity == 0 ? task.block.call : task.block.call(*(task.data))
|
33
|
-
rescue
|
34
|
-
puts $!
|
35
|
-
puts $!.backtrace
|
36
|
-
end
|
37
|
-
@running_tasks.pop
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# method ensures exclusive run of deferred tasks for 0.5 seconds, so as they do get a chance to run.
|
43
|
-
def exclusive_run
|
44
|
-
if @running_tasks.empty? && @work_queue.empty?
|
45
|
-
return
|
46
|
-
else
|
47
|
-
sleep(0.005)
|
48
|
-
return
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end # end of ThreadPool class
|
52
|
-
|
53
|
-
end # end of Packet module
|
54
|
-
|
data/lib/worker_pool.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# implements worker pools
|
2
|
-
# Warning: Work in Progress
|
3
|
-
# FIXME: but often what user needs is ability to have different workers and control their execution seperately.
|
4
|
-
# Above requirment comes from BackgrounDrb experience, and may not be used otherwise.
|
5
|
-
|
6
|
-
module Packet
|
7
|
-
class WorkerPool
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|