diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-11-23 20:52:24 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-12-21 14:48:38 -0500 |
commit | b884ae6d98d0fd684bc93aa48a0da656ea1849b7 (patch) | |
tree | 63a1fccce15decb35b0074d7c1f18e91c3d99ba5 /src/or | |
parent | ab08d8c4f7a4a6120756e964a086219a1dc3aaa2 (diff) | |
download | tor-b884ae6d98d0fd684bc93aa48a0da656ea1849b7.tar.gz tor-b884ae6d98d0fd684bc93aa48a0da656ea1849b7.zip |
Using macros and inline function for quick lookup of channel state.
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/channel.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/or/channel.h b/src/or/channel.h index 4cd8f4391e..5a2431b30a 100644 --- a/src/or/channel.h +++ b/src/or/channel.h @@ -431,6 +431,39 @@ channel_t * channel_find_by_remote_digest(const char *identity_digest); channel_t * channel_next_with_digest(channel_t *chan); /* + * Helper macros to lookup state of given channel. + */ + +#define CHANNEL_IS_CLOSED(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_CLOSED)) +#define CHANNEL_IS_OPENING(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_OPENING)) +#define CHANNEL_IS_OPEN(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_OPEN)) +#define CHANNEL_IS_MAINT(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_MAINT)) +#define CHANNEL_IS_CLOSING(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_CLOSING)) +#define CHANNEL_IS_ERROR(chan) (channel_is_in_state((chan), \ + CHANNEL_STATE_ERROR)) + +#define CHANNEL_FINISHED(chan) (CHANNEL_IS_CLOSED(chan) || \ + CHANNEL_IS_ERROR(chan)) + +#define CHANNEL_CONDEMNED(chan) (CHANNEL_IS_CLOSING(chan) || \ + CHANNEL_FINISHED(chan)) + +#define CHANNEL_CAN_HANDLE_CELLS(chan) (CHANNEL_IS_OPENING(chan) || \ + CHANNEL_IS_OPEN(chan) || \ + CHANNEL_IS_MAINT(chan)) + +static INLINE int +channel_is_in_state(channel_t *chan, channel_state_t state) +{ + return chan->state == state; +} + +/* * Metadata queries/updates */ |