feat(election-iomgr-refactor): add on_connected fire-once callback to endpoint_t

Add void (*on_connected)(endpoint_t *ep) field to endpoint_t with
endpoint_set_on_connected() helper. io_handler fires it exactly once
immediately after ssl_handshake_done=1 then nulls the pointer.

Enables ha_start_election_async to send OP_requestVote as soon as
the TLS handshake with a peer completes — no blocking SSL_connect.

6 new unit tests pass; controller suite 1/1 OK.
This commit is contained in:
Rongsong Shen 2026-05-30 07:34:08 +00:00
parent 4737b0f8a3
commit c3caab49a6
5 changed files with 205 additions and 1 deletions

View file

@ -438,6 +438,10 @@ static int handle_ssl_handshake(endpoint_t* ep)
rc = SSL_do_handshake(ep->ssl);
if (rc == 1) {
ep->ssl_handshake_done = 1;
if (ep->on_connected) {
ep->on_connected(ep);
ep->on_connected = NULL;
}
return 1;
}
@ -772,6 +776,19 @@ int endpoint_set_err_handler(endpoint_t* ep, err_handler_t h)
return 1;
}
int endpoint_set_on_connected(endpoint_t* ep, void (*cb)(endpoint_t*))
{
if (ep == NULL) {
return -EINVAL;
}
mylock_lock(&(ep->lock));
ep->on_connected = cb;
mylock_unlock(&(ep->lock));
return 0;
}
int endpoint_enq(endpoint_t* ep, data_item_t* it)
{
int rc = 0;