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 +4 -4
- data/.travis.yml +5 -4
- data/lib/sip2.rb +7 -0
- data/lib/sip2/connection.rb +2 -2
- data/lib/sip2/non_blocking_socket.rb +24 -4
- data/lib/sip2/version.rb +1 -1
- 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: 426aa3286377738536f3308fe3031e27103f6fe6
|
4
|
+
data.tar.gz: 03aa7d489c2ba5089bf5a961dc045c8c6682b8db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6acd6b54ecf7e553ce2cbc05257ea2721bcc3b5203166b755316cd4165e02e13003f1ffed164e4896883d3a6900bc45106864cffa753b68c46eceec1837965f6
|
7
|
+
data.tar.gz: 71f3609d27e6a0c6eda9541900b9982034359306cd967820db39cbd4f4411907dbfb465d842d81e712bab5a1301bf8638f6bea81a69cefb991c8428fc5ecfdbc
|
data/.travis.yml
CHANGED
data/lib/sip2.rb
CHANGED
@@ -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'
|
data/lib/sip2/connection.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
61
|
+
raise ConnectionTimeout
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
data/lib/sip2/version.rb
CHANGED
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.
|
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
|
+
date: 2018-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|