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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2483582cc33b26a5a390939ea4982d3c65d2875
4
- data.tar.gz: f8ed5185e48b2f1bd2a83b5e11cb7b7c5be65b36
3
+ metadata.gz: b1b13f7c2a5d6f073bbc1faca1e077ca3a5586e8
4
+ data.tar.gz: fb55abf384c23c250df0141443251392e0dd10fc
5
5
  SHA512:
6
- metadata.gz: f7bf6ab91a394e2f5b89266e9f991c558aff97dd693cb6dd62cee7b63e4f374691e366c124fdf9d5d7f23076c5181db4caa1afd1bb03de250c1608b2edb09f90
7
- data.tar.gz: 30f9be8aeb50ec8c440b89c1c684402671038ddf2bdab4787eff5ae186c73f9fc88faa12e64fa472f3cf9313d2137ac0e12ff2ed070a5f10e4f747482976dc99
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 Client Errors
312
+ ### Dealing with Peer Errors
313
313
 
314
- Whenever an error occurs as the result of handling a client's message should can be logged through the *client_error* method in *RxIO::Service*.
315
- The default implementation of this method simply spits out the error on STDOUT and drops the client.
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 'client_error'
320
- def client_error c, e
321
- puts "[!] ERROR [#{c[:peer][:addr]}:#{c[:peer][:port]}] - #{e}"
322
- drop_endpoint c
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
- client[:serv].on_error client, 'Invalid Message Structure'
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
- # Pass through Service Handler Module
20
- @service_handler.filter_input endpoint, chunk
19
+ # Begin
20
+ begin
21
21
 
22
- # Process Messages
23
- @service_handler.handle_msg endpoint, endpoint[:msgs].shift until endpoint[:msgs].empty? || endpoint[:dying]
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
@@ -5,5 +5,5 @@
5
5
  module RxIO
6
6
 
7
7
  # Version
8
- VERSION = '0.13.5'
8
+ VERSION = '0.13.6'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rxio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eresse