bool s2n_connection_check_io_status()

in tls/s2n_connection.c [1749:1789]


bool s2n_connection_check_io_status(struct s2n_connection *conn, s2n_io_status status)
{
    if (!conn) {
        return false;
    }

    bool read_closed = s2n_atomic_flag_test(&conn->read_closed);
    bool write_closed = s2n_atomic_flag_test(&conn->write_closed);
    bool full_duplex = !read_closed && !write_closed;

    /*
     *= https://www.rfc-editor.org/rfc/rfc8446#section-6.1
     *# Note that this is a change from versions of TLS prior to TLS 1.3 in
     *# which implementations were required to react to a "close_notify" by
     *# discarding pending writes and sending an immediate "close_notify"
     *# alert of their own.
     */
    if (s2n_connection_get_protocol_version(conn) < S2N_TLS13) {
        switch (status) {
            case S2N_IO_WRITABLE:
            case S2N_IO_READABLE:
            case S2N_IO_FULL_DUPLEX:
                return full_duplex;
            case S2N_IO_CLOSED:
                return !full_duplex;
        }
    }

    switch (status) {
        case S2N_IO_WRITABLE:
            return !write_closed;
        case S2N_IO_READABLE:
            return !read_closed;
        case S2N_IO_FULL_DUPLEX:
            return full_duplex;
        case S2N_IO_CLOSED:
            return read_closed && write_closed;
    }

    return false;
}