import socket


def set_socket_io_timeouts(transport, seconds, useconds=0):
    """
        Set timeout for transport sockets.
        Useful with highly concurrent workloads.

        Returns False if it failed to set the timeouts.
    """
    seconds = (seconds).to_bytes(8, 'little')
    useconds = (useconds).to_bytes(8, 'little')
    sock = transport.get_extra_info('socket')
    try:
        sock.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_RCVTIMEO,
            seconds + useconds,
        )
        sock.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_SNDTIMEO,
            seconds + useconds,
        )
        return True
    except OSError:
        return False