Beispiel #1
0
 def _get_connected_clients(self):
     # Get list of clients from ServerConnector
     cmsg = measpb.SessionMsg()
     cmsg.type = measpb.SessionMsg.CALL
     add_attr(cmsg, "funcname", ServerConnector.CALL_GETCLIENTS)
     self.pipe.send(cmsg.SerializeToString())
     rmsg = measpb.SessionMsg()
     rmsg.ParseFromString(self.pipe.recv())
     return rmsg.clients
Beispiel #2
0
 def send_init(self):
     self._connect()
     msg = measpb.SessionMsg()
     msg.type = measpb.SessionMsg.INIT
     msg.sid = self.sid
     self._add_attr(msg, "clientname", self.name)
     self._send_msg(self.sock, msg)
Beispiel #3
0
 def encode(self, **kwargs):
     cmsg = measpb.SessionMsg()
     cmsg.type = measpb.SessionMsg.CALL
     add_attr(cmsg, 'funcname', self.funcname)
     for aname, adict in self.funcargs.items():
         if aname in kwargs:
             add_attr(cmsg, aname, kwargs[aname])
     return cmsg
Beispiel #4
0
 def _get_msg_from_sock(self, conn):
     smsg = None
     ldata = conn.recv(4)
     if ldata:
         mlen = struct.unpack(">L", ldata)[0]
         mbuf = conn.recv(mlen)
         smsg = measpb.SessionMsg()
         smsg.ParseFromString(mbuf)
     return smsg
Beispiel #5
0
 def __del__(self):
     if self.sock:
         msg = measpb.SessionMsg()
         msg.type = measpb.SessionMsg.CLOSE
         try:
             self._send_msg(self.sock, msg)
             self.sock.close()
         except:
             pass
Beispiel #6
0
def main():
    conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    conn.connect((CONN_IP, CONN_PORT))
    msg = measpb.SessionMsg()
    msg.type = measpb.SessionMsg.INIT
    send_msg(conn, msg)
    msg.type = measpb.SessionMsg.CLOSE
    send_msg(conn, msg)
    #time.sleep(1)
    conn.close()
    exit(0)
Beispiel #7
0
    def run(self):
        (c1, c2) = mp.Pipe()
        self.pipe = c1
        self.netproc = mp.Process(target=self.connector.run,
                                  args=(c2, self.logger))
        self.netproc.start()

        while True:
            msg = measpb.SessionMsg()
            msg.ParseFromString(self.pipe.recv())
            func = get_attr(msg, "funcname")
            if func in self.CALLS:
                args = RPCCALLS[func].decode(msg)
                rmsg = measpb.SessionMsg()
                rmsg.type = measpb.SessionMsg.RESULT
                add_attr(rmsg, "funcname", func)
                if func.startswith('seq'):
                    self._do_seq(args, rmsg, self.CALLS[func])
                else:
                    self.CALLS[func](self, args, rmsg)
                self.pipe.send(rmsg.SerializeToString())
            else:
                self.logger.error("Unknown function called: %s" % func)
Beispiel #8
0
 def _get_msg_from_sock(self, conn):
     smsg = None
     ldata = conn.recv(4)
     if ldata:
         mlen = struct.unpack(">L", ldata)[0]
         mbuf = bytearray()
         while len(mbuf) < mlen:
             rd, wt, xt = select.select([conn], [], [], 1)
             if not rd:
                 self.logger.warning("No data ready for read from socket.")
             mbuf += conn.recv(mlen - len(mbuf))
         self.logger.debug("Received %d, indicated size %d." % (len(mbuf), mlen))
         smsg = measpb.SessionMsg()
         smsg.ParseFromString(mbuf)
     return smsg
Beispiel #9
0
 def cmd_waitres(self, cmd):
     clients = self._get_client_list(cmd)
     waittime = time.time() + cmd['timeout']
     self.last_results = []
     self.logger.info("Waiting for clients: %s" % clients)
     while time.time() < waittime and len(clients):
         if self.pipe.poll(self.POLLTIME):
             rmsg = measpb.SessionMsg()
             rmsg.ParseFromString(self.pipe.recv())
             clientname = get_attr(rmsg, "clientname")
             self.logger.info("Received result from: %s", clientname)
             for i in range(len(clients)):
                 if clients[i] == clientname:
                     self.last_results.append(rmsg)
                     del clients[i]
                     break
Beispiel #10
0
 def _readpipe(self, pipe, mask):
         msg = measpb.SessionMsg()
         msg.ParseFromString(pipe.recv())
         self.DISPATCH[msg.type](self, msg, pipe)
Beispiel #11
0
 def get_clients(self, msg):
     rmsg = measpb.SessionMsg()
     #rmsg.uuid = msg.uuid
     rmsg.type = measpb.SessionMsg.RESULT
     rmsg.clients.extend([cli.name for cli in self.clients.values()])
     return rmsg