Use typedefs for function pointer return values and s/listener/listener_fn/ for distinctness

This commit is contained in:
Andrea Shepard 2012-10-08 20:49:19 -07:00
parent ee4e88e4d9
commit 89a00ee63a
No known key found for this signature in database
GPG Key ID: 80BF498218A1E61B
3 changed files with 31 additions and 28 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);
}