def response(self, pdu): if _debug: PickleActorMixIn._debug("response %r", pdu) # add the data to our buffer self.pickleBuffer += pdu.pduData # build a file-like object around the buffer strm = StringIO(self.pickleBuffer) pos = 0 while (pos < strm.len): try: # try to load something msg = cPickle.load(strm) except: break # got a message rpdu = PDU(msg) rpdu.update(pdu) super(PickleActorMixIn, self).response(rpdu) # see where we are pos = strm.tell() # save anything left over, if there is any if (pos < strm.len): self.pickleBuffer = self.pickleBuffer[pos:] else: self.pickleBuffer = ''
def handle_read(self): if _debug: deferred(TCPClient._debug, "handle_read") try: msg = self.recv(65536) if _debug: deferred(TCPClient._debug, " - received %d octets", len(msg)) self.socketError = None # no socket means it was closed if not self.socket: if _debug: deferred(TCPClient._debug, " - socket was closed") else: # sent the data upstream deferred(self.response, PDU(msg)) except socket.error, err: if (err.args[0] == 111): deferred(TCPClient._error, "connection to %r refused", self.peer) else: deferred(TCPClient._error, "TCPClient.handle_read socket error: %r", err) self.socketError = err
def handle_read(self): if _debug: deferred(UDPDirector._debug, "handle_read") try: msg, addr = self.socket.recvfrom(65536) if _debug: deferred(UDPDirector._debug, " - received %d octets from %s", len(msg), addr) # send the PDU up to the client deferred(self._response, PDU(msg, source=addr)) except socket.timeout, why: deferred(UDPDirector._error, "handle_read socket timeout: %s", why)
def Chop(addr): # get the current downstream buffer buff = streamBuffer.get(addr, '') + pdu.pduData # look for a packet while 1: packet = self.packetFn(buff) if packet is None: break yield PDU(packet[0], source=pdu.pduSource, destination=pdu.pduDestination) buff = packet[1] # save what didn't get sent streamBuffer[addr] = buff
def handle_read(self): deferred(ConsoleServer._debug, "handle_read") data = sys.stdin.read() deferred(ConsoleServer._debug, " - data: %r", data) deferred(self.response, PDU(data))
def handle_read(self): deferred(ConsoleClient._debug, "handle_read") data = sys.stdin.read() deferred(ConsoleClient._debug, " - data: %r", data) deferred(self.request, PDU(data))
def emit(self, msg, addr): if _debug: CommandLoggingClient._debug("emit %r %r", msg, addr) # pass downstream to the server self.request(PDU(msg, destination=addr))
def confirmation(self, pdu): if _debug: CommandLoggingClient._debug("confirmation %r", pdu) addr = pdu.pduSource resp = self.process_command(pdu.pduData, addr) self.request(PDU(resp, destination=addr))
def emit(self, msg, addr): if _debug: CommandLoggingServer._debug("emit %r %r", msg, addr) # pass upstream to the client self.response(PDU(msg, source=addr))
def indication(self, pdu): if _debug: CommandLoggingServer._debug("indication %r", pdu) addr = pdu.pduSource resp = self.process_command(pdu.pduData, addr) self.response(PDU(resp, source=addr))