aboutsummaryrefslogtreecommitdiff
path: root/src/core/mainloop
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-07-16 10:07:21 -0400
committerNick Mathewson <nickm@torproject.org>2020-07-16 10:08:15 -0400
commit47a48e2f5a384450679a544e7a1f26f378a26a78 (patch)
treea9848573bd201bca1017fd711f6388328dbe6f32 /src/core/mainloop
parentb0d7b100886ef14a785f6ca1de968df9a884d0a7 (diff)
downloadtor-47a48e2f5a384450679a544e7a1f26f378a26a78.tar.gz
tor-47a48e2f5a384450679a544e7a1f26f378a26a78.zip
Define new CONST_TO_*_CONN() functions for const-to-const casts
These names are analogous to the CONST_TO_*_CIRC() functions we have for circuits. Part of #40046.
Diffstat (limited to 'src/core/mainloop')
-rw-r--r--src/core/mainloop/connection.c12
-rw-r--r--src/core/mainloop/connection.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 216aeb68d1..20e38ac44b 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -233,6 +233,18 @@ TO_LISTENER_CONN(connection_t *c)
return DOWNCAST(listener_connection_t, c);
}
+/**
+ * Cast a `const connection_t *` to a `const listener_connection_t *`.
+ *
+ * Exit with an assertion failure if the input is not a
+ * `listener_connection_t`.
+ **/
+const listener_connection_t *
+CONST_TO_LISTENER_CONN(const connection_t *c)
+{
+ return TO_LISTENER_CONN((connection_t *)c);
+}
+
size_t
connection_get_inbuf_len(connection_t *conn)
{
diff --git a/src/core/mainloop/connection.h b/src/core/mainloop/connection.h
index af45007676..ee3dce49f4 100644
--- a/src/core/mainloop/connection.h
+++ b/src/core/mainloop/connection.h
@@ -31,6 +31,8 @@ struct tor_addr_t;
struct or_options_t;
struct listener_connection_t *TO_LISTENER_CONN(struct connection_t *);
+const struct listener_connection_t *CONST_TO_LISTENER_CONN(
+ const struct connection_t *);
struct buf_t;