Bug 830431 - Send data from client in 4kb chunks, r=mdas

This commit is contained in:
Jonathan Griffin 2013-01-18 10:29:40 -08:00
Родитель 3378556222
Коммит dcb832123c
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -5,7 +5,8 @@
import json import json
import socket import socket
from errors import MarionetteException, InvalidResponseException, ErrorCodes from errors import InvalidResponseException, ErrorCodes
class MarionetteClient(object): class MarionetteClient(object):
""" The Marionette socket client. This speaks the same protocol """ The Marionette socket client. This speaks the same protocol
@ -15,6 +16,8 @@ class MarionetteClient(object):
20:{'command': 'test'} 20:{'command': 'test'}
""" """
max_packet_length = 4096
def __init__(self, addr, port): def __init__(self, addr, port):
self.addr = addr self.addr = addr
self.port = port self.port = port
@ -83,7 +86,12 @@ class MarionetteClient(object):
if 'to' not in msg: if 'to' not in msg:
msg['to'] = self.actor msg['to'] = self.actor
data = json.dumps(msg) data = json.dumps(msg)
self.sock.send('%s:%s' % (len(data), data)) data = '%s:%s' % (len(data), data)
for packet in [data[i:i + self.max_packet_length] for i in
range(0, len(data), self.max_packet_length)]:
self.sock.send(packet)
response = self.receive() response = self.receive()
return response return response