def _sendBytes(self, bytes=''): """\ Send bytes onto the socket. """ if self.debug and len(bytes) > 0: green("Sending: %s \n" % xstruct.hexbyte(bytes)) self.transport.write(bytes)
def __recvBytes(self): """\ Receive a bunch of bytes onto the socket. """ buffer = self.buffered['bytes-received'] try: data = self.s.recv(BUFFER_SIZE) if data == '': raise IOError("Socket.recv returned no data, connection must have been closed...") if self.debug and len(data) > 0: red("Received: %s \n" % xstruct.hexbyte(data)) buffer.write(data) except socket.error, e: pass
def __recvBytes(self): """\ Receive a bunch of bytes onto the socket. """ buffer = self.buffered['bytes-received'] try: data = self.s.recv(BUFFER_SIZE) if data == '': raise IOError( "Socket.recv returned no data, connection must have been closed..." ) if self.debug and len(data) > 0: red("Received: %s \n" % xstruct.hexbyte(data)) buffer.write(data) except socket.error, e: pass
def dataReceived(self, data): """\ """ if self.debug and len(data) > 0: red("Received: %s \n" % xstruct.hexbyte(data)) # Push the data onto the buffer buffer = self.buffered['bytes-received'] buffer.write(data) self._recvFrame(-1) sequences = self.buffered['frames-received'].keys() sequences.sort() for sequence in sequences: p = self._recvFrame(sequence) if not p: continue bases = [p.__class__] while len(bases) > 0: c = bases.pop(0) function = "On" + c.__name__ if hasattr(self, function): try: success = getattr(self, function)(p) except: type, val, tb = sys.exc_info() print ''.join(traceback.format_exception(type, val, tb)) break else: print "No handler for packet of %s" % c.__name__ bases += list(c.__bases__) if len(bases) == 0: self._sendFrame(Fail(p.sequence, 2, "Service Unavailable..."))
def __sendBytes(self): """\ Send a bunch of bytes onto the socket. """ buffer = self.buffered['bytes-tosend'] sent = 0 try: if len(buffer) > 0: sent = self.s.send(buffer.read(len(buffer))) except socket.error, e: if self.debug: print "Send Socket Error", e if self.debug and sent > 0: green("Sending: %s \n" % xstruct.hexbyte(buffer.peek(sent))) def fileno(self): """\ Returns the file descriptor number. """ # This is cached so our fileno doesn't go away when the socket dies.. if not hasattr(self, "_fileno"): self._fileno = self.s.fileno() return self._fileno def pump(self): """\ Causes the connection to read and process stuff from the buffer. This will allow you to read out of band messages.