raktr 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: 2aa060f18df13540e73b42a5e9c68bdf86eaf03ae21104da0e827e57252dffe3
4
- data.tar.gz: 5f1dd3fa7626e764f5212424c8e25b26a16bb52d4d00a2d2e6e4e5684575123a
3
+ metadata.gz: 78b82e1e277f9547fdfc576009b4b5883df5711ba8cca50a369651f758407aff
4
+ data.tar.gz: 1f594aa25c1872d359de5f7ef1a5e42dcad7699ff5ab54594ab099a3d2fa4315
5
5
  SHA512:
6
- metadata.gz: 8889f36f41d78a38dbd5afb95af6f4c2836e2056bb00451dabb10141c19d34c1ce02a7809c54e3c807713ab0b3bb94e6d969eb423878ab2c8514db703c868f85
7
- data.tar.gz: fa3426f952f1980e9916aeaa1af050da734fec2c8de94a8e352c5223271e4309f66abd9fba46399d5470394ad9b4d65801620c4b060e9b4db1c0775d23a8859e
6
+ metadata.gz: b0f1c2ec3508f4fa3c7bc841c553e5cc220208a3f7ea922802681742d33fbcb930a329eec352198f42f7910e90b679e663d08a1be19e5a91afdeb75b7cca57ed
7
+ data.tar.gz: 70eea04282a7c7ddf99d7f3df0e1e170e4eafaecb165ae02355aa1af899df089577aee4473b36a02358dd90008d2dded1772d3f7853d50dfc8ab62c7cc74a025
data/CHANGELOG.md CHANGED
@@ -1 +1,10 @@
1
1
  # ChangeLog
2
+
3
+ # 0.0.3
4
+
5
+ * `#connect`, `#listen`: Re-raise exceptions.
6
+
7
+
8
+ # 0.0.2
9
+
10
+ * Reduced object allocations.
data/README.md CHANGED
@@ -1,34 +1,5 @@
1
1
  # Raktr
2
2
 
3
- <table>
4
- <tr>
5
- <th>Version</th>
6
- <td>0.0.1</td>
7
- </tr>
8
- <tr>
9
- <th>Github page</th>
10
- <td><a href="http://github.com/qadron/raktr">http://github.com/qadron/raktr</a></td>
11
- <tr/>
12
- <tr>
13
- <th>Code Documentation</th>
14
- <td><a href="http://rubydoc.info/github/qadron/raktr/">http://rubydoc.info/github/qadron/raktr/</a></td>
15
- </tr>
16
- <tr>
17
- <th>Author</th>
18
- <td><a href="http://twitter.com/Zap0tek">Tasos Laskos</a></td>
19
- </tr>
20
- <tr>
21
- <th>Copyright</th>
22
- <td>2022 <a href="https://ecsypno.com">Ecsypno</a></td>
23
- </tr>
24
- <tr>
25
- <th>License</th>
26
- <td><a href="file.LICENSE.html">3-clause BSD</a></td>
27
- </tr>
28
- </table>
29
-
30
- ## Synopsis
31
-
32
3
  Raktr is a simple, lightweight, pure-Ruby implementation of the
33
4
  [Reactor](http://en.wikipedia.org/wiki/Reactor_pattern) pattern, mainly focused
34
5
  on network connections -- and less so on generic tasks.
@@ -77,18 +77,16 @@ module TLS
77
77
  def _connect
78
78
  return if @ssl_connected
79
79
 
80
- Error.translate do
81
- @plaintext_connected ||= super
82
- return if !@plaintext_connected
80
+ @plaintext_connected ||= super
81
+ return if !@plaintext_connected
83
82
 
84
- # Mark the connection as not connected due to the pending SSL handshake.
85
- @connected = false
83
+ # Mark the connection as not connected due to the pending SSL handshake.
84
+ @connected = false
86
85
 
87
- @socket.connect_nonblock
88
- @ssl_connected = @connected = true
89
- end
86
+ @socket.connect_nonblock
87
+ @ssl_connected = @connected = true
90
88
  rescue IO::WaitReadable, IO::WaitWritable, Errno::EINPROGRESS
91
- rescue Error => e
89
+ rescue => e
92
90
  close e
93
91
  end
94
92
 
@@ -118,11 +116,9 @@ module TLS
118
116
  private
119
117
 
120
118
  def ssl_accept
121
- Error.translate do
122
- @accepted = !!@socket.accept_nonblock
123
- end
119
+ @accepted = !!@socket.accept_nonblock
124
120
  rescue IO::WaitReadable, IO::WaitWritable
125
- rescue Error => e
121
+ rescue => e
126
122
  close e
127
123
  false
128
124
  end
@@ -142,19 +138,17 @@ module TLS
142
138
  #
143
139
  # @private
144
140
  def socket_accept
145
- Error.translate do
146
- socket = to_io.accept_nonblock
147
-
148
- ssl_socket = OpenSSL::SSL::SSLSocket.new(
149
- socket,
150
- @ssl_context
151
- )
152
- ssl_socket.sync_close = true
153
- ssl.accept if @start_immediately
154
- ssl_socket
155
- end
141
+ socket = to_io.accept_nonblock
142
+
143
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(
144
+ socket,
145
+ @ssl_context
146
+ )
147
+ ssl_socket.sync_close = true
148
+ ssl.accept if @start_immediately
149
+ ssl_socket
156
150
  rescue IO::WaitReadable, IO::WaitWritable
157
- rescue Error => e
151
+ rescue => e
158
152
  close e
159
153
  end
160
154
 
@@ -6,7 +6,6 @@
6
6
 
7
7
  =end
8
8
 
9
- require_relative 'connection/error'
10
9
  require_relative 'connection/callbacks'
11
10
  require_relative 'connection/peer_info'
12
11
  require_relative 'connection/tls'
@@ -229,9 +228,7 @@ class Connection
229
228
  return true if unix? || connected?
230
229
 
231
230
  begin
232
- Error.translate do
233
- socket.connect_nonblock( Socket.sockaddr_in( @port, @host ) )
234
- end
231
+ socket.connect_nonblock( Socket.sockaddr_in( @port, @host ) )
235
232
  # Already connected. :)
236
233
  rescue Errno::EISCONN, Errno::EALREADY
237
234
  end
@@ -241,7 +238,7 @@ class Connection
241
238
 
242
239
  true
243
240
  rescue IO::WaitReadable, IO::WaitWritable, Errno::EINPROGRESS
244
- rescue Error => e
241
+ rescue => e
245
242
  close e
246
243
  end
247
244
 
@@ -256,13 +253,11 @@ class Connection
256
253
  return _connect if !listener? && !connected?
257
254
  return accept if listener?
258
255
 
259
- Error.translate do
260
- on_read @socket.read_nonblock( BLOCK_SIZE )
261
- end
256
+ on_read @socket.read_nonblock( BLOCK_SIZE )
262
257
 
263
258
  # Not ready to read or write yet, we'll catch it on future Reactor ticks.
264
259
  rescue IO::WaitReadable, IO::WaitWritable
265
- rescue Error => e
260
+ rescue => e
266
261
  close e
267
262
  end
268
263
 
@@ -282,22 +277,21 @@ class Connection
282
277
  def _write
283
278
  return _connect if !connected?
284
279
 
285
- chunk = write_buffer.byteslice( 0, BLOCK_SIZE )
280
+ write_buffer.force_encoding( Encoding::BINARY )
281
+ chunk = write_buffer[0, BLOCK_SIZE]
286
282
  total_written = 0
287
283
 
288
284
  begin
289
- Error.translate do
290
- # Send out the chunk, **all** of it, or at least try to.
291
- loop do
292
- total_written += written = @socket.write_nonblock( chunk )
293
- @write_buffer = @write_buffer.byteslice( written..-1 )
294
-
295
- # Call #on_write every time any of the buffer is consumed.
296
- on_write
297
-
298
- break if written == chunk.bytesize
299
- chunk = chunk.byteslice( written..-1 )
300
- end
285
+ # Send out the chunk, **all** of it, or at least try to.
286
+ loop do
287
+ total_written += written = @socket.write_nonblock( chunk )
288
+ write_buffer[0, written] = ''
289
+
290
+ # Call #on_write every time any of the buffer is consumed.
291
+ on_write
292
+
293
+ break if written == chunk.size
294
+ chunk[0, written] = ''
301
295
  end
302
296
 
303
297
  # Not ready to read or write yet, we'll catch it on future Reactor ticks.
@@ -310,7 +304,7 @@ class Connection
310
304
  end
311
305
 
312
306
  total_written
313
- rescue Error => e
307
+ rescue => e
314
308
  close e
315
309
  end
316
310
 
data/lib/raktr/version.rb CHANGED
@@ -8,6 +8,6 @@
8
8
 
9
9
  class Raktr
10
10
 
11
- VERSION = '0.0.1'
11
+ VERSION = '0.0.3'
12
12
 
13
13
  end
data/lib/raktr.rb CHANGED
@@ -195,15 +195,14 @@ class Raktr
195
195
  block.call connection if block_given?
196
196
 
197
197
  begin
198
- Connection::Error.translate do
199
- socket = options[:unix_socket] ?
200
- connect_unix( options[:unix_socket] ) : connect_tcp
198
+ socket = options[:unix_socket] ?
199
+ connect_unix( options[:unix_socket] ) : connect_tcp
201
200
 
202
- connection.configure options.merge( socket: socket, role: :client )
203
- attach connection
204
- end
205
- rescue Connection::Error => e
201
+ connection.configure options.merge( socket: socket, role: :client )
202
+ attach connection
203
+ rescue => e
206
204
  connection.close e
205
+ raise
207
206
  end
208
207
 
209
208
  connection
@@ -258,16 +257,15 @@ class Raktr
258
257
  server = server_handler.call
259
258
 
260
259
  begin
261
- Connection::Error.translate do
262
- socket = options[:unix_socket] ?
263
- listen_unix( options[:unix_socket] ) :
264
- listen_tcp( options[:host], options[:port] )
260
+ socket = options[:unix_socket] ?
261
+ listen_unix( options[:unix_socket] ) :
262
+ listen_tcp( options[:host], options[:port] )
265
263
 
266
- server.configure options.merge( socket: socket, role: :server, server_handler: server_handler )
267
- attach server
268
- end
269
- rescue Connection::Error => e
264
+ server.configure options.merge( socket: socket, role: :server, server_handler: server_handler )
265
+ attach server
266
+ rescue => e
270
267
  server.close e
268
+ raise
271
269
  end
272
270
 
273
271
  server
@@ -659,10 +657,8 @@ class Raktr
659
657
 
660
658
  selected_sockets =
661
659
  begin
662
- Connection::Error.translate do
663
- select( r, w, e, @select_timeout )
664
- end
665
- rescue Connection::Error => e
660
+ select( r, w, e, @select_timeout )
661
+ rescue => e
666
662
  nil
667
663
  end
668
664
 
@@ -141,7 +141,7 @@ describe Raktr::Connection::TLS do
141
141
  context 'and options have been provided' do
142
142
  let(:client_ssl_options) { client_valid_ssl_options }
143
143
 
144
- it "passes #{Raktr::Connection::Error::SSL} to #on_error" do
144
+ it "passes #{OpenSSL::SSL::SSLError} to #on_error" do
145
145
  error = nil
146
146
 
147
147
  options = server_ssl_options.merge(
@@ -165,7 +165,7 @@ describe Raktr::Connection::TLS do
165
165
 
166
166
  raktr.wait rescue Raktr::Error::NotRunning
167
167
 
168
- error.should be_kind_of Raktr::Connection::Error::SSL
168
+ error.should be_kind_of OpenSSL::SSL::SSLError
169
169
  end
170
170
  end
171
171
  end
@@ -199,7 +199,7 @@ describe Raktr::Connection::TLS do
199
199
  context 'and are invalid' do
200
200
  let(:client_ssl_options) { client_invalid_ssl_options }
201
201
 
202
- it "passes #{Raktr::Connection::Error::SSL} to #on_error" do
202
+ it "passes #{OpenSSL::SSL::SSLError} to #on_error" do
203
203
  error = nil
204
204
 
205
205
  options = server_ssl_options.merge(
@@ -222,7 +222,7 @@ describe Raktr::Connection::TLS do
222
222
 
223
223
  raktr.wait rescue Raktr::Error::NotRunning
224
224
 
225
- error.should be_kind_of Raktr::Connection::Error::SSL
225
+ error.should be_kind_of OpenSSL::SSL::SSLError
226
226
  end
227
227
  end
228
228
  end
@@ -230,7 +230,7 @@ describe Raktr::Connection::TLS do
230
230
  context 'and no options have been provided' do
231
231
  let(:client_ssl_options) { {} }
232
232
 
233
- it "passes #{Raktr::Connection::Error::SSL} to #on_error" do
233
+ it "passes #{OpenSSL::SSL::SSLError} to #on_error" do
234
234
  error = nil
235
235
 
236
236
  options = server_ssl_options.merge(
@@ -254,7 +254,7 @@ describe Raktr::Connection::TLS do
254
254
 
255
255
  raktr.wait rescue Raktr::Error::NotRunning
256
256
 
257
- error.should be_kind_of Raktr::Connection::Error::SSL
257
+ error.should be_kind_of OpenSSL::SSL::SSLError
258
258
  end
259
259
  end
260
260
  end
@@ -302,13 +302,13 @@ describe Raktr::Connection::TLS do
302
302
  let(:server_ssl_options) { server_valid_ssl_options }
303
303
 
304
304
  context 'and no options have been provided' do
305
- it "passes #{Raktr::Connection::Error} to #on_error" do
305
+ it "passes #{OpenSSL::SSL::SSLError} to #on_error" do
306
306
  connection = nil
307
307
  raktr.run do
308
308
  connection = raktr.connect( host, port, TLSHandler )
309
309
  end
310
310
 
311
- connection.error.should be_kind_of Raktr::Connection::Error
311
+ connection.error.should be_kind_of OpenSSL::SSL::SSLError
312
312
  end
313
313
  end
314
314
 
@@ -332,13 +332,13 @@ describe Raktr::Connection::TLS do
332
332
  end
333
333
 
334
334
  context 'and are invalid' do
335
- it "passes #{Raktr::Connection::Error} to #on_error" do
335
+ it "passes #{OpenSSL::SSL::SSLError} to #on_error" do
336
336
  connection = nil
337
337
  raktr.run do
338
338
  connection = raktr.connect( host, port, TLSHandler, client_invalid_ssl_options )
339
339
  end
340
340
 
341
- connection.error.should be_kind_of Raktr::Connection::Error
341
+ connection.error.should be_kind_of OpenSSL::SSL::SSLError
342
342
  end
343
343
  end
344
344
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ap'
2
2
  require_relative '../lib/raktr'
3
3
 
4
+ require_relative 'support/helpers/paths'
4
5
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
5
6
  next if f.include? '/servers/'
6
7
  require f
@@ -4,6 +4,7 @@ require 'net/http'
4
4
  class Servers
5
5
  include Singleton
6
6
 
7
+ require_relative '../helpers/paths'
7
8
  RUNNER = "#{support_lib_path}/servers/runner.rb"
8
9
 
9
10
  attr_reader :lib
@@ -578,7 +578,7 @@ shared_examples_for 'Raktr' do
578
578
  end
579
579
 
580
580
  context 'when the socket is invalid' do
581
- it "calls #on_close with #{klass::Connection::Error::HostNotFound}" do
581
+ it "calls #on_close with #{Errno::ENOENT}" do
582
582
  outside_thread = Thread.current
583
583
  subject.run do
584
584
  Thread.current[:outside_thread] = outside_thread
@@ -591,7 +591,7 @@ shared_examples_for 'Raktr' do
591
591
  end
592
592
  end
593
593
 
594
- Thread.current[:outside_thread][:error].should be_a_kind_of klass::Connection::Error::HostNotFound
594
+ Thread.current[:outside_thread][:error].should be_a_kind_of Errno::ENOENT
595
595
  end
596
596
  end
597
597
  end
@@ -625,7 +625,7 @@ shared_examples_for 'Raktr' do
625
625
  end
626
626
 
627
627
  context 'when the host is invalid' do
628
- it "calls #on_close with #{klass::Connection::Error::HostNotFound}" do
628
+ it "calls #on_close with #{SocketError}" do
629
629
  outside_thread = Thread.current
630
630
  subject.run do
631
631
  Thread.current[:outside_thread] = outside_thread
@@ -638,12 +638,12 @@ shared_examples_for 'Raktr' do
638
638
  end
639
639
  end
640
640
 
641
- Thread.current[:outside_thread][:error].should be_a_kind_of klass::Connection::Error::HostNotFound
641
+ Thread.current[:outside_thread][:error].should be_a_kind_of SocketError
642
642
  end
643
643
  end
644
644
 
645
645
  context 'when the port is invalid' do
646
- it "calls #on_close with #{klass::Connection::Error::Refused}" do
646
+ it "calls #on_close with #{Errno::ECONNREFUSED}" do
647
647
  outside_thread = Thread.current
648
648
  subject.run do
649
649
  Thread.current[:outside_thread] = outside_thread
@@ -663,9 +663,9 @@ shared_examples_for 'Raktr' do
663
663
  end
664
664
  end
665
665
 
666
- [:error, klass::Connection::Error::Closed,
667
- klass::Connection::Error::Refused,
668
- Raktr::Connection::Error::BrokenPipe
666
+ [:error, IOError,
667
+ Errno::ECONNREFUSED,
668
+ Errno::EPIPE
669
669
  ].should include Thread.current[:outside_thread][:error]
670
670
  end
671
671
  end
@@ -735,7 +735,7 @@ shared_examples_for 'Raktr' do
735
735
  end
736
736
  end
737
737
 
738
- [:error, klass::Connection::Error::Permission].should include Thread.current[:outside_thread][:error]
738
+ [:error, Errno::EACCES].should include Thread.current[:outside_thread][:error]
739
739
  end
740
740
  end
741
741
  end
@@ -777,7 +777,7 @@ shared_examples_for 'Raktr' do
777
777
  end
778
778
  end
779
779
 
780
- [:error, klass::Connection::Error::HostNotFound].should include Thread.current[:outside_thread][:error]
780
+ [:error, SocketError].should include Thread.current[:outside_thread][:error]
781
781
  end
782
782
  end
783
783
 
@@ -802,7 +802,7 @@ shared_examples_for 'Raktr' do
802
802
  end
803
803
  end
804
804
 
805
- [:error, klass::Connection::Error::Permission].should include Thread.current[:outside_thread][:error]
805
+ [:error, Errno::EACCES].should include Thread.current[:outside_thread][:error]
806
806
  end
807
807
  end
808
808
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raktr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-20 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Raktr is a simple, lightweight, pure-Ruby implementation of the Reactor
@@ -28,7 +28,6 @@ files:
28
28
  - lib/raktr.rb
29
29
  - lib/raktr/connection.rb
30
30
  - lib/raktr/connection/callbacks.rb
31
- - lib/raktr/connection/error.rb
32
31
  - lib/raktr/connection/peer_info.rb
33
32
  - lib/raktr/connection/tls.rb
34
33
  - lib/raktr/global.rb
@@ -97,44 +96,44 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
96
  - !ruby/object:Gem::Version
98
97
  version: '0'
99
98
  requirements: []
100
- rubygems_version: 3.3.0.dev
99
+ rubygems_version: 3.4.13
101
100
  signing_key:
102
101
  specification_version: 4
103
102
  summary: A pure-Ruby implementation of the Reactor pattern.
104
103
  test_files:
105
- - spec/raktr/connection/tls_spec.rb
106
104
  - spec/raktr/connection_spec.rb
107
- - spec/raktr/iterator_spec.rb
105
+ - spec/raktr/tasks_spec.rb
108
106
  - spec/raktr/queue_spec.rb
109
- - spec/raktr/tasks/base.rb
110
107
  - spec/raktr/tasks/delayed_spec.rb
111
108
  - spec/raktr/tasks/one_off_spec.rb
109
+ - spec/raktr/tasks/base.rb
112
110
  - spec/raktr/tasks/periodic_spec.rb
113
111
  - spec/raktr/tasks/persistent_spec.rb
114
- - spec/raktr/tasks_spec.rb
115
- - spec/raktr_spec.rb
116
- - spec/raktr_tls_spec.rb
112
+ - spec/raktr/iterator_spec.rb
113
+ - spec/raktr/connection/tls_spec.rb
117
114
  - spec/spec_helper.rb
118
- - spec/support/fixtures/handlers/echo_client.rb
119
- - spec/support/fixtures/handlers/echo_client_tls.rb
115
+ - spec/raktr_tls_spec.rb
116
+ - spec/support/helpers/utilities.rb
117
+ - spec/support/helpers/paths.rb
120
118
  - spec/support/fixtures/handlers/echo_server.rb
121
119
  - spec/support/fixtures/handlers/echo_server_tls.rb
120
+ - spec/support/fixtures/handlers/echo_client_tls.rb
121
+ - spec/support/fixtures/handlers/echo_client.rb
122
122
  - spec/support/fixtures/pems/cacert.pem
123
- - spec/support/fixtures/pems/client/cert.pem
124
- - spec/support/fixtures/pems/client/foo-cert.pem
125
- - spec/support/fixtures/pems/client/foo-key.pem
126
- - spec/support/fixtures/pems/client/key.pem
127
123
  - spec/support/fixtures/pems/server/cert.pem
128
124
  - spec/support/fixtures/pems/server/key.pem
129
- - spec/support/helpers/paths.rb
130
- - spec/support/helpers/utilities.rb
131
- - spec/support/lib/server_option_parser.rb
132
- - spec/support/lib/servers/runner.rb
125
+ - spec/support/fixtures/pems/client/foo-key.pem
126
+ - spec/support/fixtures/pems/client/foo-cert.pem
127
+ - spec/support/fixtures/pems/client/cert.pem
128
+ - spec/support/fixtures/pems/client/key.pem
129
+ - spec/support/shared/task.rb
130
+ - spec/support/shared/raktr.rb
131
+ - spec/support/shared/connection.rb
133
132
  - spec/support/lib/servers.rb
134
- - spec/support/servers/echo.rb
135
- - spec/support/servers/echo_tls.rb
133
+ - spec/support/lib/servers/runner.rb
134
+ - spec/support/lib/server_option_parser.rb
136
135
  - spec/support/servers/echo_unix.rb
136
+ - spec/support/servers/echo_tls.rb
137
+ - spec/support/servers/echo.rb
137
138
  - spec/support/servers/echo_unix_tls.rb
138
- - spec/support/shared/connection.rb
139
- - spec/support/shared/raktr.rb
140
- - spec/support/shared/task.rb
139
+ - spec/raktr_spec.rb
@@ -1,120 +0,0 @@
1
- =begin
2
-
3
- This file is part of the Raktr project and may be subject to
4
- redistribution and commercial restrictions. Please see the Raktr
5
- web site for more information on licensing and terms of use.
6
-
7
- =end
8
-
9
- class Raktr
10
- class Connection
11
-
12
- # {Connection} error namespace.
13
- #
14
- # All {Connection} errors inherit from and live under it.
15
- #
16
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
17
- class Error < Raktr::Error
18
-
19
- class << self
20
- # Captures Ruby exceptions and converts them to an appropriate
21
- # subclass of {Error}.
22
- #
23
- # @param [Block] block Block to run.
24
- def translate( &block )
25
- block.call
26
- rescue IOError, Errno::ENOTCONN, Errno::ENOTSOCK => e
27
- raise_with_proper_backtrace( e, Closed )
28
- rescue SocketError, Errno::ENOENT => e
29
- raise_with_proper_backtrace( e, HostNotFound )
30
- rescue Errno::EPIPE => e
31
- raise_with_proper_backtrace( e, BrokenPipe )
32
- rescue Errno::ECONNREFUSED,
33
- # JRuby throws Errno::EADDRINUSE when trying to connect to a
34
- # non-existent server.
35
- Errno::EADDRINUSE => e
36
- raise_with_proper_backtrace( e, Refused )
37
- rescue Errno::ECONNRESET, Errno::ECONNABORTED => e
38
- raise_with_proper_backtrace( e, Reset )
39
- rescue Errno::EACCES => e
40
- raise_with_proper_backtrace( e, Permission )
41
- rescue Errno::EBADF => e
42
- raise_with_proper_backtrace( e, BadSocket )
43
-
44
- # Catch and forward these before handling OpenSSL::OpenSSLError because
45
- # all SSL errors inherit from it, including OpenSSL::SSL::SSLErrorWaitReadable
46
- # and OpenSSL::SSL::SSLErrorWaitWritable which also inherit from
47
- # IO::WaitReadable and IO::WaitWritable and need special treatment.
48
- rescue IO::WaitReadable, IO::WaitWritable, Errno::EINPROGRESS
49
- raise
50
-
51
- # We're mainly interested in translating SSL handshake errors but there
52
- # aren't any specific exceptions for these.
53
- #
54
- # Why make things easy and clean, right?
55
- rescue OpenSSL::SSL::SSLError, OpenSSL::OpenSSLError => e
56
- raise_with_proper_backtrace( e, SSL )
57
- end
58
-
59
- def raise_with_proper_backtrace( ruby, raktr )
60
- e = raktr.new( ruby.to_s )
61
- e.set_backtrace ruby.backtrace
62
- raise e
63
- end
64
- end
65
-
66
- # Like a `SocketError.getaddrinfo` exception.
67
- #
68
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
69
- class HostNotFound < Error
70
- end
71
-
72
- # Like a `Errno::EACCES` exception.
73
- #
74
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
75
- class Permission < Error
76
- end
77
-
78
- # Like a `Errno::ECONNREFUSED` exception.
79
- #
80
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
81
- class Refused < Error
82
- end
83
-
84
- # Like a `Errno::ECONNRESET` exception.
85
- #
86
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
87
- class Reset < Error
88
- end
89
-
90
- # Like a `Errno::EPIPE` exception.
91
- #
92
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
93
- class BrokenPipe < Error
94
- end
95
-
96
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
97
- class Timeout < Error
98
- end
99
-
100
- # Like a `IOError` exception.
101
- #
102
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
103
- class Closed < Error
104
- end
105
-
106
- # Like a `Errno::EBADF` exception.
107
- #
108
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
109
- class BadSocket < Error
110
- end
111
-
112
- # Like a `OpenSSL::OpenSSLError` exception.
113
- #
114
- # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
115
- class SSL < Error
116
- end
117
-
118
- end
119
- end
120
- end