sip2 0.0.9 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66c5b3c4ac6909954ad5e3c0b11577cb97d17e91
4
- data.tar.gz: 47985f7e545caec1d2d71e7fdeda15dbf099af7a
3
+ metadata.gz: 426aa3286377738536f3308fe3031e27103f6fe6
4
+ data.tar.gz: 03aa7d489c2ba5089bf5a961dc045c8c6682b8db
5
5
  SHA512:
6
- metadata.gz: c59b28ec3bfb1c1e4604e0dc8e5196c91b994c0015c11a5badfc54e6cce2a4f45a4e4bbcae42fea24e0ee28a73f609353c609eaeb53a7109ed54d91f7b567c0c
7
- data.tar.gz: 6cab90f0952d40cc71664db95b746014ad4f996049523789be36d663539f44ddcae6f36420f496befc0c8f297bebbdccc483b1f6b98b9b4936fd025458282de2
6
+ metadata.gz: 6acd6b54ecf7e553ce2cbc05257ea2721bcc3b5203166b755316cd4165e02e13003f1ffed164e4896883d3a6900bc45106864cffa753b68c46eceec1837965f6
7
+ data.tar.gz: 71f3609d27e6a0c6eda9541900b9982034359306cd967820db39cbd4f4411907dbfb465d842d81e712bab5a1301bf8638f6bea81a69cefb991c8428fc5ecfdbc
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
4
- - 2.2.5
5
- - 2.3.0
6
- - 2.4.0
3
+ - 2.1.10
4
+ - 2.2.10
5
+ - 2.3.7
6
+ - 2.4.4
7
+ - 2.5.1
7
8
 
8
9
  before_install:
9
10
  - gem update bundler
@@ -5,6 +5,13 @@ require 'sip2/patron_information'
5
5
  require 'sip2/messages/login'
6
6
  require 'sip2/messages/patron_information'
7
7
 
8
+ module Sip2
9
+ class TimeoutError < StandardError; end
10
+ class ConnectionTimeout < TimeoutError; end
11
+ class WriteTimeout < TimeoutError; end
12
+ class ReadTimeout < TimeoutError; end
13
+ end
14
+
8
15
  require 'sip2/non_blocking_socket'
9
16
  require 'sip2/connection'
10
17
  require 'sip2/client'
@@ -45,8 +45,8 @@ module Sip2
45
45
  end
46
46
 
47
47
  def send_message(message)
48
- @socket.send(message + "\r", 0)
49
- @socket.gets "\r"
48
+ @socket.send_with_timeout message
49
+ @socket.gets_with_timeout
50
50
  end
51
51
 
52
52
  def with_error_detection(message)
@@ -1,20 +1,40 @@
1
1
  require 'socket'
2
+ require 'timeout'
2
3
 
3
4
  module Sip2
4
5
  #
5
6
  # Sip2 Non-blocking socket
6
7
  # From https://spin.atomicobject.com/2013/09/30/socket-connection-timeout-ruby/
7
8
  #
8
- class NonBlockingSocket
9
+ class NonBlockingSocket < Socket
10
+ DEFAULT_TIMEOUT = 5
11
+ SEPARATOR = "\r".freeze
12
+
13
+ attr_accessor :connection_timeout
14
+
15
+ def send_with_timeout(message, separator = SEPARATOR)
16
+ ::Timeout.timeout (connection_timeout || DEFAULT_TIMEOUT), WriteTimeout do
17
+ send message + separator, 0
18
+ end
19
+ end
20
+
21
+ def gets_with_timeout(separator = SEPARATOR)
22
+ ::Timeout.timeout (connection_timeout || DEFAULT_TIMEOUT), ReadTimeout do
23
+ gets separator
24
+ end
25
+ end
26
+
9
27
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
10
- def self.connect(host, port, timeout = 5)
28
+ def self.connect(host, port, timeout = DEFAULT_TIMEOUT)
11
29
  # Convert the passed host into structures the non-blocking calls can deal with
12
30
  addr = Socket.getaddrinfo(host, nil)
13
31
  sockaddr = Socket.pack_sockaddr_in(port, addr[0][3])
14
32
 
15
- Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0).tap do |socket|
33
+ NonBlockingSocket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0).tap do |socket|
16
34
  socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
17
35
 
36
+ socket.connection_timeout = timeout
37
+
18
38
  begin
19
39
  # Initiate the socket connection in the background. If it doesn't fail
20
40
  # immediately it will raise an IO::WaitWritable (Errno::EINPROGRESS)
@@ -38,7 +58,7 @@ module Sip2
38
58
  # IO.select returns nil when the socket is not ready before timeout
39
59
  # seconds have elapsed
40
60
  socket.close
41
- raise 'Connection timeout'
61
+ raise ConnectionTimeout
42
62
  end
43
63
  end
44
64
  end
@@ -1,3 +1,3 @@
1
1
  module Sip2
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.12'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - abrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler