tra 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tra/mailbox.rb +21 -7
  3. data/lib/tra.rb +3 -2
  4. data/test.rb +1 -1
  5. data/tra.gemspec +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd1da5cafab185749f54bea2504134b1938be798
4
- data.tar.gz: 180cbc81a2ed58a413207cd2a76c805351d3e3e2
3
+ metadata.gz: 12350315bcfa8dc01152aa678632723a527d5e80
4
+ data.tar.gz: 6ee3aad4b5f4dd27eb1743d6b15d55d7e489f22d
5
5
  SHA512:
6
- metadata.gz: 476768c1029e5d715004a3339b5c5121409e8e44c45e8f0f65cc85001f4a73bf2db2cd3f2698718187ab611be10b7b2d2d0d92cade11e268d5795cdb3009ee64
7
- data.tar.gz: e7d27d0e95e8419d24fbaf6079b543a538859fa96b23be7f0e9aec0884586eb4843d69ec0b64a23f45b23f6dc3151cf6b9e0da6982004dffea46388451094fe5
6
+ metadata.gz: f9d807432a2f1e5de0f4a84ab4c609eef282cb4d70e0e96a32a6f70c2c78a6133d932624c1437a13cccc394e840f75d569e137fa51c8169a11e832f83d0f1597
7
+ data.tar.gz: 648c210b376d7089aeefec8f0d5d4034f2aa9de7d9fba7d3293188fdc6921a8d25da23f5ac5bd6cf390fa5960f81e670cb385f376f542a2b9c4e9a9aac40711f
data/lib/tra/mailbox.rb CHANGED
@@ -1,16 +1,30 @@
1
1
  module Tra
2
2
  module Mailbox
3
- def self.receive
4
- Dir.mkdir DIRECTORY unless Dir.exist? DIRECTORY
5
- file = FILE[Process.pid]
3
+ class << self
4
+ def receive
5
+ Dir.mkdir DIRECTORY unless Dir.exist? DIRECTORY
6
+ file = FILE[Process.pid]
6
7
 
7
- Thread.new do
8
- Socket.unix_server_loop file do |socket|
9
- QUEUE << (Marshal.load socket.gets)
8
+ Thread.new do
9
+ Socket.unix_server_loop file do |socket|
10
+ QUEUE << (Marshal.load socket.read size_of_message_from socket)
11
+ end
10
12
  end
13
+
14
+ sleep 0.01 until File.exist? file
11
15
  end
12
16
 
13
- sleep 0.01 until File.exist? file
17
+ private
18
+ def size_of_message_from socket
19
+ size = String.new
20
+
21
+ while digit = socket.read(1)
22
+ break if digit == ?:
23
+ size << digit
24
+ end
25
+
26
+ size.to_i
27
+ end
14
28
  end
15
29
  end
16
30
  end
data/lib/tra.rb CHANGED
@@ -7,7 +7,7 @@ require_relative 'tra/fork'
7
7
  module Tra
8
8
  QUEUE = Queue.new
9
9
 
10
- DIRECTORY = "/tmp/tractor"
10
+ DIRECTORY = "/tmp/tra"
11
11
  FILE = -> pid { "#{DIRECTORY}/#{pid}" }
12
12
 
13
13
  class << self
@@ -33,7 +33,8 @@ module Tra
33
33
  def patch_Integer_shamelessly
34
34
  Integer.class_eval do
35
35
  def put message
36
- Socket.unix(FILE[self]).write "#{Marshal.dump message}\n"
36
+ message = Marshal.dump message
37
+ Socket.unix(FILE[self]).write "#{message.size}:#{message}"
37
38
  end
38
39
  end
39
40
  end
data/test.rb CHANGED
@@ -14,4 +14,4 @@ binding.pry
14
14
  p Tra.next
15
15
  =end
16
16
  Tra.take(5).each { |message| p message }
17
- child.put [:my, :message]
17
+ child.put [:my, :message, "with\n newlines\n"]
data/tra.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |g|
2
2
  g.name = 'tra'
3
3
  g.files = `git ls-files`.split($/)
4
- g.version = '0.0.0'
4
+ g.version = '0.0.1'
5
5
  g.summary = 'Erlang-style messaging for Ruby processes'
6
6
  g.authors = ['Anatoly Chernow']
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-29 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: