diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index c117d3410..43b7ff4a2 100644 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -57,6 +57,14 @@ def latestReport(latestResults): html += '\n' 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') @@ -125,14 +133,7 @@ while True: resp += 'Content-type: text/html\n\n' print(resp + '...') resp += html - while resp: - bytes = connection.send(resp) - print('sent:' + str(bytes)) - if bytes < len(resp): - resp = resp[bytes:] - else: - resp = None - time.sleep(0.5) + sendAll(connection, resp) elif cmd.startswith('GET /'): print('[' + strDateTime() + '] ' + cmd) connection.send('HTTP/1.1 404 Not Found\n\n') diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index 69cfb6c78..bc360b8b3 100644 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -132,13 +132,23 @@ def scanPackage(workPath, cppcheck): 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): print('Uploading results..') sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = ('cppcheck.osuosl.org', 8000) sock.connect(server_address) try: - sock.sendall('write\n' + package + '\n' + results) + sendAll(sock, 'write\n' + package + '\n' + results) finally: sock.close() return package