import socket
import errno


def ignore_eagain(func):
    """
    errno.EAGAIN is generated in some platforms when the socket is
    non-blocking. This decorator ignores this exception, as it's not an error.
    """

    def decorate(ret, *kargs):
        """
        Decorator.
        """
        try:
            return func(*kargs)
        except socket.error as error:
            if error.errno == errno.EAGAIN:
                return ret
            raise error

    return decorate