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,16 +5,19 @@
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
as the remote debugger inside Gecko, in which messages are as the remote debugger inside Gecko, in which messages are
always preceded by the message length and a colon, e.g., always preceded by the message length and a colon, e.g.,
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