Пример #1
0
 def heartbeat_sender(self, sock, addr, socklock, parent):
     try:
         with closing(sock):
             while True:
                 self.heartbeat_event.wait()
                 pkt = makepacket(PacketType.PORT_AGENT_HEARTBEAT, ntp.now(), "")
                 with socklock:
                     sock.sendall(pkt)
                 sleep()
     except socket.error, e:
         log.debug("heartbeat socket err: %s" % e)
Пример #2
0
 def test_both(self):
     timestamp = 123.456
     msgtype = 222
     data = "hello, world."
     txpktbuf = makepacket(msgtype, timestamp, data)
     rxpktbuf = txpktbuf
     rxpktobj = ReceivedPacket(rxpktbuf[:HEADER_SIZE])
     rxpktobj.validate(rxpktbuf[HEADER_SIZE:])
     self.assertEquals(timestamp, rxpktobj.timestamp)
     self.assertEquals(msgtype, rxpktobj.msgtype)
     self.assertEquals(data, rxpktobj.data)
Пример #3
0
 def work(self, sock, addr):
     socklock = Semaphore()
     heartbeat = spawn(self.heartbeat_sender, sock, addr, socklock, getcurrent())
     heartbeat.link_exception(self.janitor)
     try:
         with self.subscription() as queue:
             while True:
                 orbpkt, timestamp = queue.get()
                 pkt = makepacket(PacketType.DATA_FROM_INSTRUMENT, timestamp, orbpkt)
                 with socklock:
                     sock.sendall(pkt)
     finally:
         try:
             heartbeat.kill()
         except:
             pass
Пример #4
0
 def ping(self, val, sock):
     msg = "pong. version: " + __version__
     sock.sendall(makepacket(PacketType.PORT_AGENT_STATUS, ntp.now(), msg))
Пример #5
0
 def get_state(self, val, sock):
     statestr = self.states[self.state]
     sock.sendall(makepacket(PacketType.PORT_AGENT_STATUS, ntp.now(), statestr))
Пример #6
0
 def test_makepacket(self):
     r = makepacket(0, 12345, [])
     self.assertEquals(len(r), 16)
     self.assertEquals([r[6], r[7]], [0x0, 0x40])
     self.assertEquals(r, TESTPKT1)