'Handle recv events'

def _handle_recv(self):

    if (not (self._shadow_sock.EVENTS & POLLIN)):
        return
    f = None
    while self._recv_futures:
        (f, kind, kwargs, _) = self._recv_futures.popleft()
        f._pyzmq_popped = True
        if f.done():
            f = None
        else:
            break
    if (not self._recv_futures):
        self._drop_io_state(POLLIN)
    if (f is None):
        return
    if (kind == 'poll'):
        f.set_result(None)
        return
    elif (kind == 'recv_multipart'):
        recv = self._shadow_sock.recv_multipart
    elif (kind == 'recv'):
        recv = self._shadow_sock.recv
    else:
        raise ValueError(('Unhandled    recv    event    type:    %r' % kind))
    kwargs['flags'] |= _zmq.DONTWAIT
    try:
        result = recv(**kwargs)
    except Exception as e:
        f.set_exception(e)
    else:
        f.set_result(result)
