Skip to content

Commit

Permalink
try to fix TFO on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
bradh352 committed Aug 17, 2024
1 parent 4fbffd8 commit ca8441a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib/ares__socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ ares_status_t ares__open_connection(ares_conn_t **conn_out,
ares_conn_t *conn;
ares__llist_node_t *node = NULL;
int stype = is_tcp ? SOCK_STREAM : SOCK_DGRAM;
ares_conn_state_flags_t state_flags;

*conn_out = NULL;

Expand Down Expand Up @@ -935,9 +936,19 @@ ares_status_t ares__open_connection(ares_conn_t **conn_out,
/* LCOV_EXCL_STOP */
}

ares__conn_sock_state_cb_update(
conn, ARES_CONN_STATE_READ |
(is_tcp ? ARES_CONN_STATE_WRITE : ARES_CONN_STATE_NONE));
state_flags = ARES_CONN_STATE_READ;

/* Get notified on connect if using TCP without TFO with a write event.
* If TFO is enabled, the write operation itself will turn this on. We don't
* want to prematurely turn on waiting on a write event because of the delayed
* flushing that can occur for TCP, that operation will enable waiting on the
* write event */
if (conn->flags & ARES_CONN_FLAG_TCP &&
!(conn->flags & ARES_CONN_FLAG_TFO_INITIAL)) {
state_flags |= ARES_CONN_STATE_WRITE;
}

ares__conn_sock_state_cb_update(conn, state_flags);

if (is_tcp) {
server->tcp_conn = conn;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ares_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ fprintf(stderr, "%s(): fd=%d wrote %d bytes\n", __FUNCTION__, (int)conn->fd, (in

done:
if (status == ARES_SUCCESS) {
/* When using TFO, the we need to enabling waiting on a write event to
* be notified of when a connection is actually established */
ares__conn_sock_state_cb_update(conn, ARES_CONN_STATE_READ |
(tfo?ARES_CONN_STATE_WRITE:ARES_CONN_STATE_NONE));
}
Expand Down

0 comments on commit ca8441a

Please sign in to comment.