{
ssize_t rc;
+ if (conn->state == CONN_STATE_WATCHING)
+ /* The connection cannot be used anymore. */
+ return SET_ERROR(conn, LLDPCTL_ERR_INVALID_STATE);
+
if (conn->state == CONN_STATE_IDLE) {
/* We need to build the message to send, then send
* it. */
if (rc == 0) {
conn->watch_cb = cb;
conn->watch_data = data;
+ conn->state = CONN_STATE_WATCHING;
}
return rc;
}
RESET_ERROR(conn);
- if (conn->state != CONN_STATE_IDLE)
+ if (conn->state != CONN_STATE_WATCHING)
return SET_ERROR(conn, LLDPCTL_ERR_INVALID_STATE);
conn->watch_triggered = 0;
#define CONN_STATE_GET_CHASSIS_RECV 14
#define CONN_STATE_GET_DEFAULT_PORT_SEND 15
#define CONN_STATE_GET_DEFAULT_PORT_RECV 16
+#define CONN_STATE_WATCHING 17
int state; /* Current state */
/* Data attached to the state. It is used to check that we are using the
* same data as a previous call until the state machine goes to
return conn->input_buffer_len;
}
-int lldpctl_process_conn_buffer(lldpctl_conn_t *conn)
+int
+lldpctl_process_conn_buffer(lldpctl_conn_t *conn)
{
int rc;
* reference to it, be sure to increment the reference count in the callback.
*
* @warning The provided connection should not be used at all. Do not use @c
- * lldpctl_atom_set_*() functions on @c interface or @c neighbor either.
+ * lldpctl_atom_set_*() functions on @c interface or @c neighbor either. If you
+ * do, you will get a @c LLDPCTL_ERR_INVALID_STATE error.
*
* @see lldpctl_watch_callback
*/
* LLDPCTL_ERR_WOULDBLOCK.
*
* @warning Once a callback is registered, the connection shouldn't be used for
- * anything else than receiving notifications.
+ * anything else than receiving notifications. If you do, you will get a @c
+ * LLDPCTL_ERR_INVALID_STATE error.
*/
int lldpctl_watch_callback(lldpctl_conn_t *conn,
lldpctl_change_callback cb,