rxio 0.13.5 → 0.13.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -8
- data/lib/rxio/io_base.rb +23 -7
- data/lib/rxio/service.rb +0 -9
- data/lib/rxio/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b13f7c2a5d6f073bbc1faca1e077ca3a5586e8
|
4
|
+
data.tar.gz: fb55abf384c23c250df0141443251392e0dd10fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff03cb6cba5758bd1e5709848378dbc50098b516eafa069229cc9fd47d84a8286e4944d24924cb660f352da1223fdf05e678758e9fbccc5fc83affd36d4d777f
|
7
|
+
data.tar.gz: 32dd7a9f0da6a006d156ce040714b7630f86e77b66cc46102c394b51cea3b9fcc6e24f35cc6d665c9616fc3f34534ebbac43cd657d2b29bae926a29d98108815
|
data/README.md
CHANGED
@@ -309,22 +309,25 @@ es.shutdown
|
|
309
309
|
puts 'Client has terminated!'
|
310
310
|
```
|
311
311
|
|
312
|
-
### Dealing with
|
312
|
+
### Dealing with Peer Errors
|
313
313
|
|
314
|
-
Whenever an error occurs as the result of handling a
|
315
|
-
The default implementation of this method simply spits out the error on STDOUT and drops the
|
314
|
+
Whenever an error occurs as the result of handling a peer's message, it should be notified through the *peer_error* method in *RxIO::IOBase* (included in *RxIO::Service*).
|
315
|
+
The default implementation of this method simply spits out the error on STDOUT and drops the peer.
|
316
316
|
It can be overloaded to provide custom functionality such as proper logging or more complex logic.
|
317
317
|
|
318
318
|
```ruby
|
319
|
-
# Default implementation for '
|
320
|
-
def
|
321
|
-
puts "[!] ERROR [#{
|
322
|
-
drop_endpoint
|
319
|
+
# Default implementation for 'peer_error'
|
320
|
+
def peer_error p, e
|
321
|
+
puts "[!] ERROR [#{p[:peer][:addr]}:#{p[:peer][:port]}] - #{e}"
|
322
|
+
drop_endpoint p
|
323
323
|
end
|
324
324
|
```
|
325
325
|
|
326
326
|
Usage:
|
327
327
|
|
328
|
+
While the actual 'peer_error' method can be publicly called on any class that includes the *RxIO::IOBase* Module, it is normally not necessary.
|
329
|
+
In fact, calls to both the *filter_input* & *handle_msg* callback methods (to be implemented in the Service Handler Module) are wrapped within a *begin* / *rescue* block which will call *peer_error* for any exception raised during either parsing or processing of messages.
|
330
|
+
|
328
331
|
```ruby
|
329
332
|
#!/usr/bin/env ruby
|
330
333
|
|
@@ -344,7 +347,10 @@ class EchoService < RxIO::Service
|
|
344
347
|
def self.handle_msg client, msg
|
345
348
|
|
346
349
|
# Everything is an error
|
347
|
-
|
350
|
+
raise 'Invalid Message Structure'
|
351
|
+
|
352
|
+
# Equivalent to:
|
353
|
+
# return client[:serv].peer_error client, msg
|
348
354
|
end
|
349
355
|
end
|
350
356
|
end
|
data/lib/rxio/io_base.rb
CHANGED
@@ -16,11 +16,21 @@ module RxIO
|
|
16
16
|
# @param [String] chunk A chunk of data, as received by the socket
|
17
17
|
def process_input endpoint, chunk
|
18
18
|
|
19
|
-
#
|
20
|
-
|
19
|
+
# Begin
|
20
|
+
begin
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# Pass through Service Handler Module
|
23
|
+
@service_handler.filter_input endpoint, chunk
|
24
|
+
|
25
|
+
# Process Messages
|
26
|
+
@service_handler.handle_msg endpoint, endpoint[:msgs].shift until endpoint[:msgs].empty?
|
27
|
+
|
28
|
+
# Rescue
|
29
|
+
rescue Exception => e
|
30
|
+
|
31
|
+
# Peer Error
|
32
|
+
peer_error endpoint, e
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
# Read Socket
|
@@ -69,14 +79,20 @@ module RxIO
|
|
69
79
|
# @param [Hash] endpoint
|
70
80
|
def drop_endpoint endpoint
|
71
81
|
|
72
|
-
# Mark as Dying
|
73
|
-
endpoint[:dying] = true
|
74
|
-
|
75
82
|
# Notify Service Handler
|
76
83
|
@service_handler.on_drop endpoint if @service_handler.respond_to? :on_drop
|
77
84
|
|
78
85
|
# Drop Endpoint
|
79
86
|
on_drop endpoint
|
80
87
|
end
|
88
|
+
|
89
|
+
# Peer Error
|
90
|
+
# Handles an Error from a Peer
|
91
|
+
# @param [Hash] p Endpoint Hash
|
92
|
+
# @param [String] e Error String
|
93
|
+
def peer_error p, e
|
94
|
+
puts "[!] ERROR [#{p[:peer][:addr]}:#{p[:peer][:port]}] - #{e}"
|
95
|
+
drop_endpoint p
|
96
|
+
end
|
81
97
|
end
|
82
98
|
end
|
data/lib/rxio/service.rb
CHANGED
@@ -86,15 +86,6 @@ module RxIO
|
|
86
86
|
@stop = true
|
87
87
|
end
|
88
88
|
|
89
|
-
# Client Error
|
90
|
-
# Handles an Error from a Client
|
91
|
-
# @param [Hash] c Client Hash
|
92
|
-
# @param [String] e Error String
|
93
|
-
def client_error c, e
|
94
|
-
puts "[!] ERROR [#{c[:peer][:addr]}:#{c[:peer][:port]}] - #{e}"
|
95
|
-
drop_endpoint c
|
96
|
-
end
|
97
|
-
|
98
89
|
# Privates
|
99
90
|
private
|
100
91
|
|
data/lib/rxio/version.rb
CHANGED