(server_address_port: int, packages: list, packageIndex: int, resultPath: str)
| 1333 | return data |
| 1334 | |
| 1335 | def server(server_address_port: int, packages: list, packageIndex: int, resultPath: str) -> None: |
| 1336 | socket.setdefaulttimeout(30) |
| 1337 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 1338 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 1339 | server_address = ('', server_address_port) |
| 1340 | sock.bind(server_address) |
| 1341 | |
| 1342 | sock.listen(1) |
| 1343 | |
| 1344 | latestResults = [] |
| 1345 | if os.path.isfile('latest.txt'): |
| 1346 | with open('latest.txt', 'rt') as f: |
| 1347 | latestResults = f.read().strip().split(' ') |
| 1348 | |
| 1349 | print_ts('version ' + SERVER_VERSION) |
| 1350 | print_ts('listening on port ' + str(server_address_port)) |
| 1351 | |
| 1352 | while True: |
| 1353 | # wait for a connection |
| 1354 | print_ts('waiting for a connection') |
| 1355 | connection, _ = sock.accept() |
| 1356 | try: |
| 1357 | bytes_received = connection.recv(128) |
| 1358 | cmd = bytes_received.decode('utf-8', 'ignore') |
| 1359 | except socket.error as e: |
| 1360 | print_ts('Error: Recv error: ' + str(e)) |
| 1361 | connection.close() |
| 1362 | continue |
| 1363 | except UnicodeDecodeError as e: |
| 1364 | print_ts('Error: Decoding failed: ' + str(e)) |
| 1365 | connection.close() |
| 1366 | continue |
| 1367 | pos_nl = cmd.find('\n') |
| 1368 | if pos_nl < 1: |
| 1369 | print_ts("No newline found in data: '{}'".format(cmd)) |
| 1370 | connection.close() |
| 1371 | continue |
| 1372 | firstLine = cmd[:pos_nl] |
| 1373 | if re.match('[a-zA-Z0-9./ ]+', firstLine) is None: |
| 1374 | print_ts('Unsupported characters found in command: {}'.format(firstLine)) |
| 1375 | connection.close() |
| 1376 | continue |
| 1377 | if cmd.startswith('GET /'): |
| 1378 | cmd = cmd[:cmd.find('\r\n')] |
| 1379 | print_ts(cmd) |
| 1380 | newThread = HttpClientThread(connection, cmd, resultPath, latestResults) |
| 1381 | newThread.start() |
| 1382 | continue |
| 1383 | if cmd == 'GetCppcheckVersions\n': |
| 1384 | reply = 'head ' + OLD_VERSION |
| 1385 | print_ts('GetCppcheckVersions: ' + reply) |
| 1386 | connection.send(reply.encode('utf-8', 'ignore')) |
| 1387 | connection.close() |
| 1388 | continue |
| 1389 | if cmd == 'get\n': |
| 1390 | while True: |
| 1391 | pkg = packages[packageIndex] |
| 1392 | packageIndex += 1 |
no test coverage detected