Skip to content

Commit

Permalink
read and parse incomming packets untill valid ASN.1 received
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Yudin committed Jun 29, 2011
1 parent 6003bf0 commit 3ef456e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 10 additions & 1 deletion debian/changelog
@@ -1,7 +1,16 @@
python-proto (0.4.1.1cyclozzo1) lucid; urgency=high python-proto (0.4.2.1cyclozzo1) lucid; urgency=low


* Decode read request data until the whole valid ASN.1 payload received

-- Cyclozzo Builder <cyclozzo@repo> Wed, 29 Jun 2011 17:21:53 +0530

python-proto (0.4.1.1cyclozzo2) lucid; urgency=low

[ Stanislav Yudin ]
* Try to parse response data with available response_class each time to figure out the real end of received response. * Try to parse response data with available response_class each time to figure out the real end of received response.
* Prevents response reading errors on slow networks * Prevents response reading errors on slow networks

-- Cyclozzo Builder <cyclozzo@repo> Thu, 02 Jun 2011 15:48:57 +0530


python-proto (0.4.0.1cyclozzo1) lucid; urgency=low python-proto (0.4.0.1cyclozzo1) lucid; urgency=low


Expand Down
13 changes: 7 additions & 6 deletions proto/__init__.py
Expand Up @@ -135,9 +135,8 @@ def handle_socket(*args, **kw):
""" """
Reading packets Reading packets
""" """
data = socket.recv_data(None)
#call method #call method
service_name, method_name, request_inst, response_class = packet.decode_request(data, get_pb2_module()) service_name, method_name, request_inst, response_class = socket.recv_data(None)
log.info('rpc api %s.%s started' % (type(server).__name__, method_name)) log.info('rpc api %s.%s started' % (type(server).__name__, method_name))
log.debug('rpc service object: %s (%s)' % (service_name, getattr(get_pb2_module(), service_name))) log.debug('rpc service object: %s (%s)' % (service_name, getattr(get_pb2_module(), service_name)))
if not isinstance(server, getattr(get_pb2_module(), service_name) ): if not isinstance(server, getattr(get_pb2_module(), service_name) ):
Expand Down Expand Up @@ -196,7 +195,7 @@ def recv_data(self, response_type):
while True: while True:
data = None data = None
try: try:
data = self.__socket.recv(4096)#, socket.MSG_DONTWAIT) data = self.__socket.recv(SIZE)


if not data: if not data:
log.debug('no more data in socket') log.debug('no more data in socket')
Expand All @@ -210,16 +209,18 @@ def recv_data(self, response_type):
log.debug('whole data packet was received.') log.debug('whole data packet was received.')
return decoded_packet return decoded_packet
except Exception, ex: except Exception, ex:
log.debug('waiting for the whole packet.')
continue continue


except socket.error, err: except socket.error, err:
#EAGAIN & EWOULDBLOCK #EAGAIN & EWOULDBLOCK
if err.errno != 11: if err.errno != 11:
raise err raise err
elif total_data and not response_type: elif total_data and not response_type:
log.debug('looks like the whole data received.') try:
break service_name, method_name, request_inst, response_class = packet.decode_request(total_data, get_pb2_module())
return service_name, method_name, request_inst, response_class
except Exception, ex:
continue


if not total_data: if not total_data:
log.debug('socket disconnected!') log.debug('socket disconnected!')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -7,7 +7,7 @@


setup( setup(
name='proto', name='proto',
version='0.4.1', version='0.4.2',
description="The \"Proto!\" Python Async RPC based on ProtocolBuffers and TCP sockets.", description="The \"Proto!\" Python Async RPC based on ProtocolBuffers and TCP sockets.",
author="Stanislav Yudin", author="Stanislav Yudin",
author_email="decvar@gmail.com", author_email="decvar@gmail.com",
Expand Down

0 comments on commit 3ef456e

Please sign in to comment.