handset_detection 4.1.3 → 4.1.4
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/lib/handset_detection/base.rb +1 -1
- data/lib/handset_detection/vendor/tcp_timeout.rb +165 -0
- metadata +14 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69c1bd9d9226704ee141f82ad619d200d35c6f2
|
4
|
+
data.tar.gz: 9f436e0577fe7aabd98a27b1fd7d99a9e8e757bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278d4c46f66b6ea5e88c3d0602bd0b034353c19995cc440478e9ddc94da4b6589f3908db3bff43e81288ea70943672a7cde98aece39ef7347bdea7564b9e17c1
|
7
|
+
data.tar.gz: 40366162bd92394810d780d535b340739641a3ca1947f86683ff4a112c8899c90ad7e1cf5dc3927761acaee1e8e4f2742c833f5dccab92c1c3e9ecebadad90e8
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# Modified from the tcp_timeout gem.
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module TCPTimeout
|
6
|
+
VERSION = "0.1.1"
|
7
|
+
|
8
|
+
DELEGATED_METHODS = %w[
|
9
|
+
close closed?
|
10
|
+
getsockopt setsockopt
|
11
|
+
local_address remote_address
|
12
|
+
read_nonblock wrote_nonblock
|
13
|
+
fileno
|
14
|
+
]
|
15
|
+
|
16
|
+
class SocketTimeout < SocketError; end
|
17
|
+
|
18
|
+
class TCPSocket
|
19
|
+
DELEGATED_METHODS.each do |method|
|
20
|
+
class_eval(<<-EVAL, __FILE__, __LINE__)
|
21
|
+
def #{method}(*args)
|
22
|
+
@socket.__send__(:#{method}, *args)
|
23
|
+
end
|
24
|
+
EVAL
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(host, port, opts = {})
|
28
|
+
@connect_timeout = opts[:connect_timeout]
|
29
|
+
@write_timeout = opts[:write_timeout]
|
30
|
+
@read_timeout = opts[:read_timeout]
|
31
|
+
|
32
|
+
family = opts[:family] || Socket::AF_INET
|
33
|
+
address = Socket.getaddrinfo(host, nil, family).first[3]
|
34
|
+
@sockaddr = Socket.pack_sockaddr_in(port, address)
|
35
|
+
|
36
|
+
@socket = Socket.new(family, Socket::SOCK_STREAM, 0)
|
37
|
+
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
38
|
+
|
39
|
+
local_host = opts[:local_host]
|
40
|
+
local_port = opts[:local_port]
|
41
|
+
if local_host || local_port
|
42
|
+
local_host ||= ''
|
43
|
+
local_address = Socket.getaddrinfo(local_host, nil, family).first[3]
|
44
|
+
local_sockaddr = Socket.pack_sockaddr_in(local_port, local_address)
|
45
|
+
@socket.bind(local_sockaddr)
|
46
|
+
end
|
47
|
+
|
48
|
+
connect
|
49
|
+
end
|
50
|
+
|
51
|
+
def connect
|
52
|
+
return @socket.connect(@sockaddr) unless @connect_timeout
|
53
|
+
|
54
|
+
begin
|
55
|
+
@socket.connect_nonblock(@sockaddr)
|
56
|
+
rescue Errno::EINPROGRESS
|
57
|
+
select_timeout(:connect, @connect_timeout)
|
58
|
+
# If there was a failure this will raise an Error
|
59
|
+
begin
|
60
|
+
@socket.connect_nonblock(@sockaddr)
|
61
|
+
rescue Errno::EISCONN
|
62
|
+
# Successfully connected
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def write(data, timeout = nil)
|
68
|
+
timeout ||= @write_timeout
|
69
|
+
return @socket.write(data) unless timeout
|
70
|
+
|
71
|
+
length = data.bytesize
|
72
|
+
|
73
|
+
total_count = 0
|
74
|
+
loop do
|
75
|
+
begin
|
76
|
+
count = @socket.write_nonblock(data)
|
77
|
+
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
78
|
+
timeout = select_timeout(:write, timeout)
|
79
|
+
retry
|
80
|
+
end
|
81
|
+
|
82
|
+
total_count += count
|
83
|
+
return total_count if total_count >= length
|
84
|
+
data = data.byteslice(count..-1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def read(length = nil, *args)
|
89
|
+
raise ArgumentError, 'too many arguments' if args.length > 2
|
90
|
+
|
91
|
+
timeout = (args.length > 1) ? args.pop : @read_timeout
|
92
|
+
return @socket.read(length, *args) unless length > 0 && timeout
|
93
|
+
|
94
|
+
buffer = args.first || ''.force_encoding(Encoding::ASCII_8BIT)
|
95
|
+
|
96
|
+
begin
|
97
|
+
# Drain internal buffers
|
98
|
+
@socket.read_nonblock(length, buffer)
|
99
|
+
return buffer if buffer.bytesize >= length
|
100
|
+
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
101
|
+
# Internal buffers were empty
|
102
|
+
buffer.clear
|
103
|
+
rescue EOFError
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
@chunk ||= ''.force_encoding(Encoding::ASCII_8BIT)
|
108
|
+
|
109
|
+
loop do
|
110
|
+
timeout = select_timeout(:read, timeout)
|
111
|
+
|
112
|
+
begin
|
113
|
+
@socket.read_nonblock(length, @chunk)
|
114
|
+
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
115
|
+
retry
|
116
|
+
rescue EOFError
|
117
|
+
return buffer.empty? ? nil : buffer
|
118
|
+
end
|
119
|
+
buffer << @chunk
|
120
|
+
|
121
|
+
if length
|
122
|
+
length -= @chunk.bytesize
|
123
|
+
return buffer if length <= 0
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def readpartial(length, *args)
|
129
|
+
raise ArgumentError, 'too many arguments' if args.length > 2
|
130
|
+
|
131
|
+
timeout = (args.length > 1) ? args.pop : @read_timeout
|
132
|
+
return @socket.readpartial(length, *args) unless length > 0 && timeout
|
133
|
+
|
134
|
+
begin
|
135
|
+
@socket.read_nonblock(length, *args)
|
136
|
+
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
137
|
+
timeout = select_timeout(:read, timeout)
|
138
|
+
retry
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def readbyte
|
143
|
+
readpartial(1).ord
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def select_timeout(type, timeout)
|
149
|
+
if timeout >= 0
|
150
|
+
if type == :read
|
151
|
+
read_array = [@socket]
|
152
|
+
else
|
153
|
+
write_array = [@socket]
|
154
|
+
end
|
155
|
+
|
156
|
+
start = Time.now
|
157
|
+
if IO.select(read_array, write_array, [@socket], timeout)
|
158
|
+
waited = Time.now - start
|
159
|
+
return timeout - waited
|
160
|
+
end
|
161
|
+
end
|
162
|
+
raise SocketTimeout, "#{type} timeout"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handset_detection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Handset Detection
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dalli
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubyzip
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.1.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.1.7
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: tcp_timeout
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.1'
|
48
|
-
- - '>='
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.1.1
|
51
|
-
type: :runtime
|
52
|
-
prerelease: false
|
53
|
-
version_requirements: !ruby/object:Gem::Requirement
|
54
|
-
requirements:
|
55
|
-
- - ~>
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '0.1'
|
58
|
-
- - '>='
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.1.1
|
61
41
|
description: Use the HandsetDetection.com API from Ruby.
|
62
42
|
email: hello@handsetdetection.com
|
63
43
|
executables: []
|
@@ -67,15 +47,16 @@ files:
|
|
67
47
|
- lib/handset_detection.rb
|
68
48
|
- lib/handset_detection/base.rb
|
69
49
|
- lib/handset_detection/cache.rb
|
70
|
-
- lib/handset_detection/device.rb
|
71
|
-
- lib/handset_detection/extra.rb
|
72
|
-
- lib/handset_detection/hd4.rb
|
73
|
-
- lib/handset_detection/store.rb
|
74
50
|
- lib/handset_detection/cache/filesystem.rb
|
75
51
|
- lib/handset_detection/cache/memcached.rb
|
76
52
|
- lib/handset_detection/cache/none.rb
|
77
53
|
- lib/handset_detection/cache/rails.rb
|
54
|
+
- lib/handset_detection/device.rb
|
55
|
+
- lib/handset_detection/extra.rb
|
56
|
+
- lib/handset_detection/hd4.rb
|
57
|
+
- lib/handset_detection/store.rb
|
78
58
|
- lib/handset_detection/vendor/blank.rb
|
59
|
+
- lib/handset_detection/vendor/tcp_timeout.rb
|
79
60
|
homepage: https://github.com/HandsetDetection/ruby-apikit/
|
80
61
|
licenses:
|
81
62
|
- MIT
|
@@ -86,17 +67,17 @@ require_paths:
|
|
86
67
|
- lib
|
87
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
69
|
requirements:
|
89
|
-
- -
|
70
|
+
- - ">="
|
90
71
|
- !ruby/object:Gem::Version
|
91
72
|
version: '0'
|
92
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
74
|
requirements:
|
94
|
-
- -
|
75
|
+
- - ">="
|
95
76
|
- !ruby/object:Gem::Version
|
96
77
|
version: '0'
|
97
78
|
requirements: []
|
98
79
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.4.8
|
100
81
|
signing_key:
|
101
82
|
specification_version: 4
|
102
83
|
summary: API kit for HandsetDetection.com
|