'Reads all pending incoming data.
In case of disconnection calls owner\'s disconnected() method and then raises IOError exception.'

def receive(self):

    try:
        received = self._recv(BUFLEN)
    except socket.sslerror as e:
        self._seen_data = 0
        if (e[0] == socket.SSL_ERROR_WANT_READ):
            return ''
        if (e[0] == socket.SSL_ERROR_WANT_WRITE):
            return ''
        self.DEBUG('Socket    error    while    receiving    data', 'error')
        sys.exc_clear()
        self._owner.disconnected()
        raise IOError('Disconnected    from    server')
    except:
        received = ''
    while self.pending_data(0):
        try:
            add = self._recv(BUFLEN)
        except:
            add = ''
        received += add
        if (not add):
            break
    if len(received):
        self._seen_data = 1
        self.DEBUG(received, 'got')
        if hasattr(self._owner, 'Dispatcher'):
            self._owner.Dispatcher.Event('', DATA_RECEIVED, received)
    else:
        self.DEBUG('Socket    error    while    receiving    data', 'error')
        self._owner.disconnected()
        raise IOError('Disconnected    from    server')
    return received
