Donate CPU: send data in chunks

This commit is contained in:
Daniel Marjamäki 2018-08-25 10:25:05 +02:00
parent 48f5792ca1
commit 33b93cdd3a
2 changed files with 20 additions and 9 deletions

View File

@ -57,6 +57,14 @@ def latestReport(latestResults):
html += '</pre></body></html>\n' html += '</pre></body></html>\n'
return html return html
def sendAll(connection, data):
while data:
bytes = connection.send(data)
if bytes < len(data):
data = data[bytes:]
else:
data = None
time.sleep(0.5)
resultPath = os.path.expanduser('~/donated-results') resultPath = os.path.expanduser('~/donated-results')
@ -125,14 +133,7 @@ while True:
resp += 'Content-type: text/html\n\n' resp += 'Content-type: text/html\n\n'
print(resp + '...') print(resp + '...')
resp += html resp += html
while resp: sendAll(connection, resp)
bytes = connection.send(resp)
print('sent:' + str(bytes))
if bytes < len(resp):
resp = resp[bytes:]
else:
resp = None
time.sleep(0.5)
elif cmd.startswith('GET /'): elif cmd.startswith('GET /'):
print('[' + strDateTime() + '] ' + cmd) print('[' + strDateTime() + '] ' + cmd)
connection.send('HTTP/1.1 404 Not Found\n\n') connection.send('HTTP/1.1 404 Not Found\n\n')

View File

@ -132,13 +132,23 @@ def scanPackage(workPath, cppcheck):
return errout return errout
def sendAll(connection, data):
while data:
bytes = connection.send(data)
if bytes < len(data):
data = data[bytes:]
else:
data = None
time.sleep(0.5)
def uploadResults(package, results): def uploadResults(package, results):
print('Uploading results..') print('Uploading results..')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('cppcheck.osuosl.org', 8000) server_address = ('cppcheck.osuosl.org', 8000)
sock.connect(server_address) sock.connect(server_address)
try: try:
sock.sendall('write\n' + package + '\n' + results) sendAll(sock, 'write\n' + package + '\n' + results)
finally: finally:
sock.close() sock.close()
return package return package