def _recvMsg(self): r, _, _ = select.select([self.s], [], [], self.timeout) if r: response = "" while not response.endswith("\r\n"): data = self.s.recv(1) if data == '': raise exceptions.EOFError("Got empty data (remote died?). from {0}".format(self.host)) response += data return response[:-2] else: raise exceptions.EOFError("Timeout waiting for socket recv. from {0}".format(self.host))
def _recvData(self, length): r, _, _ = select.select([self.s], [], [], self.timeout) if r: response = "" while len(response) < length + 2: data = self.s.recv((length + 2) - len(response)) if data == '': raise exceptions.EOFError("Got empty data (remote died?). from {0}".format(self.host)) response += data return response[:-2] else: raise exceptions.EOFError("Timeout waiting for socket recv. from {0}".format(self.host))
def _sendMsg(self, cmd): _, w, _ = select.select([], [self.s], [], self.timeout) if w: self.s.send(cmd) else: raise exceptions.EOFError( "Timeout waiting for socket send. from {0}".format(self.host))
def _recvMsg(self): response = "" while len(response) < MIN_RECV_PACKET: data = self._socketRecv(MIN_RECV_PACKET - len(response)) if data == '': raise exceptions.EOFError("Got empty data (remote died?).") response += data assert len(response) == MIN_RECV_PACKET magic, cmd, keylen, extralen, dtype, errcode, remaining, opaque, cas=\ struct.unpack(RES_PKT_FMT, response) rv = "" while remaining > 0: data = self._socketRecv(remaining) if data == '': raise exceptions.EOFError("Got empty data (remote died?).") rv += data remaining -= len(data) assert (magic in (RES_MAGIC_BYTE, REQ_MAGIC_BYTE)), "Got magic: %d" % magic return cmd, errcode, opaque, cas, keylen, extralen, rv