vagrant-listen-server 0.0.4 → 0.0.5

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: 54a4ce449ded50fcc6e74eee8185c87f505f52c6
4
- data.tar.gz: ccdb1dc74ba61cf0b73020934b795988a936ced6
3
+ metadata.gz: a30b9bb31559cff8314063a36ebbe2b42f041504
4
+ data.tar.gz: f19e8fe12f1e3700841cb95a4caf7ecbfe0334cc
5
5
  SHA512:
6
- metadata.gz: d34b120570d800c0ef54f7ff55dafcf55321e83ab16ab991a36d6e8b0e54aeb7f6724f0e7dd6109684d065055ccb8ac8958fa3961d92395005f0fe72e13bd34d
7
- data.tar.gz: d82c5bee25552a3c5f5d7285a035966c47bc41bbd3a02d767f35735842e1f18545369e7f78a7bf3df9bfead96d990ab3105e98f075d21d96652692380c25f0da
6
+ metadata.gz: c1b0dda84cc0a2a0951f4f3b6810bdf8dc7ead5d5ab2b1c55939190c41a710198757d63e14550ebae86e612e640974c390d3ee8c0bb61719a2f7a5298f54ba86
7
+ data.tar.gz: 0c19dc5641435505ebfae14329a5dc0d30ebf20f8dd0e47b4e8edc82aa72b750f0af16a271af4cfa8b8bf2c2689db81b89126927aa42a24ccb96ea09b9e5eb77
data/README.md CHANGED
@@ -32,6 +32,10 @@ You can also write a simple server that touches all files on the guest, however
32
32
  you'll have to be aware of loops created if filesystem notifications are passed
33
33
  back from the guest to the host.
34
34
 
35
+ See the [examples](/examples) section for some implementations. Currently there
36
+ is solely my node based client, but if you're using this in any other
37
+ languages, please add your client and submit a pull request!
38
+
35
39
 
36
40
  ## Usage
37
41
 
@@ -0,0 +1,48 @@
1
+ var net = require('net');
2
+
3
+
4
+ // Assuming the existence of some `build` method that returns a promise.
5
+ var sequence = build();
6
+
7
+
8
+ // gathers rapid changes as one build
9
+ var timeout = null;
10
+ var scheduleBuild = function() {
11
+ if (timeout) { return; }
12
+
13
+ // we want the timeout to start now before we wait for the current build
14
+ var timeoutPromise = new Promise(function(resolve) {
15
+ timeout = setTimeout(resolve, 100);
16
+ });
17
+
18
+ var timeoutThenBuild = function() {
19
+ timeoutPromise.then(function() {
20
+ timeout = null
21
+ return build();
22
+ });
23
+ };
24
+
25
+ // we want the current promise to be waiting for the current build
26
+ // regardless if it fails or not.
27
+ sequence = sequence.then(timeoutThenBuild, timeoutThenBuild);
28
+ };
29
+
30
+
31
+ var port = 4000;
32
+ var host = '172.16.172.1';
33
+ var client = new net.Socket();
34
+
35
+ client.connect(port, host, function() {
36
+ console.log('Connected to listen server: ', host, port);
37
+ });
38
+
39
+ client.on('data', function(data) {
40
+ // message is [modified, added, removed]
41
+ console.log('Data received', data)
42
+ var message = JSON.parse(data.toString().trim())
43
+ scheduleBuild();
44
+ });
45
+
46
+ client.on('close', function() {
47
+ console.log('Connection closed');
48
+ });
@@ -1,5 +1,6 @@
1
- require 'celluloid'
2
1
  require 'listen'
2
+ require 'socket'
3
+ require 'json'
3
4
 
4
5
  # No ActiveSupport in vagrant
5
6
  def array_wrap object
@@ -28,9 +29,8 @@ module VagrantPlugins
28
29
 
29
30
  config = @machine.config.listen_server
30
31
  folders = array_wrap config.folders
31
- host = "#{config.ip}:#{config.port}"
32
32
 
33
- @ui.info "Starting listen server - #{host}"
33
+ @ui.info "Starting listen server - #{config.ip}:#{config.port}"
34
34
 
35
35
  # Check whether the daemon is already running.
36
36
  if File.exists? config.pid_file
@@ -52,18 +52,51 @@ module VagrantPlugins
52
52
  # machine to test it out on...
53
53
  pid = fork do
54
54
  $0 = "vagrant-listen-server - #{@machine.name}"
55
- listener = Listen.to *folders, forward_to: host do |modified, added, removed|
56
- File.open('/tmp/listen.txt', 'a+') do |f|
57
- f.puts 'listen fired', modified, added, removed
55
+
56
+ clients = []
57
+ server = TCPServer.new config.ip, config.port
58
+
59
+ callback = Proc.new do |modified, added, removed|
60
+ bad_clients = []
61
+ # @ui.info "Listen fired - #{clients.count} clients.\n #{modified}\n #{added}\n #{removed}"
62
+ clients.each do |client|
63
+ begin
64
+ client.puts [modified, added, removed].to_json
65
+ rescue Errno::EPIPE
66
+ @ui.info "Connection broke! #{client}"
67
+ # Don't want to change the list of threads as we iterate.
68
+ bad_clients.push client
69
+ end
58
70
  end
59
- end
60
71
 
61
- begin
62
- listener.start
63
- rescue Errno::EADDRNOTAVAIL
64
- @ui.info "Can't start server - Port in use"
65
- exit
72
+ bad_clients.each do |client|
73
+ clients.delete client
74
+ end
66
75
  end
76
+ listener = Listen.to(*folders, &callback)
77
+ listener.start
78
+
79
+ # server.accept blocks - we need it in its own thread so we can
80
+ # continue to have listener callbacks fired, and so we can sleep
81
+ # and catch any interrupts from vagrant.
82
+ Thread.new do
83
+ loop do
84
+ Thread.fork(server.accept) do |client|
85
+ @ui.info "New connection - #{client}"
86
+ clients.push client
87
+ end
88
+ end
89
+ end
90
+
91
+ # TODO: this error won't happen on the listen anymore - it will
92
+ # happen somewhere on the tcp call. Not sure where.
93
+ #
94
+ # begin
95
+ # listener.start
96
+ # rescue Errno::EADDRNOTAVAIL
97
+ # @ui.info "Can't start server - Port in use"
98
+ # exit
99
+ # end
67
100
 
68
101
  # Uhh... this needs work. Vagrant steals the interrupt from us and
69
102
  # there's no way to get it back
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ListenServer
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -17,9 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'celluloid', '~> 0.16'
21
- spec.add_dependency 'celluloid-io', '~> 0.16', '>= 0.16.2'
22
-
23
20
  spec.add_dependency 'rb-inotify', '~> 0.9', '>= 0.9.5'
24
21
  spec.add_dependency 'rb-fsevent', '~> 0.9', '>= 0.9.4'
25
22
  spec.add_dependency 'rb-kqueue', '~> 0.2', '>= 0.2.3'
metadata CHANGED
@@ -1,49 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-listen-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kelso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-11 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: celluloid
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.16'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.16'
27
- - !ruby/object:Gem::Dependency
28
- name: celluloid-io
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.16'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.16.2
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '0.16'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.16.2
47
13
  - !ruby/object:Gem::Dependency
48
14
  name: rb-inotify
49
15
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +110,7 @@ files:
144
110
  - LICENSE.txt
145
111
  - README.md
146
112
  - Rakefile
113
+ - examples/node-client.js
147
114
  - lib/vagrant-listen-server.rb
148
115
  - lib/vagrant-listen-server/action.rb
149
116
  - lib/vagrant-listen-server/config.rb