From 7b6e3adf62230df93f0a5e65aa5fa637942503a5 Mon Sep 17 00:00:00 2001 From: Marius Sandu-Popa Date: Fri, 16 Apr 2010 17:48:44 +0300 Subject: [PATCH] autorun: updated Commander --- autorun/commander/Commander.py | 10 ++++++++-- autorun/commander/CommanderBase.py | 25 ++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/autorun/commander/Commander.py b/autorun/commander/Commander.py index 9fa8897..2b42408 100644 --- a/autorun/commander/Commander.py +++ b/autorun/commander/Commander.py @@ -60,6 +60,7 @@ class Commander(Thread): ret = self.Commander.startClient(node.public_address, int(node.listen_port), config_data) + print ">>>>>>>>", ret if ret: si.pid = ret @@ -84,8 +85,10 @@ class Commander(Thread): for si in self.swarm.getSIs(): self.startSI(si) - #for si in self.swarm.getSIs(): - # self.stopSI(si) + + def stopAll(self): + for si in self.swarm.getSIs(): + self.stopSI(si) def run(self): self.printUsage() @@ -94,10 +97,13 @@ class Commander(Thread): if k == '': break elif k == '1': self.startAll() + elif k == '2': + self.stopAll() def printUsage(self): print "=========Commander Options==========" print "1. Start Swarm" + print "2. Stop Swarm" print "====================================" if __name__ == "__main__": diff --git a/autorun/commander/CommanderBase.py b/autorun/commander/CommanderBase.py index 9e82d8b..85ef7d5 100644 --- a/autorun/commander/CommanderBase.py +++ b/autorun/commander/CommanderBase.py @@ -67,20 +67,19 @@ class CommanderBase(): def recvMsg(self): msg = '' while 1: - chunk = self.sock.recv(BUFFER_SIZE) - if not chunk: - break - #raise RuntimeError, "socket connection broken" - + chunk = self.sock.recv(BUFFER_SIZE) + if not chunk: + break + #raise RuntimeError, "socket connection broken" msg = msg + chunk - if len(chunk) < BUFFER_SIZE: + if len(chunk) < BUFFER_SIZE: break dd = pickle.loads(msg) return dd - #chunk = self.sock.recv(MSGLEN) - #if chunk == '': + # chunk = self.sock.recv(MSGLEN) + # if chunk == '': # raise RuntimeError, "socket connection broken" # msg = msg + chunk # @@ -131,11 +130,11 @@ class CommanderBase(): START_MSG, config_data) #print listen_port - #if msg_type == ACK_MSG: - # return msg_data - #else: - # print msg_data - # return -1 + if msg_type == ACK_MSG: + return msg_data + else: + print msg_data + return -1 def printDummyCommand(self, public_address, public_port, option1, data): print "----------------------" -- 2.20.1