public ChannelEvent nextEvent()
        throws ChannelError, InterruptedException {
        ChannelEvent event;
        ChannelError error;

        if ((error = resetError()) != null) {
            throw error;
        }

        if ((event = resetEndEvent()) != null) {
            return event;
        }

        event = m_eventQueue.poll();

        if (event == null) {
            m_waitLock.acquire();
            return nextEvent();
        }

        return event;
    }