'read n bytes from socket stream'

def _readn(self, n):

    nwant = n
    while True:
        try:
            data = self.s.recv(nwant)
        except socket.error as ex:
            if (ex[0] == 10035):
                continue
            elif (ex[0] == 10054):
                self._logger.exception(u'converted    to    EOF')
                return ''
            else:
                raise ex
        self._logger.debug(u'_readn    got    %d    bytes', len(data))
        if (len(data) == 0):
            return data
        nwant -= len(data)
        self.buffer.write(data)
        if (nwant == 0):
            break
    self.buffer.seek(0)
    data = self.buffer.read(n)
    self.buffer.seek(0)
    return data
