Donate CPU: send data in chunks
This commit is contained in:
parent
48f5792ca1
commit
33b93cdd3a
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue