uv-rays 0.2.3 → 0.2.4

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
  SHA1:
3
- metadata.gz: 939125ab88b4466ba538e431f186dccfe37bd638
4
- data.tar.gz: 427ddebe1f2451c4938785123457276cc61e9c2c
3
+ metadata.gz: a5ba5df00f6948a972973d5bfbd9a41af4f5a5d6
4
+ data.tar.gz: d8dd4e730a3b5152eeaf3b2c85f1dd5939788014
5
5
  SHA512:
6
- metadata.gz: 8f1f88697b9ce52d05587646e81b833f58f3d998a186f2cbafd6b12beff1cad12c768a8449120615063f511e56d0f0e31bd026c7b64c6848a5f176ac136138c4
7
- data.tar.gz: 0e00f1f4bc2b8c8cb1bc2bab1e83c0cc0eca629b591cfe06933134d1cd9fd003847202d48ba58e18a379cceacd3963bf8500499667ed929ffcfda36b7666ef6e
6
+ metadata.gz: bf3d5fbef4c6587d85bfc99aa6dc0ec3647877d5382c12d2fb5602cba3b34da321ca0e173076a998ecd9e45051fad7730f6ff36a937004c3a862cdc658db41e1
7
+ data.tar.gz: d02305fa34106ed9d314f5d1d3bb4b2d353689bf1a296eb9a0e0cfb47f7a180afd35d3764da4a3bad5d55f9f5b5c85741ffb5ea6308039e064f2db05d9df2a8f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # uv-rays
2
2
 
3
- [![Build Status](https://travis-ci.org/cotag/uv-rays.png?branch=master)](https://travis-ci.org/cotag/uv-rays)
3
+ [![Build Status](https://travis-ci.org/cotag/uv-rays.svg?branch=master)](https://travis-ci.org/cotag/uv-rays)
4
4
 
5
5
  UV-Rays was designed to eliminate the complexities of high-performance threaded network programming, allowing engineers to concentrate on their application logic.
6
6
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'yard' # yard documentation
8
8
  task :default => :limited_spec
9
9
  RSpec::Core::RakeTask.new(:limited_spec) do |t|
10
10
  # Exclude network tests
11
- # t.rspec_opts = "--tag ~network"
11
+ t.rspec_opts = "--tag ~network"
12
12
  end
13
13
  RSpec::Core::RakeTask.new(:spec)
14
14
 
@@ -57,7 +57,17 @@ module UV
57
57
  end
58
58
  else
59
59
  # This will work with a regex
60
- index = messages.last.nil? ? 0 : @input[0...-last.length].rindex(messages.last) + messages.last.length
60
+ index = if messages.last.nil?
61
+ 0
62
+ else
63
+ # Possible that rindex will not find a match
64
+ check = @input[0...-last.length].rindex(messages.last)
65
+ if check.nil?
66
+ 0
67
+ else
68
+ check + messages.last.length
69
+ end
70
+ end
61
71
  indicator_val = @input[index...-last.length]
62
72
  @input = indicator_val + last
63
73
  end
File without changes
@@ -88,9 +88,9 @@ module UV
88
88
  # String - custom auth string (OAuth, etc)
89
89
  def encode_auth(k,v)
90
90
  if v.is_a? Array
91
- FIELD_ENCODING % [k, ["Basic", Base64.encode64(v.join(":")).split.join].join(" ")]
91
+ FIELD_ENCODING % [k, ["Basic", Base64.strict_encode64(v.join(":"))].join(" ")]
92
92
  else
93
- encode_field(k,v)
93
+ encode_field(k, v)
94
94
  end
95
95
  end
96
96
 
@@ -82,8 +82,17 @@ module UV
82
82
  if body
83
83
  transport.write(body).catch error
84
84
  elsif file
85
- # TODO:: Send file
86
- #@conn.stream_file_data @req.file, :http_chunks => false
85
+ # Send file
86
+ fileRef = @endpoint.loop.file file, File::RDONLY
87
+ fileRef.progress do
88
+ # File is open and available for reading
89
+ pSend = fileRef.send_file(transport, :raw)
90
+ pSend.catch error
91
+ pSend.finally do
92
+ fileRef.close
93
+ end
94
+ end
95
+ fileRef.catch error
87
96
  end
88
97
  end
89
98
 
File without changes
@@ -53,10 +53,10 @@ module UV
53
53
  @last_scheduled = @loop.now
54
54
 
55
55
 
56
- parsed_time = parse_in(time, :quiet)
56
+ parsed_time = Scheduler.parse_in(time, :quiet)
57
57
  if parsed_time.nil?
58
58
  # Parse at will throw an error if time is invalid
59
- parsed_time = parse_at(time) - @scheduler.time_diff
59
+ parsed_time = Scheduler.parse_at(time) - @scheduler.time_diff
60
60
  else
61
61
  parsed_time += @last_scheduled
62
62
  end
@@ -84,7 +84,7 @@ module UV
84
84
  #
85
85
  # @param schedule [String] a standard CRON job line or a human readable string representing a time period.
86
86
  def update(every)
87
- time = parse_in(every, :quiet) || parse_cron(every, :quiet)
87
+ time = Scheduler.parse_in(every, :quiet) || Scheduler.parse_cron(every, :quiet)
88
88
  raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil?
89
89
 
90
90
  @every = time
@@ -238,6 +238,7 @@ module UV
238
238
  else
239
239
  @schedules << event
240
240
  end
241
+ @next = nil if @next == event
241
242
 
242
243
  # optimal algorithm for inserting into an already sorted list
243
244
  Bisect.insort(@scheduled, event)
@@ -287,7 +288,16 @@ module UV
287
288
  end
288
289
 
289
290
  if not @next.nil?
290
- @timer.start(@next - @loop.now)
291
+ in_time = @next - @loop.now
292
+
293
+ # Ensure there are never negative start times
294
+ if in_time > 30
295
+ @timer.start(in_time)
296
+ else
297
+ @loop.next_tick do
298
+ on_timer
299
+ end
300
+ end
291
301
  end
292
302
  end
293
303
  end
@@ -295,6 +305,7 @@ module UV
295
305
  # Is called when the libuv timer fires
296
306
  def on_timer
297
307
  schedule = @scheduled.shift
308
+ @schedules.delete(schedule)
298
309
  schedule.trigger
299
310
 
300
311
  # execute schedules that are within 30ms of this event
@@ -302,6 +313,7 @@ module UV
302
313
  now = @loop.now + 30
303
314
  while @scheduled.first && @scheduled.first.next_scheduled <= now
304
315
  schedule = @scheduled.shift
316
+ @schedules.delete(schedule)
305
317
  schedule.trigger
306
318
  end
307
319
  check_timer
@@ -1,3 +1,3 @@
1
1
  module UV
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
File without changes
@@ -10,60 +10,6 @@ describe UV::BufferedTokenizer do
10
10
  end
11
11
 
12
12
 
13
- it "should not return anything when a complete message is not available" do
14
- msg1 = "test"
15
-
16
- result = @buffer.extract(msg1)
17
- expect(result).to eq([])
18
- end
19
-
20
- it "should tokenize messages where the data is a complete message" do
21
- msg1 = "test\n\r"
22
-
23
- result = @buffer.extract(msg1)
24
- expect(result).to eq(['test'])
25
- end
26
-
27
- it "should return multiple complete messages" do
28
- msg1 = "test\n\rwhoa\n\r"
29
-
30
- result = @buffer.extract(msg1)
31
- expect(result).to eq(['test', 'whoa'])
32
- end
33
-
34
- it "should tokenize messages where the delimiter is split" do
35
- msg1 = "test\n"
36
- msg2 = "\rwhoa\n\r"
37
-
38
- result = @buffer.extract(msg1)
39
- expect(result).to eq([])
40
- result = @buffer.extract(msg2)
41
- expect(result).to eq(['test', 'whoa'])
42
-
43
-
44
- msg3 = "test\n"
45
- msg4 = "\rwhoa\n"
46
- msg5 = "\r"
47
-
48
- result = @buffer.extract(msg3)
49
- expect(result).to eq([])
50
- result = @buffer.extract(msg4)
51
- expect(result).to eq(['test'] )
52
-
53
- result = @buffer.extract(msg5)
54
- expect(result).to eq(['whoa'])
55
- end
56
- end
57
-
58
- describe 'delimiter' do
59
-
60
- before :each do
61
- @buffer = UV::BufferedTokenizer.new({
62
- delimiter: "\n\r"
63
- })
64
- end
65
-
66
-
67
13
  it "should not return anything when a complete message is not available" do
68
14
  msg1 = "test"
69
15
 
@@ -38,7 +38,10 @@ module TestServer
38
38
  end
39
39
 
40
40
  def on_read(data, ip, port, conection)
41
- send_datagram(data, ip, port)
41
+ # ephemeral port is used for sending on windows and linux?
42
+ # Bound port seems to be used on OSX...
43
+ # TODO:: Needs investigation, might be a Libuv bug
44
+ send_datagram(data, ip, 3211)
42
45
  end
43
46
  end
44
47
 
@@ -70,7 +73,7 @@ describe UV::Connection do
70
73
  end
71
74
 
72
75
  describe 'basic tcp client server' do
73
- it "should send some data and shutdown the socket", :network => true do
76
+ it "should send some data and shutdown the socket" do
74
77
  @loop.run { |logger|
75
78
  logger.progress do |level, errorid, error|
76
79
  begin
@@ -91,7 +94,7 @@ describe UV::Connection do
91
94
  expect(res[2]).to eq('hello')
92
95
  end
93
96
 
94
- it "should not call connect on connection failure", :network => true do
97
+ it "should not call connect on connection failure" do
95
98
  @loop.run { |logger|
96
99
  logger.progress do |level, errorid, error|
97
100
  begin
@@ -113,7 +116,7 @@ describe UV::Connection do
113
116
  end
114
117
 
115
118
  describe 'basic tcp client server with tls' do
116
- it "should send some data and shutdown the socket", :network => true do
119
+ it "should send some data and shutdown the socket" do
117
120
  @loop.run { |logger|
118
121
  logger.progress do |level, errorid, error|
119
122
  begin
@@ -137,7 +140,7 @@ describe UV::Connection do
137
140
  end
138
141
 
139
142
  describe 'basic udp client server' do
140
- it "should send some data and close the socket", :network => true do
143
+ it "should send some data and close the socket" do
141
144
  @loop.run { |logger|
142
145
  logger.progress do |level, errorid, error|
143
146
  begin
@@ -40,6 +40,33 @@ module OldServer
40
40
  end
41
41
 
42
42
 
43
+ #
44
+ # TODO:: Write tests for bad server responses
45
+ # Need to be able to recover when:
46
+ # * no response is sent
47
+ # * disconnect
48
+ # * bad length etc
49
+ #
50
+ module BadServer
51
+ def post_init
52
+ @parser = ::HttpParser::Parser.new(self)
53
+ @state = ::HttpParser::Parser.new_instance
54
+ @state.type = :request
55
+ end
56
+
57
+ def on_message_complete(parser)
58
+ write("HTTP/1.0 200 OK\r\nContent-type: text/html\r\nContent-length: 0\r\n\r\n")
59
+ end
60
+
61
+ def on_read(data, connection)
62
+ if @parser.parse(@state, data)
63
+ p 'parse error'
64
+ p @state.error
65
+ end
66
+ end
67
+ end
68
+
69
+
43
70
  describe UV::HttpEndpoint do
44
71
  before :each do
45
72
  @loop = Libuv::Loop.new
@@ -57,7 +84,7 @@ describe UV::HttpEndpoint do
57
84
  end
58
85
 
59
86
  describe 'basic http request' do
60
- it "should send a request then receive a response", :network => true do
87
+ it "should send a request then receive a response" do
61
88
  @loop.run { |logger|
62
89
  logger.progress do |level, errorid, error|
63
90
  begin
@@ -88,7 +115,7 @@ describe UV::HttpEndpoint do
88
115
  expect(@response[:body]).to eq('y')
89
116
  end
90
117
 
91
- it "should send multiple requests on the same connection", :network => true do
118
+ it "should send multiple requests on the same connection" do
92
119
  @loop.run { |logger|
93
120
  logger.progress do |level, errorid, error|
94
121
  begin
@@ -129,7 +156,7 @@ describe UV::HttpEndpoint do
129
156
  expect(@response2[:headers].keep_alive).to eq(true)
130
157
  end
131
158
 
132
- it "should send pipelined requests on the same connection", :network => true do
159
+ it "should send pipelined requests on the same connection" do
133
160
  @loop.run { |logger|
134
161
  logger.progress do |level, errorid, error|
135
162
  begin
@@ -172,7 +199,7 @@ describe UV::HttpEndpoint do
172
199
  end
173
200
 
174
201
  describe 'old http request' do
175
- it "should send a request then receive a response", :network => true do
202
+ it "should send a request then receive a response" do
176
203
  @loop.run { |logger|
177
204
  logger.progress do |level, errorid, error|
178
205
  begin
@@ -201,7 +228,7 @@ describe UV::HttpEndpoint do
201
228
  expect(@response[:headers].keep_alive).to eq(false)
202
229
  end
203
230
 
204
- it "should send multiple requests", :network => true do
231
+ it "should send multiple requests" do
205
232
  @loop.run { |logger|
206
233
  logger.progress do |level, errorid, error|
207
234
  begin
@@ -242,7 +269,7 @@ describe UV::HttpEndpoint do
242
269
  expect(@response2[:headers].keep_alive).to eq(false)
243
270
  end
244
271
 
245
- it "should fail to send pipelined requests", :network => true do
272
+ it "should fail to send pipelined requests" do
246
273
  @loop.run { |logger|
247
274
  logger.progress do |level, errorid, error|
248
275
  begin
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,153 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uv-rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libuv
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.11.20
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: 0.11.20
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bisect
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
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: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: tzinfo
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: cookiejar
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ipaddress
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: addressable
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: http-parser
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.0.4
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.0.4
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '2.14'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.14'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '10.1'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '10.1'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: yard
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  description: Opinionated abstractions for Libuv
@@ -192,17 +192,17 @@ require_paths:
192
192
  - lib
193
193
  required_ruby_version: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - ">="
195
+ - - '>='
196
196
  - !ruby/object:Gem::Version
197
197
  version: 1.9.2
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ">="
200
+ - - '>='
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project:
205
- rubygems_version: 2.0.3
205
+ rubygems_version: 2.1.11
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Abstractions for working with Libuv