diff options
author | Todd Gaunt <singularik@iol.unh.edu> | 2016-10-03 16:02:12 -0400 |
---|---|---|
committer | Todd Gaunt <singularik@iol.unh.edu> | 2016-10-03 16:02:12 -0400 |
commit | 4f0ecb702a601d122f261a134007377435e4aca1 (patch) | |
tree | 40acae3074ab4a5ec1287e282b31646d22ed55be /pharos-validator/src/validation_tool/src/receiver.py | |
parent | 6ecb8d290c106e41d0f5a446e7aa878a219224ff (diff) |
Add pharos-validator tool
Change-Id: I38e077c2c90059e39ee9871abf5d867a875827a3
Signed-off-by: Todd Gaunt <singularik@iol.unh.edu>
Diffstat (limited to 'pharos-validator/src/validation_tool/src/receiver.py')
-rw-r--r-- | pharos-validator/src/validation_tool/src/receiver.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pharos-validator/src/validation_tool/src/receiver.py b/pharos-validator/src/validation_tool/src/receiver.py new file mode 100644 index 0000000..07d968e --- /dev/null +++ b/pharos-validator/src/validation_tool/src/receiver.py @@ -0,0 +1,46 @@ +############################################################################## +# Copyright (c) 2015 Todd Gaunt and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import socket +import threading +import logging + +from pharosvalidator.util import read_msg + +def start(nodecount, port, q): + """Start a server to retrieve the files from the nodes. Server will run + indefinetely until the parent process ends""" + logging.basicConfig(level=0) + logger = logging.getLogger(__name__) + + address = "" # Empty means act as a server on all available interfaces + + logger.info("Bringing up receiver server...") + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind((address, port)) + sock.listen(nodecount) # Max connections is the amount of nodes + + while True: + # Receive a descriptor for the client socket, cl stands for client + (clsock, claddress) = sock.accept() + logger.info("Received client connection...") + client_thread = threading.Thread(target=_server_accept_thread, \ + args=(clsock, claddress, q), daemon=True) + # Start a new thread to read the new client socket connection + client_thread.start() + + socket.close() + logger.info("Bringing down receiver server...") + +def _server_accept_thread(clsock, claddress, q): + """Read from the socket into the queue, then close the connection""" + logger = logging.getLogger(__name__) + q.put(read_msg(clsock)) + logger.info("Retreived message from socket") + clsock.close() |