]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Add call to process more messages from data already read.
authorSam Tannous <stannous@cumulusnetworks.com>
Tue, 8 Jul 2014 19:15:49 +0000 (15:15 -0400)
committerVincent Bernat <vincent@bernat.im>
Tue, 8 Jul 2014 20:39:28 +0000 (22:39 +0200)
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 <ddutt@cumulusnetworks.com>
Signed-off-by: Sam Tannous <stannous@cumulusnetworks.com>
src/lib/connection.c
src/lib/lldpctl.h

index 05bd5c61d11eb40390b79c2c0733170f1e9d5083..f7525704d801c18a8abe4ca3cb48c7087d728109 100644 (file)
@@ -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)
 {
index fa787c5f3f0d96fb606dcc219b66507bc263fcf4..f77af51b0a8094266a329b5874affa84bf810ba6 100644 (file)
@@ -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.
  *