ftw 0.0.30 → 0.0.31

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.
@@ -129,62 +129,67 @@ class FTW::Connection
129
129
 
130
130
  # Do dns resolution on the host. If there are multiple
131
131
  # addresses resolved, return one at random.
132
- @remote_address = FTW::DNS.singleton.resolve_random(host)
133
- @logger.debug("Connecting", :address => @remote_address,
134
- :host => host, :port => port)
135
-
136
- # Addresses with colon ':' in them are assumed to be IPv6
137
- family = @remote_address.include?(":") ? Socket::AF_INET6 : Socket::AF_INET
138
- @socket = Socket.new(family, Socket::SOCK_STREAM, 0)
139
-
140
- # This api is terrible. pack_sockaddr_in? This isn't C, man...
141
- @logger.debug("packing", :data => [port.to_i, @remote_address])
142
- sockaddr = Socket.pack_sockaddr_in(port.to_i, @remote_address)
143
- # TODO(sissel): Support local address binding
144
-
145
- # Connect with timeout
146
- begin
147
- @socket.connect_nonblock(sockaddr)
148
- rescue IO::WaitWritable, Errno::EINPROGRESS
149
- # Ruby actually raises Errno::EINPROGRESS, but for some reason
150
- # the documentation says to use this IO::WaitWritable thing...
151
- # I don't get it, but whatever :(
152
-
153
- writable = writable?(timeout)
154
-
155
- # http://jira.codehaus.org/browse/JRUBY-6528; IO.select doesn't behave correctly
156
- # on JRuby < 1.7, so work around it.
157
- if writable || (RUBY_PLATFORM == "java" and JRUBY_VERSION < "1.7.0")
158
- begin
159
- @socket.connect_nonblock(sockaddr) # check connection failure
160
- rescue Errno::EISCONN
161
- # Ignore, we're already connected.
162
- rescue Errno::ECONNREFUSED => e
163
- # Fire 'disconnected' event with reason :refused
164
- @socket.close
165
- return ConnectRefused.new("#{host}[#{@remote_address}]:#{port}")
166
- rescue Errno::ETIMEDOUT
167
- # This occurs when the system's TCP timeout hits, we have no control
168
- # over this, as far as I can tell. *maybe* setsockopt(2) has a flag
169
- # for this, but I haven't checked..
170
- # TODO(sissel): We should instead do 'retry' unless we've exceeded
171
- # the timeout.
172
- @socket.close
173
- return ConnectTimeout.new("#{host}[#{@remote_address}]:#{port}")
174
- rescue Errno::EINPROGRESS
175
- # If we get here, it's likely JRuby version < 1.7.0. EINPROGRESS at
176
- # this point in the code means that we have timed out.
177
- @socket.close
132
+ addresses = FTW::DNS.singleton.resolve(host)
133
+
134
+ addresses.each do |address|
135
+ # Try each address until one works.
136
+ @remote_address = address
137
+ # Addresses with colon ':' in them are assumed to be IPv6
138
+ family = @remote_address.include?(":") ? Socket::AF_INET6 : Socket::AF_INET
139
+ @logger.debug("Connecting", :address => @remote_address,
140
+ :host => host, :port => port, :family => family)
141
+ @socket = Socket.new(family, Socket::SOCK_STREAM, 0)
142
+
143
+ # This api is terrible. pack_sockaddr_in? This isn't C, man...
144
+ @logger.debug("packing", :data => [port.to_i, @remote_address])
145
+ sockaddr = Socket.pack_sockaddr_in(port.to_i, @remote_address)
146
+ # TODO(sissel): Support local address binding
147
+
148
+ # Connect with timeout
149
+ begin
150
+ @socket.connect_nonblock(sockaddr)
151
+ rescue IO::WaitWritable, Errno::EINPROGRESS
152
+ # Ruby actually raises Errno::EINPROGRESS, but for some reason
153
+ # the documentation says to use this IO::WaitWritable thing...
154
+ # I don't get it, but whatever :(
155
+
156
+ writable = writable?(timeout)
157
+
158
+ # http://jira.codehaus.org/browse/JRUBY-6528; IO.select doesn't behave
159
+ # correctly on JRuby < 1.7, so work around it.
160
+ if writable || (RUBY_PLATFORM == "java" and JRUBY_VERSION < "1.7.0")
161
+ begin
162
+ @socket.connect_nonblock(sockaddr) # check connection failure
163
+ rescue Errno::EISCONN
164
+ # Ignore, we're already connected.
165
+ rescue Errno::ECONNREFUSED => e
166
+ # Fire 'disconnected' event with reason :refused
167
+ @socket.close
168
+ return ConnectRefused.new("#{host}[#{@remote_address}]:#{port}")
169
+ rescue Errno::ETIMEDOUT
170
+ # This occurs when the system's TCP timeout hits, we have no
171
+ # control over this, as far as I can tell. *maybe* setsockopt(2)
172
+ # has a flag for this, but I haven't checked..
173
+ # TODO(sissel): We should instead do 'retry' unless we've exceeded
174
+ # the timeout.
175
+ @socket.close
176
+ return ConnectTimeout.new("#{host}[#{@remote_address}]:#{port}")
177
+ rescue Errno::EINPROGRESS
178
+ # If we get here, it's likely JRuby version < 1.7.0. EINPROGRESS at
179
+ # this point in the code means that we have timed out.
180
+ @socket.close
181
+ return ConnectTimeout.new("#{host}[#{@remote_address}]:#{port}")
182
+ end
183
+ else
184
+ # Connection timeout;
178
185
  return ConnectTimeout.new("#{host}[#{@remote_address}]:#{port}")
179
186
  end
180
- else
181
- # Connection timeout;
182
- return ConnectTimeout.new("#{host}[#{@remote_address}]:#{port}")
183
- end
184
- end
185
187
 
186
- # We're now connected.
187
- @connected = true
188
+ # If no error at this point, we're now connected.
189
+ @connected = true
190
+ break
191
+ end # addresses.each
192
+ end
188
193
  return nil
189
194
  end # def connect
190
195
 
@@ -34,7 +34,7 @@ class FTW::DNS::DNS
34
34
  if address.length == 16
35
35
  # Unpack 16 bit chunks, convert to hex, join with ":"
36
36
  address.unpack("n8").collect { |p| p.to_s(16) } \
37
- .join(":").sub(/(?:0:(?:0:)+)/, "::")
37
+ .join(":").sub(/(?:0:(?:0:)+)/, ":")
38
38
  else
39
39
  # assume ipv4
40
40
  # Per the following sites, "::127.0.0.1" is valid and correct
@@ -3,5 +3,5 @@ require "ftw/namespace"
3
3
  # :nodoc:
4
4
  module FTW
5
5
  # The version of this library
6
- VERSION = "0.0.30"
6
+ VERSION = "0.0.31"
7
7
  end
metadata CHANGED
@@ -1,98 +1,107 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
5
- prerelease:
4
+ version: 0.0.31
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jordan Sissel
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-30 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- type: :runtime
15
+ name: cabin
16
16
  version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>'
18
+ - - !binary |-
19
+ Pg==
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
22
- name: cabin
23
- prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
21
+ version: !binary |-
22
+ MA==
25
23
  none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
- - - ! '>'
26
+ - - !binary |-
27
+ Pg==
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
29
+ version: !binary |-
30
+ MA==
31
+ none: false
32
+ prerelease: false
31
33
  type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ name: http_parser.rb
32
36
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
37
  requirements:
35
38
  - - '='
36
39
  - !ruby/object:Gem::Version
37
40
  version: 0.5.3
38
- name: http_parser.rb
39
- prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
41
41
  none: false
42
+ requirement: !ruby/object:Gem::Requirement
42
43
  requirements:
43
44
  - - '='
44
45
  - !ruby/object:Gem::Version
45
46
  version: 0.5.3
46
- - !ruby/object:Gem::Dependency
47
+ none: false
48
+ prerelease: false
47
49
  type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ name: addressable
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
53
  requirements:
51
- - - ! '>='
54
+ - - ">="
52
55
  - !ruby/object:Gem::Version
53
- version: '0'
54
- name: addressable
55
- prerelease: false
56
- requirement: !ruby/object:Gem::Requirement
56
+ version: !binary |-
57
+ MA==
57
58
  none: false
59
+ requirement: !ruby/object:Gem::Requirement
58
60
  requirements:
59
- - - ! '>='
61
+ - - ">="
60
62
  - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
+ version: !binary |-
64
+ MA==
65
+ none: false
66
+ prerelease: false
63
67
  type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ name: backports
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
71
  requirements:
67
- - - ! '>='
72
+ - - '='
68
73
  - !ruby/object:Gem::Version
69
- version: '0'
70
- name: backports
71
- prerelease: false
72
- requirement: !ruby/object:Gem::Requirement
74
+ version: 2.3.0
73
75
  none: false
76
+ requirement: !ruby/object:Gem::Requirement
74
77
  requirements:
75
- - - ! '>='
78
+ - - '='
76
79
  - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
80
+ version: 2.3.0
81
+ none: false
82
+ prerelease: false
79
83
  type: :runtime
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest
80
86
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
87
  requirements:
83
- - - ! '>'
88
+ - - !binary |-
89
+ Pg==
84
90
  - !ruby/object:Gem::Version
85
- version: '0'
86
- name: minitest
87
- prerelease: false
88
- requirement: !ruby/object:Gem::Requirement
91
+ version: !binary |-
92
+ MA==
89
93
  none: false
94
+ requirement: !ruby/object:Gem::Requirement
90
95
  requirements:
91
- - - ! '>'
96
+ - - !binary |-
97
+ Pg==
92
98
  - !ruby/object:Gem::Version
93
- version: '0'
94
- description: For The Web. Trying to build a solid and sane API for client and server
95
- web stuff. Client and Server operations for HTTP, WebSockets, SPDY, etc.
99
+ version: !binary |-
100
+ MA==
101
+ none: false
102
+ prerelease: false
103
+ type: :development
104
+ description: For The Web. Trying to build a solid and sane API for client and server web stuff. Client and Server operations for HTTP, WebSockets, SPDY, etc.
96
105
  email:
97
106
  - jls@semicomplete.com
98
107
  executables: []
@@ -100,6 +109,7 @@ extensions: []
100
109
  extra_rdoc_files: []
101
110
  files:
102
111
  - lib/ftw.rb
112
+ - lib/rack/handler/ftw.rb
103
113
  - lib/ftw/websocket.rb
104
114
  - lib/ftw/protocol.rb
105
115
  - lib/ftw/webserver.rb
@@ -126,7 +136,6 @@ files:
126
136
  - lib/ftw/dns/dns.rb
127
137
  - lib/ftw/http/headers.rb
128
138
  - lib/ftw/http/message.rb
129
- - lib/rack/handler/ftw.rb
130
139
  - test/docs.rb
131
140
  - test/all.rb
132
141
  - test/testing.rb
@@ -138,28 +147,29 @@ files:
138
147
  homepage: http://github.com/jordansissel/ruby-ftw
139
148
  licenses:
140
149
  - Apache License (2.0)
141
- post_install_message:
150
+ post_install_message:
142
151
  rdoc_options: []
143
152
  require_paths:
144
153
  - lib
145
154
  - lib
146
155
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
156
  requirements:
149
- - - ! '>='
157
+ - - ">="
150
158
  - !ruby/object:Gem::Version
151
- version: '0'
152
- required_rubygems_version: !ruby/object:Gem::Requirement
159
+ version: !binary |-
160
+ MA==
153
161
  none: false
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
163
  requirements:
155
- - - ! '>='
164
+ - - ">="
156
165
  - !ruby/object:Gem::Version
157
- version: '0'
166
+ version: !binary |-
167
+ MA==
168
+ none: false
158
169
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 1.8.25
161
- signing_key:
170
+ rubyforge_project:
171
+ rubygems_version: 1.8.24
172
+ signing_key:
162
173
  specification_version: 3
163
- summary: For The Web. Trying to build a solid and sane API for client and server web
164
- stuff. Client and Server operations for HTTP, WebSockets, SPDY, etc.
174
+ summary: For The Web. Trying to build a solid and sane API for client and server web stuff. Client and Server operations for HTTP, WebSockets, SPDY, etc.
165
175
  test_files: []