Skip to content
Browse files

minor changes

  • Loading branch information...
1 parent 0f1ce70 commit f83cfba05a49fd9f0db0bbd517a08d50b9a942eb Josh Chung committed Aug 5, 2012
Showing with 17 additions and 3 deletions.
  1. +17 −3 apns.py
View
20 apns.py
@@ -32,6 +32,8 @@
import ssl
import json
+TIMEOUT = 60
+
GATEWAY_PORT = 2195
GATEWAY_HOST = 'gateway.push.apple.com'
GATEWAY_SANDBOX_HOST = 'gateway.sandbox.push.apple.com'
@@ -173,9 +175,23 @@ def read(self, n=None):
return self._connection().read(n)
return self._connection().read(n)
+ def recvall(self, n):
+ data = ""
+ while True:
+ more = self._connection().recv(n - len(data))
+ data += more
+ if len(data) >= n:
+ break
+ rlist, _, _ = select.select([self._connection()], [], [], TIMEOUT)
+ if not rlist:
+ raise socket.timeout
+
def write(self, string):
if self.enhanced: # nonblocking socket
rlist, wlist, _ = select.select([self._connection()], [self._connection()], [])
+ if len(wlist) > 0:
+ self._connection().sendall(string)
+
if len(rlist) > 0: # there's error response from APNs
buff = self.read(ERROR_RESPONSE_LENGTH)
if len(buff) != ERROR_RESPONSE_LENGTH:
@@ -184,10 +200,8 @@ def write(self, string):
if 8 != command: # not error response
return None
return (status, identifier)
- if len(wlist) > 0:
- self._connection().write(string)
else: # blocking socket
- return self._connection().write(string)
+ return self._connection().sendall(string)
class PayloadAlert(object):

0 comments on commit f83cfba

Please sign in to comment.
Something went wrong with that request. Please try again.