rxio 0.13.6 → 0.13.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rxio/client.rb +13 -13
- data/lib/rxio/handler_base.rb +3 -3
- data/lib/rxio/io_base.rb +13 -10
- data/lib/rxio/io_filters/bin_delim.rb +4 -4
- data/lib/rxio/io_filters/msg_size.rb +3 -3
- data/lib/rxio/io_filters.rb +1 -1
- data/lib/rxio/service.rb +12 -12
- data/lib/rxio/version.rb +1 -1
- data/lib/rxio.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba978c3b4a32fa7123729faa8a8ef9b9a349f3d
|
4
|
+
data.tar.gz: ae1ba6d9308798d554e1420a611ba84cebdf0f69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4749f998fc6afc4b4919c2944edd1bdc8d105bd2ad4fef25a70fd6e7c603bc56da7cab752a40d3f94a857399c2926bb82b0eaced70f9a5c613ff0f504556f4
|
7
|
+
data.tar.gz: 91f54ed3418905a5704beda6ecdb900b64b84408dcfcd0b9f741003e2fdd85475b54eabe7d2c85ebdaa2f3981b54e2d9bed07fb23ac6a60afd64b9e72c064fbf
|
data/lib/rxio/client.rb
CHANGED
@@ -27,7 +27,7 @@ module RxIO
|
|
27
27
|
# Select Timeout (seconds)
|
28
28
|
SELECT_TIMEOUT = 0.1
|
29
29
|
|
30
|
-
# Construct
|
30
|
+
# Construct:
|
31
31
|
# Builds a *Client* around a given _service_handler_ module, set to connect to _addr_ on _port_.
|
32
32
|
# @param [String] addr Address to which the client should connect
|
33
33
|
# @param [Fixnum] port Port on which the client should connect
|
@@ -54,8 +54,8 @@ module RxIO
|
|
54
54
|
}
|
55
55
|
end
|
56
56
|
|
57
|
-
# Send Message
|
58
|
-
# Enqueues a Message to be sent to the server
|
57
|
+
# Send Message:
|
58
|
+
# Enqueues a Message to be sent to the server.
|
59
59
|
# @param [String] msg
|
60
60
|
def send_msg msg
|
61
61
|
|
@@ -66,7 +66,7 @@ module RxIO
|
|
66
66
|
@service_handler.send_msg @client, msg
|
67
67
|
end
|
68
68
|
|
69
|
-
# Run
|
69
|
+
# Run:
|
70
70
|
# Executes the main client loop, taking care of I/O scheduling and message handling.
|
71
71
|
def run
|
72
72
|
|
@@ -85,9 +85,9 @@ module RxIO
|
|
85
85
|
@sock = nil
|
86
86
|
end
|
87
87
|
|
88
|
-
# Stop
|
88
|
+
# Stop:
|
89
89
|
# Requests the client loop to stop executing.
|
90
|
-
# The _run_ method should return shortly after calling _stop_
|
90
|
+
# The _run_ method should return shortly after calling _stop_.
|
91
91
|
def stop
|
92
92
|
@stop = true
|
93
93
|
end
|
@@ -95,7 +95,7 @@ module RxIO
|
|
95
95
|
# Privates
|
96
96
|
private
|
97
97
|
|
98
|
-
# Update
|
98
|
+
# Update:
|
99
99
|
# Serves as the client loop main method, performing I/O scheduling and message handling.
|
100
100
|
def update
|
101
101
|
|
@@ -110,8 +110,8 @@ module RxIO
|
|
110
110
|
wr.each { |s| write_sock s } if wr
|
111
111
|
end
|
112
112
|
|
113
|
-
# Ensure Socket is available
|
114
|
-
# Re-creates the socket in the event of failure
|
113
|
+
# Ensure Socket is available:
|
114
|
+
# Re-creates the socket in the event of failure.
|
115
115
|
def ensure_sock
|
116
116
|
|
117
117
|
# Check
|
@@ -146,16 +146,16 @@ module RxIO
|
|
146
146
|
@sock
|
147
147
|
end
|
148
148
|
|
149
|
-
# Get Endpoint for Socket - Callback for IOBase
|
150
|
-
# Simply returns the Client Hash
|
149
|
+
# Get Endpoint for Socket - Callback for IOBase:
|
150
|
+
# Simply returns the Client Hash.
|
151
151
|
# @param [TCPSocket] _s
|
152
152
|
# @return [Hash] The Client Hash
|
153
153
|
def get_endpoint_for_sock _s
|
154
154
|
@client
|
155
155
|
end
|
156
156
|
|
157
|
-
# On Drop - Callback for IOBase
|
158
|
-
# Kills the socket
|
157
|
+
# On Drop - Callback for IOBase:
|
158
|
+
# Kills the socket.
|
159
159
|
# @param [Hash] _e
|
160
160
|
def on_drop _e
|
161
161
|
@sock.close rescue nil
|
data/lib/rxio/handler_base.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# RxIO Module
|
5
5
|
module RxIO
|
6
6
|
|
7
|
-
# Handler Base Module
|
7
|
+
# Handler Base Module:
|
8
8
|
# Provides common abstractions to Service Handler implementations.
|
9
9
|
module HandlerBase
|
10
10
|
|
11
|
-
# Write
|
11
|
+
# Write:
|
12
12
|
# Writes one or more chunks of data to the endpoint's output buffer (:obuf).
|
13
13
|
# @param [Hash] endpoint
|
14
14
|
# @param [String] data One or more chunks of data to be written to the ouput buffer
|
@@ -18,7 +18,7 @@ module RxIO
|
|
18
18
|
data.each { |c| endpoint[:lock].synchronize { endpoint[:obuf] << c } }
|
19
19
|
end
|
20
20
|
|
21
|
-
# Buffer Input Chunk
|
21
|
+
# Buffer Input Chunk:
|
22
22
|
# Writes a chunk of data to the endpoint's input buffer (:ibuf).
|
23
23
|
# @param [Hash] endpoint
|
24
24
|
# @param [String] chunk
|
data/lib/rxio/io_base.rb
CHANGED
@@ -10,8 +10,8 @@ module RxIO
|
|
10
10
|
# Chunk Size
|
11
11
|
CHUNK_SIZE = 1024
|
12
12
|
|
13
|
-
# Process Input
|
14
|
-
# Processes Input for an Endpoint, in the form of a data chunk
|
13
|
+
# Process Input:
|
14
|
+
# Processes Input for an Endpoint, in the form of a data chunk.
|
15
15
|
# @param [Hash] endpoint
|
16
16
|
# @param [String] chunk A chunk of data, as received by the socket
|
17
17
|
def process_input endpoint, chunk
|
@@ -25,7 +25,10 @@ module RxIO
|
|
25
25
|
# Process Messages
|
26
26
|
@service_handler.handle_msg endpoint, endpoint[:msgs].shift until endpoint[:msgs].empty?
|
27
27
|
|
28
|
-
|
28
|
+
# Sub-Process Input
|
29
|
+
@service_handler.subprocess_input endpoint if @service_handler.respond_to? :subprocess_input
|
30
|
+
|
31
|
+
# Rescue
|
29
32
|
rescue Exception => e
|
30
33
|
|
31
34
|
# Peer Error
|
@@ -33,7 +36,7 @@ module RxIO
|
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
|
-
# Read Socket
|
39
|
+
# Read Socket:
|
37
40
|
# Attempts to read as many bytes as possible (up to CHUNK_SIZE) from a given socket _s_, passing the data chunks to _process_input_.
|
38
41
|
# @param [TCPSocket] s
|
39
42
|
def read_sock s
|
@@ -54,7 +57,7 @@ module RxIO
|
|
54
57
|
process_input e, chunk
|
55
58
|
end
|
56
59
|
|
57
|
-
# Write Socket
|
60
|
+
# Write Socket:
|
58
61
|
# Attempts to write as many bytes as possible to a given socket _s_ from the associated client's output buffer.
|
59
62
|
# @param [TCPSocket] s
|
60
63
|
def write_sock s
|
@@ -74,8 +77,8 @@ module RxIO
|
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
# Drop Endpoint
|
78
|
-
# Notifies the Service Handler and Parent Implementation (in that order) of a dropped endpoint
|
80
|
+
# Drop Endpoint:
|
81
|
+
# Notifies the Service Handler and Parent Implementation (in that order) of a dropped endpoint.
|
79
82
|
# @param [Hash] endpoint
|
80
83
|
def drop_endpoint endpoint
|
81
84
|
|
@@ -86,12 +89,12 @@ module RxIO
|
|
86
89
|
on_drop endpoint
|
87
90
|
end
|
88
91
|
|
89
|
-
# Peer Error
|
90
|
-
# Handles an Error from a Peer
|
92
|
+
# Peer Error:
|
93
|
+
# Handles an Error from a Peer.
|
91
94
|
# @param [Hash] p Endpoint Hash
|
92
95
|
# @param [String] e Error String
|
93
96
|
def peer_error p, e
|
94
|
-
puts "[!] ERROR [#{p[:peer][:addr]}:#{p[:peer][:port]}] - #{e}"
|
97
|
+
puts "[!] ERROR [#{p[:peer][:addr]}:#{p[:peer][:port]}] - #{e} - #{e.backtrace.collect { |b| " * #{b}" }.join "\n"}"
|
95
98
|
drop_endpoint p
|
96
99
|
end
|
97
100
|
end
|
@@ -10,7 +10,7 @@ module RxIO
|
|
10
10
|
# I/O Filters Module
|
11
11
|
module IOFilters
|
12
12
|
|
13
|
-
# Binary-Delimiter I/O Filter
|
13
|
+
# Binary-Delimiter I/O Filter:
|
14
14
|
# Splits messages according to a given fixed *binary delimiter*, which can be any number of bytes, defined through the _msg_delim_ method.
|
15
15
|
module BinDelim
|
16
16
|
|
@@ -20,14 +20,14 @@ module RxIO
|
|
20
20
|
base.extend RxIO::HandlerBase
|
21
21
|
end
|
22
22
|
|
23
|
-
# Set Message Delimiter
|
23
|
+
# Set Message Delimiter:
|
24
24
|
# Used to define the binary string used as message delimiter for this protocol.
|
25
25
|
# @param [String] v The message delimiter string
|
26
26
|
def msg_delim v
|
27
27
|
@msg_delim = v
|
28
28
|
end
|
29
29
|
|
30
|
-
# Filter Input
|
30
|
+
# Filter Input:
|
31
31
|
# Buffers data chunks sent by the endpoint and extracts messages from them, according to the delimiter defined through _msg_delim_.
|
32
32
|
# @param [Hash] endpoint
|
33
33
|
# @param [String] chunk
|
@@ -59,7 +59,7 @@ module RxIO
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
# Send Message
|
62
|
+
# Send Message:
|
63
63
|
# Buffers a message to be sent to the endpoint, after wrapping it according to the delimiter defined through _msg_delim_.
|
64
64
|
# @param [Hash] endpoint
|
65
65
|
# @param [String] msg
|
@@ -13,7 +13,7 @@ module RxIO
|
|
13
13
|
# I/O Filters Module
|
14
14
|
module IOFilters
|
15
15
|
|
16
|
-
# Message-Size I/O Filter
|
16
|
+
# Message-Size I/O Filter:
|
17
17
|
# Splits messages according to a _4-byte unsigned big-endian integer_ *size* field, which prefixes every message and indicates its length in bytes.
|
18
18
|
module MsgSize
|
19
19
|
|
@@ -23,7 +23,7 @@ module RxIO
|
|
23
23
|
base.extend RxIO::HandlerBase
|
24
24
|
end
|
25
25
|
|
26
|
-
# Filter Input
|
26
|
+
# Filter Input:
|
27
27
|
# Buffers data chunks sent by the endpoint and extracts messages from them, according to the *size* field present at the beginning of each message.
|
28
28
|
# @param [Hash] endpoint
|
29
29
|
# @param [String] chunk
|
@@ -52,7 +52,7 @@ module RxIO
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
# Send Message
|
55
|
+
# Send Message:
|
56
56
|
# Buffers a message to be sent to the endpoint, after prefixing it with a _size_ field.
|
57
57
|
# @param [Hash] endpoint
|
58
58
|
# @param [String] msg
|
data/lib/rxio/io_filters.rb
CHANGED
data/lib/rxio/service.rb
CHANGED
@@ -24,7 +24,7 @@ module RxIO
|
|
24
24
|
# Select Timeout (seconds)
|
25
25
|
SELECT_TIMEOUT = 0.1
|
26
26
|
|
27
|
-
# Construct
|
27
|
+
# Construct:
|
28
28
|
# Builds a *Service* around a given _service_handler_ module, set to listen for incoming connections @ _addr_ on _port_.
|
29
29
|
# @param [String] addr Address on which the service should listen
|
30
30
|
# @param [Fixnum] port Port on which the service should listen
|
@@ -48,9 +48,9 @@ module RxIO
|
|
48
48
|
@cmap = {}
|
49
49
|
end
|
50
50
|
|
51
|
-
# Run
|
51
|
+
# Run:
|
52
52
|
# Executes the main service loop, taking care of I/O scheduling, client management and message handling.
|
53
|
-
#
|
53
|
+
# This method blocks until the service loop terminates.
|
54
54
|
def run
|
55
55
|
|
56
56
|
# Update Loop
|
@@ -79,9 +79,9 @@ module RxIO
|
|
79
79
|
@serv = nil
|
80
80
|
end
|
81
81
|
|
82
|
-
# Stop
|
82
|
+
# Stop:
|
83
83
|
# Requests the service loop to stop executing.
|
84
|
-
# The _run_ method should return shortly after calling _stop_
|
84
|
+
# The _run_ method should return shortly after calling _stop_.
|
85
85
|
def stop
|
86
86
|
@stop = true
|
87
87
|
end
|
@@ -89,7 +89,7 @@ module RxIO
|
|
89
89
|
# Privates
|
90
90
|
private
|
91
91
|
|
92
|
-
# Update
|
92
|
+
# Update:
|
93
93
|
# Serves as the service loop main method, performing I/O scheduling, client management and message handling.
|
94
94
|
def update
|
95
95
|
|
@@ -104,7 +104,7 @@ module RxIO
|
|
104
104
|
wr.each { |s| write_sock s } if wr
|
105
105
|
end
|
106
106
|
|
107
|
-
# Register Client
|
107
|
+
# Register Client:
|
108
108
|
# Creates a new Client around a given socket _s_ and registers it.
|
109
109
|
# Also, notifies the Handler Module if the _on_join_ method is available.
|
110
110
|
# @param [TCPSocket] s The new client's network socket
|
@@ -145,7 +145,7 @@ module RxIO
|
|
145
145
|
@service_handler.on_join c if @service_handler.respond_to? :on_join
|
146
146
|
end
|
147
147
|
|
148
|
-
# Accept Socket
|
148
|
+
# Accept Socket:
|
149
149
|
# Tries to accept any queued connection request in a non-blocking manner.
|
150
150
|
# Registers a new Client through _add_client_ around the newly-accepted socket if present.
|
151
151
|
# @param [TCPServer] s The service's listening socket
|
@@ -158,16 +158,16 @@ module RxIO
|
|
158
158
|
add_client ns if ns
|
159
159
|
end
|
160
160
|
|
161
|
-
# Get Endpoint for Socket
|
162
|
-
# Finds the Client associated with a given Socket
|
161
|
+
# Get Endpoint for Socket:
|
162
|
+
# Callback for IOBase - Finds the Client associated with a given Socket.
|
163
163
|
# @param [TCPSocket] s Any socket
|
164
164
|
# @return [Hash] The Endpoint associated with Socket _s_, or nil
|
165
165
|
def get_endpoint_for_sock s
|
166
166
|
@cmap[s]
|
167
167
|
end
|
168
168
|
|
169
|
-
# On Drop
|
170
|
-
# Unregisters a Client and closes the associated socket.
|
169
|
+
# On Drop:
|
170
|
+
# Callback for IOBase - Unregisters a Client and closes the associated socket.
|
171
171
|
# @param [Hash] c Client Hash
|
172
172
|
def on_drop c
|
173
173
|
|
data/lib/rxio/version.rb
CHANGED
data/lib/rxio.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rxio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eresse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|