}
/** Add a callback to be executed after a state function has been called
+ *
+ * Where a user callback is executed on state change, the post function
+ * is only called if the callback succeeds.
*
* @param[in] conn to add watcher to.
* @param[in] state to call watcher on entering.
{
if (state >= FR_CONNECTION_STATE_MAX) return;
- connection_add_watch(conn, &conn->watch_pre[state], watch, oneshot, uctx);
+ connection_add_watch(conn, &conn->watch_post[state], watch, oneshot, uctx);
}
/** Close a connection if it's freed
} else {
ret = FR_CONNECTION_STATE_CONNECTED;
}
- WATCH_POST(conn);
-
switch (ret) {
/*
*/
case FR_CONNECTION_STATE_CONNECTED:
DEBUG2("Connection established");
+ WATCH_POST(conn); /* Only call if we successfully connected */
return;
/*
} else {
ret = FR_CONNECTION_STATE_CONNECTING;
}
- WATCH_POST(conn);
switch (ret) {
case FR_CONNECTION_STATE_CONNECTING:
conn->is_closed = false; /* We now have a handle */
+ WATCH_POST(conn); /* Only call if we successfully initialised the handle */
connection_state_connecting_enter(conn);
return;