in tls/s2n_handshake_io.c [849:895]
static int s2n_advance_message(struct s2n_connection *conn)
{
/* Get the mode: 'C'lient or 'S'erver */
char previous_writer = ACTIVE_STATE(conn).writer;
char this_mode = CONNECTION_WRITER(conn);
/* Actually advance the message number */
conn->handshake.message_number++;
/* When reading and using TLS1.3, skip optional change_cipher_spec states. */
if (ACTIVE_STATE(conn).writer != this_mode && EXPECTED_RECORD_TYPE(conn) == TLS_CHANGE_CIPHER_SPEC && IS_TLS13_HANDSHAKE(conn)) {
conn->handshake.message_number++;
}
/* Set TCP_QUICKACK to avoid artificial delay during the handshake */
POSIX_GUARD(s2n_socket_quickack(conn));
/* If optimized io hasn't been enabled or if the caller started out with a corked socket,
* we don't mess with it
*/
if (!conn->corked_io || s2n_socket_was_corked(conn)) {
return S2N_SUCCESS;
}
/* Are we changing I/O directions */
if (ACTIVE_STATE(conn).writer == previous_writer || ACTIVE_STATE(conn).writer == 'A') {
return S2N_SUCCESS;
}
/* We're the new writer */
if (ACTIVE_STATE(conn).writer == this_mode) {
if (s2n_connection_is_managed_corked(conn)) {
/* Set TCP_CORK/NOPUSH */
POSIX_GUARD(s2n_socket_write_cork(conn));
}
return S2N_SUCCESS;
}
/* We're the new reader, or we reached the "B" writer stage indicating that
we're at the application data stage - uncork the data */
if (s2n_connection_is_managed_corked(conn)) {
POSIX_GUARD(s2n_socket_write_uncork(conn));
}
return S2N_SUCCESS;
}