[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Use typedefs for function pointer return values and s/listener/listener_fn/ for distinctness



commit 89a00ee63ae61e707343432dd9f74702cf60ac3c
Author: Andrea Shepard <andrea@xxxxxxxxxxxxxx>
Date:   Mon Oct 8 20:49:19 2012 -0700

    Use typedefs for function pointer return values and s/listener/listener_fn/ for distinctness
---
 src/or/channel.c |   25 +++++++++++--------------
 src/or/channel.h |   32 +++++++++++++++++++-------------
 src/or/command.c |    2 +-
 3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index cdb0830..9fbfecb 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -823,9 +823,8 @@ channel_force_free(channel_t *chan)
  * @return Function pointer to an incoming channel handler
  */
 
-void
-(* channel_get_listener(channel_t *chan))
-  (channel_t *, channel_t *)
+channel_listener_fn_ptr
+channel_get_listener_fn(channel_t *chan)
 {
   tor_assert(chan);
   tor_assert(chan->is_listener);
@@ -847,8 +846,8 @@ void
  */
 
 void
-channel_set_listener(channel_t *chan,
-                     void (*listener)(channel_t *, channel_t *) )
+channel_set_listener_fn(channel_t *chan,
+                        channel_listener_fn_ptr listener)
 {
   tor_assert(chan);
   tor_assert(chan->is_listener);
@@ -872,9 +871,8 @@ channel_set_listener(channel_t *chan,
  * @return A function pointer to chan's fixed-length cell handler, if any.
  */
 
-void
-(* channel_get_cell_handler(channel_t *chan))
-  (channel_t *, cell_t *)
+channel_cell_handler_fn_ptr
+channel_get_cell_handler(channel_t *chan)
 {
   tor_assert(chan);
   tor_assert(!(chan->is_listener));
@@ -897,9 +895,8 @@ void
  * @return A function pointer to chan's variable-length cell handler, if any.
  */
 
-void
-(* channel_get_var_cell_handler(channel_t *chan))
-  (channel_t *, var_cell_t *)
+channel_var_cell_handler_fn_ptr
+channel_get_var_cell_handler(channel_t *chan)
 {
   tor_assert(chan);
   tor_assert(!(chan->is_listener));
@@ -927,9 +924,9 @@ void
 
 void
 channel_set_cell_handlers(channel_t *chan,
-                          void (*cell_handler)(channel_t *, cell_t *),
-                          void (*var_cell_handler)(channel_t *,
-                                                   var_cell_t *))
+                          channel_cell_handler_fn_ptr cell_handler,
+                          channel_var_cell_handler_fn_ptr
+                            var_cell_handler)
 {
   int try_again = 0;
 
diff --git a/src/or/channel.h b/src/or/channel.h
index 696ae07..70ea30f 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -11,6 +11,11 @@
 
 #include "or.h"
 
+/* Channel handler function pointer typedefs */
+typedef void (*channel_listener_fn_ptr)(channel_t *, channel_t *);
+typedef void (*channel_cell_handler_fn_ptr)(channel_t *, cell_t *);
+typedef void (*channel_var_cell_handler_fn_ptr)(channel_t *, var_cell_t *);
+
 /*
  * Channel struct; see the channel_t typedef in or.h.  A channel is an
  * abstract interface for the OR-to-OR connection, similar to connection_or_t,
@@ -65,7 +70,7 @@ struct channel_s {
   union {
     struct {
       /* Registered listen handler to call on incoming connection */
-      void (*listener)(channel_t *, channel_t *);
+      channel_listener_fn_ptr listener;
 
       /* List of pending incoming connections */
       smartlist_t *incoming_list;
@@ -78,8 +83,8 @@ struct channel_s {
     } listener;
     struct {
       /* Registered handlers for incoming cells */
-      void (*cell_handler)(channel_t *, cell_t *);
-      void (*var_cell_handler)(channel_t *, var_cell_t *);
+      channel_cell_handler_fn_ptr cell_handler;
+      channel_var_cell_handler_fn_ptr var_cell_handler;
 
       /* Methods implemented by the lower layer */
 
@@ -238,19 +243,20 @@ void channel_write_var_cell(channel_t *chan, var_cell_t *cell);
 /* Channel callback registrations */
 
 /* Listener callback */
-void (* channel_get_listener(channel_t *chan))(channel_t *, channel_t *);
-void channel_set_listener(channel_t *chan,
-                          void (*listener)(channel_t *, channel_t *) );
+channel_listener_fn_ptr channel_get_listener_fn(channel_t *chan);
+void channel_set_listener_fn(channel_t *chan,
+                             channel_listener_fn_ptr listener);
 
 /* Incoming cell callbacks */
-void (* channel_get_cell_handler(channel_t *chan))
-  (channel_t *, cell_t *);
-void (* channel_get_var_cell_handler(channel_t *chan))
-  (channel_t *, var_cell_t *);
+channel_cell_handler_fn_ptr channel_get_cell_handler(channel_t *chan);
+
+channel_var_cell_handler_fn_ptr
+channel_get_var_cell_handler(channel_t *chan);
+
 void channel_set_cell_handlers(channel_t *chan,
-                               void (*cell_handler)(channel_t *, cell_t *),
-                               void (*var_cell_handler)(channel_t *,
-                                                        var_cell_t *));
+                               channel_cell_handler_fn_ptr cell_handler,
+                               channel_var_cell_handler_fn_ptr
+                                 var_cell_handler);
 
 /* Clean up closed channels periodically; called from run_scheduled_events()
  * in main.c
diff --git a/src/or/command.c b/src/or/command.c
index 351ab08..2fb70b5 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -505,6 +505,6 @@ command_setup_listener(channel_t *listener)
   tor_assert(listener);
   tor_assert(listener->state == CHANNEL_STATE_LISTENING);
 
-  channel_set_listener(listener, command_handle_incoming_channel);
+  channel_set_listener_fn(listener, command_handle_incoming_channel);
 }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits