celluloid_pubsub 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: faa7d11ef4c8c4386d6c1f038acffd1c09f8640e
4
- data.tar.gz: f00d2631f80b29c369db480e2a6d48241a9b756b
3
+ metadata.gz: c703a33e176ab7877a83eb259536afa905b9aab2
4
+ data.tar.gz: d60ef25c80a4ebfffd92b9b289b9d1fdd0206a96
5
5
  SHA512:
6
- metadata.gz: 43df4cecdb8b824ba3de71838be4688c75483044a7d2f80b99a9f579ff61e529396ae8c9da281370da1ed94da1343bd1127cddb8598c74a54421c50c3f8bd605
7
- data.tar.gz: 7df5f27c57d397b2a4e1ded42eed6ca6f3fabdaf31b078f3d8f44b21bcac2d04dae614034b22d5ec8fca92cadcdbf582507f97f42190d4a00f0fb7b025052f1c
6
+ metadata.gz: 32e7cf4839a394666c6cc6c508781d6e2271f4faee03e4b10dc547984ea241f9fcd4e4320ee17481216f12bdaa5c4269caceac61320c770598471e5d8a28055f
7
+ data.tar.gz: 086654a510e94c6a1f4ab74ff34258e95e750e54a485d3d16577643b80249833a7ee58a4db5c37e2c175a46db09025a140423b00be45fd348b307f7ca2251259
data/README.md CHANGED
@@ -8,6 +8,8 @@ Description
8
8
 
9
9
  CelluloidPubsub is a simple ruby implementation of publish subscribe design patterns using celluloid actors and websockets, using Celluloid::Reel server
10
10
 
11
+ **Starting with version 0.9.0, the webserver will automatically detect an unused port instead of trying to connect by default to 1234 port. This solves some issues when this port is already used.**
12
+
11
13
  Starting with version 0.7.0, Support for Celluloid 0.17 has been added.
12
14
 
13
15
  Starting with version 0.6.0, Redis support was moved into gem [celluloid_pubsub_redis_adapter](https://github.com/bogdanRada/celluloid_pubsub_redis_adapter)
@@ -88,7 +88,7 @@ module CelluloidPubsub
88
88
  #
89
89
  # @api public
90
90
  def port
91
- @port ||= @options.fetch('port', CelluloidPubsub::WebServer::PORT)
91
+ @port ||= @options.fetch('port', nil) || CelluloidPubsub::WebServer.find_unused_port
92
92
  end
93
93
 
94
94
  # the method will return the path of the URL on which the servers acccepts the connection
@@ -40,7 +40,7 @@ module CelluloidPubsub
40
40
  #
41
41
  # @api public
42
42
  def debug_enabled?
43
- @server.present? && @server.alive? && @server.debug_enabled?
43
+ !@server.dead? && @server.debug_enabled?
44
44
  end
45
45
 
46
46
  # reads from the socket the message
@@ -54,7 +54,7 @@ module CelluloidPubsub
54
54
  # :nocov:
55
55
  def run
56
56
  loop do
57
- break if !Actor.current.alive? || @websocket.closed? || !@server.alive?
57
+ break if Actor.current.dead? || @websocket.closed? || @server.dead?
58
58
  message = try_read_websocket
59
59
  handle_websocket_message(message) if message.present?
60
60
  end
@@ -15,9 +15,9 @@ module CelluloidPubsub
15
15
  # major release version
16
16
  MAJOR = 0
17
17
  # minor release version
18
- MINOR = 8
18
+ MINOR = 9
19
19
  # tiny release version
20
- TINY = 4
20
+ TINY = 0
21
21
  # prelease version ( set this only if it is a prelease)
22
22
  PRE = nil
23
23
 
@@ -18,8 +18,6 @@ module CelluloidPubsub
18
18
 
19
19
  # The hostname on which the webserver runs on by default
20
20
  HOST = '0.0.0.0'
21
- # The port on which the webserver runs on by default
22
- PORT = 1234
23
21
  # The request path that the webserver accepts by default
24
22
  PATH = '/ws'
25
23
  # The name of the default adapter
@@ -46,10 +44,44 @@ module CelluloidPubsub
46
44
  @subscribers = {}
47
45
  @mutex = Mutex.new
48
46
  setup_celluloid_logger
49
- log_debug "CelluloidPubsub::WebServer example starting on #{hostname}:#{port}"
47
+ debug "CelluloidPubsub::WebServer example starting on #{hostname}:#{port}"
50
48
  super(hostname, port, { spy: spy, backlog: backlog }, &method(:on_connection))
51
49
  end
52
50
 
51
+ # the method will return the socket conection opened on the unused port
52
+ #
53
+ #
54
+ # @return [TCPServer] return the socket connection opened on a random port
55
+ #
56
+ # @api public
57
+ def self.open_socket_on_unused_port
58
+ infos = ::Socket::getaddrinfo("localhost", nil, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
59
+ families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
60
+
61
+ return ::TCPServer.open('0.0.0.0', 0) if families.has_key?('AF_INET')
62
+ return ::TCPServer.open('::', 0) if families.has_key?('AF_INET6')
63
+ return ::TCPServer.open(0)
64
+ end
65
+
66
+ # the method get from the socket connection that is already opened the port used.
67
+ # @see #open_socket_on_unused_port
68
+ #
69
+ # @return [Integer] returns the port that can be used to issue new connection
70
+ #
71
+ # @api public
72
+ def self.find_unused_port
73
+ @@unused_port ||= begin
74
+ socket = open_socket_on_unused_port
75
+ port = socket.addr[1]
76
+ socket.close
77
+ port
78
+ end
79
+ end
80
+
81
+ # this method is overriden from the Reel::Server::HTTP in order to set the spy to the celluloid logger
82
+ # before the connection is accepted.
83
+ # @see #handle_connection
84
+ # @api public
53
85
  def run
54
86
  @spy = Celluloid.logger if spy
55
87
  loop { async.handle_connection @server.accept }
@@ -115,7 +147,7 @@ module CelluloidPubsub
115
147
  #
116
148
  # @api public
117
149
  def port
118
- @port = @server_options.fetch('port', CelluloidPubsub::WebServer::PORT)
150
+ @port ||= @server_options.fetch('port', nil) || self.class.find_unused_port
119
151
  end
120
152
 
121
153
  # the method will return the URL path on which will acceept connections
@@ -19,7 +19,7 @@ describe CelluloidPubsub::Reactor do
19
19
  websocket.stubs(:url)
20
20
  websocket.stubs(:close)
21
21
  websocket.stubs(:closed?).returns(false)
22
- server.stubs(:alive?).returns(true)
22
+ server.stubs(:dead?).returns(false)
23
23
  subject.stubs(:inspect).returns(subject)
24
24
  subject.stubs(:run)
25
25
  subject.work(websocket, server)
@@ -7,10 +7,6 @@ describe CelluloidPubsub::WebServer do
7
7
  expect(CelluloidPubsub::WebServer::HOST).to eq('0.0.0.0')
8
8
  end
9
9
 
10
- it 'should have host constant' do
11
- expect(CelluloidPubsub::WebServer::PORT).to eq(1234)
12
- end
13
-
14
10
  it 'should have host constant' do
15
11
  expect(CelluloidPubsub::WebServer::PATH).to eq('/ws')
16
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid