[cmaster-next] [PATCH 1/2] isisd: use a smaller #ifdef for isis_receive()

Renato Westphal renato at opensourcerouting.org
Mon Nov 28 16:02:17 EST 2016


There's no need to provide two definitions of the isis_receive()
function (one for GNU_LINUX and the other for !GNU_LINUX). Both differ
only slightly so it makes more sense to define isis_receive() just once
and use a smaller #ifdef to account for these differences. This improves
code readability.

Signed-off-by: Renato Westphal <renato at opensourcerouting.org>
---
 isisd/isis_pdu.c | 40 ++++------------------------------------
 1 file changed, 4 insertions(+), 36 deletions(-)

diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c
index 1dfb462..39d2df7 100644
--- a/isisd/isis_pdu.c
+++ b/isisd/isis_pdu.c
@@ -2139,7 +2139,6 @@ isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa)
   return retval;
 }
 
-#ifdef GNU_LINUX
 int
 isis_receive (struct thread *thread)
 {
@@ -2153,10 +2152,11 @@ isis_receive (struct thread *thread)
   circuit = THREAD_ARG (thread);
   assert (circuit);
 
+  circuit->t_read = NULL;
+
   isis_circuit_stream(circuit, &circuit->rcv_stream);
 
   retval = circuit->rx (circuit, ssnpa);
-  circuit->t_read = NULL;
 
   if (retval == ISIS_OK)
     retval = isis_handle_pdu (circuit, ssnpa);
@@ -2166,52 +2166,20 @@ isis_receive (struct thread *thread)
    */
   if (!circuit->is_passive)
   {
+#ifdef GNU_LINUX
     THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
                     circuit->fd);
-  }
-
-  return retval;
-}
-
 #else
-int
-isis_receive (struct thread *thread)
-{
-  struct isis_circuit *circuit;
-  u_char ssnpa[ETH_ALEN];
-  int retval;
-
-  /*
-   * Get the circuit 
-   */
-  circuit = THREAD_ARG (thread);
-  assert (circuit);
-
-  circuit->t_read = NULL;
-
-  isis_circuit_stream(circuit, &circuit->rcv_stream);
-
-  retval = circuit->rx (circuit, ssnpa);
-
-  if (retval == ISIS_OK)
-    retval = isis_handle_pdu (circuit, ssnpa);
-
-  /* 
-   * prepare for next packet. 
-   */
-  if (!circuit->is_passive)
-  {
     circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit,
   					     listcount
 					     (circuit->area->circuit_list) *
 					     100);
+#endif
   }
 
   return retval;
 }
 
-#endif
-
  /* filling of the fixed isis header */
 void
 fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type)
-- 
1.9.1





More information about the dev mailing list