From: Sam Tannous Date: Tue, 8 Jul 2014 19:15:49 +0000 (-0400) Subject: Add call to process more messages from data already read. X-Git-Tag: 0.7.10~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fa64c11d337c8aad5efdcca33ba50dce3aad580;p=thirdparty%2Flldpd.git Add call to process more messages from data already read. Currently, the calls within lldpctl are assumed to be all associated with synchronous sockets. With async sockets, the data read can be varied and so its useful to process as much of the data as possible. However, lldpctl_recv only processes one message and there isn't a call to be made to process data that's sitting in a control connection's buffer. This patch adds such a call for external users to call. It simply calls check_for_notification and returns whatever check_for_notification returns with 0 signalling more processing is possible and non-zero indicating buffer is fully processed (though there may still be data). Signed-off-by: Dinesh G Dutt Signed-off-by: Sam Tannous --- diff --git a/src/lib/connection.c b/src/lib/connection.c index 05bd5c61..f7525704 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -177,7 +177,7 @@ _lldpctl_needs(lldpctl_conn_t *conn, size_t length) return rc; } -static void +static int check_for_notification(lldpctl_conn_t *conn) { struct lldpd_neighbor_change *change; @@ -190,7 +190,7 @@ check_for_notification(lldpctl_conn_t *conn) NOTIFICATION, &p, &MARSHAL_INFO(lldpd_neighbor_change)); - if (rc != 0) return; + if (rc != 0) return rc; change = p; /* We have a notification, call the callback */ @@ -225,6 +225,9 @@ end: } free(change->ifname); free(change); + + /* Indicate if more data remains in the buffer for processing */ + return (rc); } ssize_t @@ -257,6 +260,17 @@ lldpctl_recv(lldpctl_conn_t *conn, const uint8_t *data, size_t length) return conn->input_buffer_len; } +int lldpctl_process_conn_buffer(lldpctl_conn_t *conn) +{ + int rc; + + rc = check_for_notification(conn); + + RESET_ERROR(conn); + + return rc; +} + ssize_t lldpctl_send(lldpctl_conn_t *conn) { diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index fa787c5f..f77af51b 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -160,6 +160,19 @@ ssize_t lldpctl_recv(lldpctl_conn_t *conn, const uint8_t *data, size_t length); */ ssize_t lldpctl_send(lldpctl_conn_t *conn); +/** + * Function invoked to see if there's more data to be processed in the buffer. + * + * This function should be invoked to check for notifications in the data that + * has already been read. Its used typically for asynchronous connections. + * + * @param conn Handle to the connection to lldpd. + * @return 0 to indicate maybe more data is available for processing + * !0 to indicate no data or insufficient data for processing + */ +int lldpctl_process_conn_buffer(lldpctl_conn_t *conn); + + /** * Allocate a new handler for connecting to lldpd. *