socket_duplex 1.1.6 → 1.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba10e612d5278cbe626c7e54595546bd783533c2
4
- data.tar.gz: 37bf8986a52ca7e480edcfab09c528d46b3650dd
3
+ metadata.gz: 396d97092eb58854d336f76c7058737967201b95
4
+ data.tar.gz: b28000e38753d974e7442f0209b28dc6efe4a3e3
5
5
  SHA512:
6
- metadata.gz: 006b58d014a9f89b9eee9601420b67b12712855d1c25ecce2aebe7d308978cff2e05e7123dddf93723289980fa5c797d1e240c44d28b828bf51caf1a67d2c4e2
7
- data.tar.gz: 7840fdd2bd34c6113e9b33d46581ca1a448cc665db60be9cb67488fc561eeb251d4aad8033701db60590b0102404aa62a28903354874249ef39e519705b593d8
6
+ metadata.gz: 9a53ca6192b230c303f6f0e2bc9069fcd30cf27f1436af1fcab07f62f0b044cc23598f707903a73cccca9afc53bd70b2250d7b7290c030a686b650593312ef4f
7
+ data.tar.gz: e9728db7f2ba14f3d78101753b6c12f094ff6bca5c50983780e36b2fd735b5672fe08c95bf4409818056cffa4d0f2988ea47e5cf28b5a865bbea62acf98eee89
data/lib/socket_duplex.rb CHANGED
@@ -3,13 +3,11 @@ require 'socket'
3
3
  require 'securerandom'
4
4
 
5
5
  require_relative 'websocket-client-simple'
6
- require 'utils'
7
6
 
8
7
  module Rack
9
8
  class SocketDuplex
10
9
  MAX_QUEUE_SIZE = 50
11
10
  NUM_OF_THREADS = 5
12
- @@queue = Utils::QueueWithTimeout.new
13
11
 
14
12
  def initialize(app, socket_path, secful_key, verify_mode=OpenSSL::SSL::VERIFY_PEER)
15
13
  @app, @socket_path, @verify_mode = app, socket_path, verify_mode
@@ -21,8 +19,8 @@ module Rack
21
19
  puts 'secful: agent_identifier'
22
20
  @machine_ip = Socket.ip_address_list.detect(&:ipv4_private?).try(:ip_address)
23
21
  puts 'secful: machine_ip'
24
- #@queue = SizedQueue.new(MAX_QUEUE_SIZE)
25
- #puts 'secful: queue init ' + @queue.__id__.to_s
22
+ @queue = SizedQueue.new(MAX_QUEUE_SIZE)
23
+ puts 'secful: queue init ' + @queue.__id__.to_s
26
24
  @threads_to_sockets = {}
27
25
  puts 'secful: threads_to_sockets'
28
26
  Thread.new { activate_workers() }
@@ -50,10 +48,10 @@ module Rack
50
48
  puts 'secful: _call'
51
49
  status, headers, body = @app.call(env)
52
50
  puts 'secful: app.call'
53
- puts 'secful: queue.len = ' + @@queue.length.to_s
54
- if @@queue.length < MAX_QUEUE_SIZE
51
+ puts 'secful: queue.len = ' + @queue.length.to_s + ' id: ' + @queue.__id__.to_s
52
+ if @queue.length < MAX_QUEUE_SIZE
55
53
  puts 'secful: about to put in queue'
56
- @@queue << env
54
+ @queue << env
57
55
  puts 'secful: put in queue'
58
56
  end
59
57
  return [status, headers, body]
@@ -63,21 +61,17 @@ module Rack
63
61
  puts 'secful: activate_workers'
64
62
  NUM_OF_THREADS.times do
65
63
  puts 'secful: new thread'
66
- Thread.new {worker()}
67
- puts 'secful: thread started'
64
+ thr = Thread.new {worker()}
65
+ puts 'secful: thread started ' + thr.__id__.to_s
68
66
  end
69
67
  end
70
68
 
71
69
  def worker
72
70
  loop do
73
71
  begin
74
- #puts 'secful: worker start: ' + @@queue.__id__.to_s
75
- begin
76
- env = @@queue.pop_with_timeout(1)
77
- rescue => e
78
- #puts 'secful: queue-pop-exception: ' + e.message
79
- end
80
- #puts 'secful: worker poped'
72
+ puts 'secful: worker start: ' + Thread.current.__id__.to_s + 'queue: ' + @queue.__id__.to_s
73
+ env = @queue.pop
74
+ puts 'secful: worker poped'
81
75
  if env
82
76
  puts 'secful: env'
83
77
  connect_to_ws(Thread.current)
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "socket_duplex"
6
- spec.version = '1.1.6'
6
+ spec.version = '1.1.7'
7
7
  spec.authors = ["Secful"]
8
8
  spec.description = %q{Rack middleware that duplexes HTTP traffic}
9
9
  spec.summary = spec.description
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socket_duplex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Secful
@@ -117,7 +117,6 @@ files:
117
117
  - Gemfile
118
118
  - README.md
119
119
  - lib/socket_duplex.rb
120
- - lib/utils.rb
121
120
  - lib/websocket-client-simple.rb
122
121
  - lib/websocket-client-simple/client.rb
123
122
  - lib/websocket-client-simple/version.rb
data/lib/utils.rb DELETED
@@ -1,36 +0,0 @@
1
- module Rack::Utils
2
- #https://spin.atomicobject.com/2014/07/07/ruby-queue-pop-timeout/
3
- class QueueWithTimeout
4
- def initialize
5
- @mutex = Mutex.new
6
- @queue = []
7
- @recieved = ConditionVariable.new
8
- end
9
-
10
- def <<(x)
11
- @mutex.synchronize do
12
- @queue << x
13
- @recieved.signal
14
- end
15
- end
16
-
17
- def length
18
- @queue.length
19
- end
20
-
21
- def pop(non_block = false)
22
- pop_with_timeout(non_block ? 0 : nil)
23
- end
24
-
25
- def pop_with_timeout(timeout = nil)
26
- @mutex.synchronize do
27
- if @queue.empty?
28
- @recieved.wait(@mutex, timeout) if timeout != 0
29
- #if we're still empty after the timeout, raise exception
30
- raise ThreadError, "queue empty" if @queue.empty?
31
- end
32
- @queue.shift
33
- end
34
- end
35
- end
36
- end