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'
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')

View File

@ -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