Ejemplo n.º 1
0
def run(t1: Place) -> None:
    Requires(token(t1, 2) and listener_io(t1))
    Ensures(False)

    Open(listener_io(t1))

    server_socket, t_loop = create_server_socket(t1)

    while True:
        Invariant(
            token(t_loop, 1) and
            listener_loop_io(t_loop, server_socket) and
            server_socket != None
        )

        Open(listener_loop_io(t_loop, server_socket))

        client_socket, t3 = accept(t_loop, server_socket)

        data, t4 = read_all(t3, client_socket, timeout=1)

        Open(output_io(t4, client_socket, data))

        if data is not None:
            t5, t6 = Split(t4)

            t7 = print_int(t6, get_address(client_socket))

            t8 = send(t5, client_socket, data)

            t9 = Join(t8, t7)
        else:
            t9 = NoOp(t4)

        t_loop = close(t9, client_socket)
Ejemplo n.º 2
0
def handle_client(client_socket: Socket, t1: Place) -> None:
    Requires(client_socket is not None)
    Requires(token(t1, 2) and handle_client_io(t1, client_socket))
    Requires(MustTerminate(2))

    Open(handle_client_io(t1, client_socket))

    data, t4 = read_all(t1, client_socket, timeout=1)

    Open(output_io(t4, client_socket, data))

    if data is not None:
        t5, t6 = Split(t4)

        t7 = print_int(t6, get_address(client_socket))

        t8 = send(t5, client_socket, data)

        t9 = Join(t8, t7)
    else:
        t9 = NoOp(t4)

    t10 = close(t9, client_socket)

    End(t10)
Ejemplo n.º 3
0
def test(t1: Place) -> Place:
    IOExists1(Place)(lambda t_end: (
        Requires(token(t1, 2) and test_io(t1, t_end)),
        Ensures(token(t_end) and t_end == Result()),
    ))

    Open(test_io(t1))

    t2 = NoOp(t1)
    t3, t4 = Split(t2)
    res, t5 = SetVar(t4, 1)
    t6 = Join(t3, t5)
    t_end = NoOp(t6)

    Assert(res == 1)

    return t_end
Ejemplo n.º 4
0
def run(t1: Place) -> None:
    Requires(token(t1, 2) and listener_io(t1))
    Ensures(False)

    Open(listener_io(t1))

    server_socket, t_loop = create_server_socket(t1)

    while True:
        Invariant(
            token(t_loop, 1) and listener_loop_io(t_loop, server_socket)
            and server_socket != None)

        Open(listener_loop_io(t_loop, server_socket))

        client_socket, t3 = accept(t_loop, server_socket)

        t4, t_loop = Split(t3)

        handle_client(client_socket, t4)