mad-p-xmpp4r 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ mad-p-xmpp4r 0.6.1 (21/02/2013)
2
+ ===============================
3
+ * Modified to work with BOSH with HTTPBinding::Client
4
+ - Support stream restart with urn:xmpp:xbosh way.
5
+ - Removed unnecessary wait until authenticated.
6
+ - Added Semaphore to wait for auth and bind response.
7
+ - Hook to setup SSL flags (certificate, etc.)
8
+ - Adjusted HTTP::Net read_timeout according to http_wait.
9
+ - Proxy handling.
10
+ - Respect poll/request BOSH parameters to avoid overactivity.
11
+
1
12
  XMPP4R 0.5 (15/06/2009)
2
13
  =======================
3
14
  * Many bugs fixed and tests cleanups (better Ruby 1.9 support, in
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ RDOC_OPTIONS = [
34
34
  # Extra files outside of the lib dir that should be included with the rdocs.
35
35
  RDOC_FILES = (%w( README.rdoc README_ruby19.txt CHANGELOG LICENSE COPYING )).sort
36
36
 
37
- # The full file list used for rdocs, tarballs, gems, and for generating the mad-p-xmpp4r.gemspec.
37
+ # The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
38
38
  PKG_FILES = (%w( Rakefile setup.rb mad-p-xmpp4r.gemspec ) + RDOC_FILES + Dir["{lib,test,data,tools}/**/*"]).sort
39
39
 
40
40
  ##############################################################################
@@ -223,7 +223,7 @@ rescue LoadError
223
223
  ###
224
224
  Packaging Warning : RubyGems is apparently not installed on this
225
225
  system and any file add/remove/rename will not
226
- be auto-updated in the 'mad-p-xmpp4r.gemspec' when you run any
226
+ be auto-updated in the 'xmpp4r.gemspec' when you run any
227
227
  package tasks. All such file changes are recommended
228
228
  to be packaged on a system with RubyGems installed
229
229
  if you intend to push commits to the Git repo so the
@@ -125,7 +125,8 @@ module Jabber
125
125
  @stream_features = {}
126
126
  @http_rid = IdGenerator.generate_id.to_i
127
127
  @pending_rid = @http_rid
128
- @pending_rid_lock = Semaphore.new
128
+ @pending_rid_lock = Mutex.new
129
+ @pending_rid_cv = [] # [ [rid, cv], [rid, cv], ... ]
129
130
 
130
131
  req_body = REXML::Element.new('body')
131
132
  req_body.attributes['rid'] = @http_rid
@@ -202,16 +203,30 @@ module Jabber
202
203
  # Receive stanzas ensuring that the 'rid' order is kept
203
204
  # result:: [REXML::Element]
204
205
  def receive_elements_with_rid(rid, elements)
205
- while rid > @pending_rid
206
- @pending_rid_lock.wait
206
+ @pending_rid_lock.synchronize do
207
+ # Wait until rid == @pending_rid
208
+ if rid > @pending_rid
209
+ cv = ConditionVariable.new
210
+ @pending_rid_cv << [rid, cv]
211
+ @pending_rid_cv.sort!
212
+ while rid > @pending_rid
213
+ cv.wait(@pending_rid_lock)
214
+ end
215
+ end
207
216
  end
208
- @pending_rid = rid + 1
209
217
 
210
218
  elements.each { |e|
211
219
  receive(e)
212
220
  }
213
221
 
214
- @pending_rid_lock.run
222
+ # Signal waiting elements
223
+ @pending_rid_lock.synchronize do
224
+ @pending_rid = rid + 1 # Ensure @pending_rid is modified atomically
225
+ if @pending_rid_cv.size > 0 && @pending_rid_cv.first.first == @pending_rid
226
+ next_rid, cv = @pending_rid_cv.shift
227
+ cv.signal
228
+ end
229
+ end
215
230
  end
216
231
 
217
232
  ##
@@ -278,6 +293,7 @@ module Jabber
278
293
  # Do not send unneeded requests
279
294
  if data.size < 1 and @pending_requests > 0 and !restart
280
295
  @pending_requests += 1 # compensate for decrement in ensure clause
296
+ Jabber::debuglog "post_data: not sending excessive poll"
281
297
  return
282
298
  end
283
299
 
@@ -343,40 +359,47 @@ module Jabber
343
359
  # Send data,
344
360
  # buffered and obeying 'polling' and 'requests' limits
345
361
  def send_data(data, restart = false)
346
- @lock.synchronize do
347
- Jabber::debuglog("send_data")
362
+ Jabber::debuglog("send_data")
348
363
 
349
- @send_buffer += data
350
- limited_by_polling = false
351
- if @pending_requests + 1 == @http_requests
352
- limited_by_polling = (@last_send + @http_polling >= Time.now)
353
- end
354
- limited_by_requests = (@pending_requests + 1 > @http_requests)
355
-
356
- # Can we send?
357
- if !limited_by_polling and !limited_by_requests or !@authenticated
358
- Jabber::debuglog("send_data non_limited")
359
- data = @send_buffer
360
- @send_buffer = ''
364
+ while true do # exit by return
365
+ @lock.synchronize do
366
+ if @last_send + 0.05 >= Time.now
367
+ Jabber::debuglog("send_data too fast: waiting 0.05sec")
368
+ next
369
+ end
361
370
 
362
- Thread.new do
363
- Thread.current.abort_on_exception = true
364
- sleep(0.05)
365
- post_data(data, restart)
371
+ @send_buffer += data
372
+ limited_by_polling = false
373
+ if @pending_requests + 1 == @http_requests && @send_buffer.size == 0
374
+ limited_by_polling = (@last_send + @http_polling >= Time.now)
366
375
  end
376
+ limited_by_requests = (@pending_requests + 1 > @http_requests)
367
377
 
368
- elsif !limited_by_requests
369
- Jabber::debuglog("send_data limited")
370
- Thread.new do
371
- Thread.current.abort_on_exception = true
372
- # Defer until @http_polling has expired
373
- wait = @last_send + @http_polling - Time.now
374
- sleep(wait) if wait > 0
375
- # Ignore locking, it's already threaded ;-)
376
- send_data('', restart)
378
+ # Can we send?
379
+ if !limited_by_polling and !limited_by_requests or !@authenticated
380
+ Jabber::debuglog("send_data non_limited")
381
+ data = @send_buffer
382
+ @send_buffer = ''
383
+
384
+ Thread.new do
385
+ Thread.current.abort_on_exception = true
386
+ post_data(data, restart)
387
+ end
388
+ return
389
+ elsif limited_by_requests
390
+ Jabber::debuglog("send_data limited by requests")
391
+ # Do nothing.
392
+ # When a pending request gets an response, it calls send_data('')
393
+ return
394
+ elsif # limited_by_polling && @authenticated
395
+ # Wait until we get some data to send, or @http_polling expires
396
+ Jabber::debuglog("send_data limited by polling: #{@http_polling}")
397
+ else
398
+ Jabber::errorlog("send_data: can't happen: pending_requests=#{@pending_requests} http_requests=#{@http_requests} send_buffer.size=#{@send_buffer.size} limited_by_polling=#{limited_by_polling} limited_by_requests=#{limited_by_requests}")
399
+ return
377
400
  end
378
401
  end
379
-
402
+ sleep(0.1)
380
403
  end
381
404
  end
382
405
  end
data/lib/xmpp4r/xmpp4r.rb CHANGED
@@ -8,7 +8,7 @@ module Jabber
8
8
  # XMPP4R Version number. This is the ONLY place where the version number
9
9
  # should be specified. This constant is used to determine the version of
10
10
  # package tarballs and generated gems.
11
- XMPP4R_VERSION = '0.6.0'
11
+ XMPP4R_VERSION = '0.6.1'
12
12
  end
13
13
 
14
14
  require 'xmpp4r/client'
data/mad-p-xmpp4r.gemspec CHANGED
@@ -242,8 +242,8 @@ Gem::Specification.new do |s|
242
242
  s.required_ruby_version = ">= 1.8.4"
243
243
  s.required_rubygems_version = ">= 0"
244
244
  s.rubyforge_project = "mad-p-xmpp4r"
245
- s.rubygems_version = "1.8.10"
245
+ s.rubygems_version = "1.8.24"
246
246
  s.specification_version = 3
247
247
  s.summary = "This is a fork from XMPP4R (https://github.com/ln/xmpp4r), fixing BOSH"
248
- s.version = "0.6.0"
248
+ s.version = "0.6.1"
249
249
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mad-p-xmpp4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-12-01 00:00:00.000000000 Z
15
+ date: 2013-02-21 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: This is a fork from XMPP4R (https://github.com/ln/xmpp4r), fixing BOSH
18
18
  email: kaoru.maeda@gmail.com
@@ -279,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  version: '0'
280
280
  requirements: []
281
281
  rubyforge_project: mad-p-xmpp4r
282
- rubygems_version: 1.8.10
282
+ rubygems_version: 1.8.24
283
283
  signing_key:
284
284
  specification_version: 3
285
285
  summary: This is a fork from XMPP4R (https://github.com/ln/xmpp4r), fixing BOSH