kw_apn 0.2 → 0.3
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.
- data/VERSION +1 -1
- data/kw_apn.gemspec +2 -2
- data/lib/sender.rb +18 -15
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3
|
data/kw_apn.gemspec
CHANGED
@@ -7,9 +7,9 @@ end
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'kw_apn'
|
9
9
|
s.version = version
|
10
|
-
s.authors = ['Jonathan Cichon']
|
10
|
+
s.authors = ['Jonathan Cichon', 'Kupferwerk GmbH']
|
11
11
|
s.email = 'cichon@kupferwerk.com'
|
12
|
-
s.homepage = 'http://
|
12
|
+
s.homepage = 'http://github.com/kupferwerk/kw_apn'
|
13
13
|
s.summary = 'APN Lib by Kupferwerk'
|
14
14
|
s.description = 'Apple Push Notification Library by Kupferwerk'
|
15
15
|
s.has_rdoc = true
|
data/lib/sender.rb
CHANGED
@@ -4,7 +4,7 @@ module KwAPN
|
|
4
4
|
# if there is a bug on our side feel free to fix it, but for now it seems to work with the offset workaround
|
5
5
|
ID_OFFSET = 333
|
6
6
|
class Sender < Connection
|
7
|
-
attr_accessor :host, :port, :count, :fail_count, :work_thread, :watch_thread, :failed_index_array, :session_id
|
7
|
+
attr_accessor :host, :port, :count, :fail_count, :work_thread, :watch_thread, :failed_index_array, :session_id, :last_error_index
|
8
8
|
|
9
9
|
# Creates new {Sender} object with given host and port
|
10
10
|
def initialize(session_id, host=nil, port=nil)
|
@@ -40,6 +40,7 @@ module KwAPN
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def start_threads(notifications, index=0)
|
43
|
+
@last_error_index = nil
|
43
44
|
@ssl = connect(@host, @port, KwAPN::Config.options)
|
44
45
|
if @ssl
|
45
46
|
@watch_thread = Thread.new do
|
@@ -63,33 +64,35 @@ private
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def perform_batch(notifications, index=0)
|
66
|
-
|
67
|
-
|
67
|
+
begin
|
68
|
+
notifications[index..-1].each_with_index do |n, i|
|
68
69
|
n.identifier = i + index + ID_OFFSET
|
69
70
|
bytes = @ssl.write(n.to_s)
|
70
71
|
if bytes <= 0
|
71
|
-
|
72
|
-
# TODO?
|
73
|
-
# we do not realy want to respond to network errors, as we do not know how many apns might have been lost.
|
74
|
-
# At the moment we hope the watchthread does everything right and our connection holds.
|
72
|
+
raise "write returned #{bytes} bytes"
|
75
73
|
end
|
76
|
-
|
77
|
-
|
74
|
+
end
|
75
|
+
# wait for apple to respond errors
|
76
|
+
sleep(1)
|
77
|
+
rescue => e
|
78
|
+
if @last_error_index.nil?
|
79
|
+
# stop watchthread as the connection should be allready down
|
80
|
+
@watch_thread.exit
|
78
81
|
self.class.log("(#{session_id}) Exception at index #{i+index}: #{e.message}")
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
@failed_index_array << (i+index)
|
83
|
+
failed
|
84
|
+
else
|
85
|
+
# should be interrupted by watchthread, do nothing wait for restart
|
82
86
|
end
|
83
87
|
end
|
84
|
-
# wait for apple to respond errors
|
85
|
-
sleep(5)
|
86
88
|
end
|
87
89
|
|
88
90
|
def perform_watch
|
89
91
|
ret = @ssl.read
|
90
92
|
err = ret.strip.unpack('CCN')
|
91
93
|
if err[1] != 0 and err[2]
|
92
|
-
@
|
94
|
+
@last_error_index = (err[2] - ID_OFFSET)
|
95
|
+
@failed_index_array << @last_error_index
|
93
96
|
failed
|
94
97
|
@work_thread.exit
|
95
98
|
else
|
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kw_apn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonathan Cichon
|
13
|
+
- Kupferwerk GmbH
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-10 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -43,7 +44,7 @@ files:
|
|
43
44
|
- README.rdoc
|
44
45
|
- VERSION
|
45
46
|
has_rdoc: true
|
46
|
-
homepage: http://
|
47
|
+
homepage: http://github.com/kupferwerk/kw_apn
|
47
48
|
licenses: []
|
48
49
|
|
49
50
|
post_install_message:
|