import socket


def create_async_server_socket(host, port, reuse: bool = False):
    """
    :param host:
    :param port:
    :param reuse: If true, allows shutting down the server and starting it up
        right away. Otherwise, we have to wait 1min before starting it up again
        https://stackoverflow.com/questions/4465959/python-errno-98-address-already-in-use
        In production, you'd want this set to `false`.
    :return:
    """
    # socket.socket, bind, accept, listen, send, (recv to do), close, shutdown
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if reuse:
        server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((host, port))
    server_socket.listen()
    server_socket.setblocking(False)
    return server_socket