zchannel 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -12
- data/.yardopts +0 -2
- data/Gemfile +4 -0
- data/README.md +8 -5
- data/lib/zchannel/unix_socket.rb +30 -21
- data/lib/zchannel/version.rb +1 -1
- data/test/setup.rb +2 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ddefd25411898f9e157391b0024f2c20dc481f1
|
4
|
+
data.tar.gz: 00821b76dbee39af1210d7fe6d09b4eee3c4df46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c44b7dd8784fc7313db3136498c1ded8f61c41a5ef2843b63a9ae273e1aa53474f882fc166344131dae445966d0af626e16ff12f1bf46b27f990440654d689
|
7
|
+
data.tar.gz: 835f2f8b041dd696880281c50beca1a5c69478da550e28082fd12b34d7ed61c9b88228c9e3396228d62d9b5afcb1a0171beda458bca537384cf551919b797f1e
|
data/.travis.yml
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
+
script: ruby -S rake
|
2
|
+
|
1
3
|
rvm:
|
2
|
-
-
|
3
|
-
-
|
4
|
-
- 2.0.0
|
5
|
-
- rbx-19mode
|
6
|
-
# - ruby-head
|
4
|
+
- 2.2
|
5
|
+
- ruby-head
|
7
6
|
|
8
7
|
env:
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
12
|
-
|
13
|
-
services:
|
14
|
-
- redis-server
|
8
|
+
- SERIALIZER=YAML
|
9
|
+
- SERIALIZER=Marshal
|
10
|
+
- SERIALIZER=JSON
|
15
11
|
|
16
12
|
notifications:
|
17
|
-
email: true
|
13
|
+
email: true
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/jazzonmymind/zchannel.rb.svg?branch=master)](https://travis-ci.org/jazzonmymind/zchannel.rb)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/jazzonmymind/zchannel.rb/badges/gpa.svg)](https://codeclimate.com/github/jazzonmymind/zchannel.rb)
|
3
|
+
|
1
4
|
__zchannel__
|
2
5
|
|
3
6
|
zchannel is a library that assists with InterProcess Communication, or
|
4
7
|
IPC for short. It provides a high level and easy to use API for sending
|
5
|
-
Ruby objects between processes that are running on the same machine
|
6
|
-
A channel is implemented on top of an
|
7
|
-
|
8
|
-
|
9
|
-
dependencies.
|
8
|
+
Ruby objects between processes that are running on the same machine and
|
9
|
+
who have a parent-child relationship. A channel is implemented on top of an
|
10
|
+
unbound UNIXSocket. Objects are serialized on write and deserialized on
|
11
|
+
read using a serializer of your choice. The examples use the "Marshal"
|
12
|
+
serializer, which is available without any extra dependencies.
|
10
13
|
|
11
14
|
__Examples__
|
12
15
|
|
data/lib/zchannel/unix_socket.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'socket'
|
2
2
|
class ZChannel::UNIXSocket
|
3
|
-
SEP =
|
3
|
+
SEP = "\x00" if respond_to? :private_constant
|
4
4
|
|
5
5
|
#
|
6
6
|
# @param [#dump,#load] serializer
|
7
|
-
#
|
7
|
+
# Any object that implements "dump" and "load" methods.
|
8
8
|
#
|
9
9
|
# @return [ZChannel::UNIXSocket]
|
10
10
|
#
|
@@ -16,20 +16,18 @@ class ZChannel::UNIXSocket
|
|
16
16
|
|
17
17
|
#
|
18
18
|
# @return [Boolean]
|
19
|
-
# Returns true when a channel is closed
|
19
|
+
# Returns true when a channel is closed.
|
20
20
|
#
|
21
21
|
def closed?
|
22
22
|
@reader.closed? and @writer.closed?
|
23
23
|
end
|
24
24
|
|
25
|
-
#
|
26
|
-
# Close the channel
|
27
25
|
#
|
28
26
|
# @raise [IOError]
|
29
|
-
#
|
27
|
+
# Raises IOError when a channel is already closed.
|
30
28
|
#
|
31
29
|
# @return [Boolean]
|
32
|
-
# Returns true
|
30
|
+
# Returns true when a channel is closed successfully.
|
33
31
|
#
|
34
32
|
def close
|
35
33
|
if closed?
|
@@ -41,29 +39,34 @@ class ZChannel::UNIXSocket
|
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
42
|
+
#
|
43
|
+
# Perform a blocking write.
|
44
44
|
#
|
45
45
|
# @raise [IOError]
|
46
46
|
# (see #send!)
|
47
47
|
#
|
48
48
|
# @param [Object] object
|
49
|
-
# An object to
|
49
|
+
# An object to write to a channel.
|
50
50
|
#
|
51
51
|
def send(object)
|
52
52
|
send!(object, nil)
|
53
53
|
end
|
54
|
+
alias_method :write, :send
|
54
55
|
|
55
56
|
#
|
56
|
-
#
|
57
|
-
#
|
57
|
+
# Perform a write with a timeout.
|
58
|
+
#
|
59
|
+
# @param [Object] object
|
60
|
+
# An object to write to a channel.
|
58
61
|
#
|
59
|
-
# @param [Fixnum] timeout
|
60
|
-
#
|
62
|
+
# @param [Float, Fixnum] timeout
|
63
|
+
# The number of seconds to wait before raising an exception.
|
61
64
|
#
|
62
65
|
# @raise [IOError]
|
63
|
-
#
|
66
|
+
# Raises an IOError when a channel is closed.
|
64
67
|
#
|
65
68
|
# @raise [ZChannel::TimeoutError]
|
66
|
-
#
|
69
|
+
# Raises a ZChannel::TimeoutError when a write doesn't finish within the specified timeout.
|
67
70
|
#
|
68
71
|
def send!(object, timeout = 0.1)
|
69
72
|
if @writer.closed?
|
@@ -77,30 +80,32 @@ class ZChannel::UNIXSocket
|
|
77
80
|
raise ZChannel::TimeoutError, "timeout, waited #{timeout} seconds"
|
78
81
|
end
|
79
82
|
end
|
83
|
+
alias_method :write!, :send!
|
80
84
|
|
81
85
|
#
|
82
|
-
# Perform a blocking read
|
86
|
+
# Perform a blocking read.
|
83
87
|
#
|
84
88
|
# @raise
|
85
|
-
# (see ZChannel::UNIXSocket#recv)
|
89
|
+
# (see ZChannel::UNIXSocket#recv!)
|
86
90
|
#
|
87
91
|
# @return [Object]
|
88
92
|
#
|
89
93
|
def recv
|
90
94
|
recv!(nil)
|
91
95
|
end
|
96
|
+
alias_method :read, :recv
|
92
97
|
|
93
98
|
#
|
94
|
-
# Perform a read with a timeout
|
99
|
+
# Perform a read with a timeout.
|
95
100
|
#
|
96
|
-
# @param [Fixnum] timeout
|
97
|
-
#
|
101
|
+
# @param [Float, Fixnum] timeout
|
102
|
+
# The number of seconds to wait before raising an exception.
|
98
103
|
#
|
99
104
|
# @raise [IOError]
|
100
|
-
#
|
105
|
+
# Raises an IOError when a channel is closed.
|
101
106
|
#
|
102
107
|
# @raise [ZChannel::TimeoutError]
|
103
|
-
#
|
108
|
+
# Raises ZChannel::TimeoutError when a read doesn't finish within the specified timeout.
|
104
109
|
#
|
105
110
|
# @return [Object]
|
106
111
|
#
|
@@ -116,9 +121,12 @@ class ZChannel::UNIXSocket
|
|
116
121
|
raise ZChannel::TimeoutError, "timeout, waited #{timeout} seconds"
|
117
122
|
end
|
118
123
|
end
|
124
|
+
alias_method :read!, :recv!
|
119
125
|
|
120
126
|
#
|
121
127
|
# @return [Object]
|
128
|
+
# Reads from a channel until there are no messages left, and
|
129
|
+
# then returns the last read message.
|
122
130
|
#
|
123
131
|
def last_msg
|
124
132
|
@last_msg = recv while readable?
|
@@ -127,6 +135,7 @@ class ZChannel::UNIXSocket
|
|
127
135
|
|
128
136
|
#
|
129
137
|
# @return [Boolean]
|
138
|
+
# Returns true when a channel has messages waiting to be read.
|
130
139
|
#
|
131
140
|
def readable?
|
132
141
|
if closed?
|
data/lib/zchannel/version.rb
CHANGED
data/test/setup.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zchannel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jazzonmymind
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides a high level and easy to use API for sending objects between
|
14
14
|
Ruby processes
|
@@ -57,4 +57,3 @@ specification_version: 4
|
|
57
57
|
summary: Provides a high level and easy to use API for sending objects between Ruby
|
58
58
|
processes
|
59
59
|
test_files: []
|
60
|
-
has_rdoc:
|