summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-04-03 05:22:33 +0000
committerNick Mathewson <nickm@torproject.org>2005-04-03 05:22:33 +0000
commit0dc02328afa5e6ec6c1799bd013476ae02db568f (patch)
tree55030b458ccd38032fce95b58b8da3e746d98549
parent2a332bf0b8ef1fb0cbe2958b8b129f77d58bc90e (diff)
downloadtor-0dc02328afa5e6ec6c1799bd013476ae02db568f.tar.gz
tor-0dc02328afa5e6ec6c1799bd013476ae02db568f.zip
Move most of *_mark_for_close out of macros.
svn:r3992
-rw-r--r--src/or/circuitlist.c17
-rw-r--r--src/or/connection.c17
-rw-r--r--src/or/connection_edge.c9
-rw-r--r--src/or/or.h37
4 files changed, 35 insertions, 45 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 563e01c190..1e60d48341 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -389,12 +389,20 @@ void circuit_mark_all_unused_circs(void) {
* - If circ->rend_splice is set (we are the midpoint of a joined
* rendezvous stream), then mark the other circuit to close as well.
*/
-int _circuit_mark_for_close(circuit_t *circ) {
+void _circuit_mark_for_close(circuit_t *circ, int line, const char *file)
+{
connection_t *conn;
assert_circuit_ok(circ);
- if (circ->marked_for_close)
- return -1;
+ tor_assert(line);
+ tor_assert(file);
+
+ if (circ->marked_for_close) {
+ log(LOG_WARN,"Duplicate call to circuit_mark_for_close at %s:%d"
+ " (first at %s:%d)", line, file,
+ circ->marked_for_close_file, circ->marked_for_close);
+ return;
+ }
if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
onion_pending_remove(circ);
@@ -441,7 +449,8 @@ int _circuit_mark_for_close(circuit_t *circ) {
for (conn=circ->p_streams; conn; conn=conn->next_stream)
connection_edge_destroy(circ->p_circ_id, conn);
- circ->marked_for_close = 1;
+ circ->marked_for_close = line;
+ circ->marked_for_close_file = file;
if (circ->rend_splice && !circ->rend_splice->marked_for_close) {
/* do this after marking this circuit, to avoid infinite recursion. */
diff --git a/src/or/connection.c b/src/or/connection.c
index ee51ef8d9c..43fbea35cf 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -336,28 +336,31 @@ void connection_close_immediate(connection_t *conn)
/** Mark <b>conn</b> to be closed next time we loop through
* conn_close_if_marked() in main.c. */
-int
-_connection_mark_for_close(connection_t *conn)
+void
+_connection_mark_for_close(connection_t *conn, int line, const char *file)
{
assert_connection_ok(conn,0);
+ tor_assert(line);
+ tor_assert(file);
if (conn->marked_for_close) {
- log(LOG_WARN, "Bug: Double mark-for-close on connection.");
+ log(LOG_WARN, "Duplicate call to connection_mark_for_close at %s:%d"
+ " (first at %s:%d)", file, line, conn->marked_for_close_file,
+ conn->marked_for_close);
#ifdef TOR_FRAGILE
tor_assert(0);
#endif
- return -1;
+ return;
}
- conn->marked_for_close = 1;
+ conn->marked_for_close = line;
+ conn->marked_for_close_file = file;
add_connection_to_closeable_list(conn);
/* in case we're going to be held-open-til-flushed, reset
* the number of seconds since last successful write, so
* we get our whole 15 seconds */
conn->timestamp_lastwritten = time(NULL);
-
- return 0;
}
/** Find each connection that has hold_open_until_flushed set to
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index b176dff971..1e72d6f7d3 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -32,9 +32,8 @@ _connection_mark_unattached_ap(connection_t *conn, int endreason,
conn->has_sent_end = 1; /* no circ yet */
if (conn->marked_for_close) {
- log(LOG_WARN,"Duplicate call to connection_mark_unattached_ap at %s:%d (first marked at %s:%d)",
- file, line,
- conn->marked_for_close_file,conn->marked_for_close);
+ /* This call will warn as appropriate. */
+ _connection_mark_for_close(conn, line, file);
return;
}
@@ -52,9 +51,7 @@ _connection_mark_unattached_ap(connection_t *conn, int endreason,
connection_ap_handshake_socks_resolved(conn,RESOLVED_TYPE_ERROR,0,NULL);
}
- _connection_mark_for_close(conn);
- conn->marked_for_close_file = file;
- conn->marked_for_close = line;
+ _connection_mark_for_close(conn, line, file);
conn->hold_open_until_flushed = 1;
}
diff --git a/src/or/or.h b/src/or/or.h
index d61cde47f3..25c912f4fc 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1177,19 +1177,10 @@ circuit_t *circuit_get_rendezvous(const char *cookie);
circuit_t *circuit_get_clean_open(uint8_t purpose, int need_uptime,
int need_capacity, int internal);
void circuit_mark_all_unused_circs(void);
-int _circuit_mark_for_close(circuit_t *circ);
-
-#define circuit_mark_for_close(c) \
- do { \
- if (_circuit_mark_for_close(c)<0) { \
- log(LOG_WARN,"Duplicate call to circuit_mark_for_close at %s:%d (first at %s:%d)", \
- _SHORT_FILE_,__LINE__, \
- c->marked_for_close_file,c->marked_for_close); \
- } else { \
- c->marked_for_close_file = _SHORT_FILE_; \
- c->marked_for_close = __LINE__; \
- } \
- } while (0)
+void _circuit_mark_for_close(circuit_t *circ, int line, const char *file);
+
+#define circuit_mark_for_close(c) \
+ _circuit_mark_for_close((c), __LINE__, _SHORT_FILE_)
void assert_cpath_layer_ok(const crypt_path_t *cp);
void assert_circuit_ok(const circuit_t *c);
@@ -1267,19 +1258,10 @@ void connection_free(connection_t *conn);
void connection_free_all(void);
void connection_about_to_close_connection(connection_t *conn);
void connection_close_immediate(connection_t *conn);
-int _connection_mark_for_close(connection_t *conn);
-
-#define connection_mark_for_close(c) \
- do { \
- if (_connection_mark_for_close(c)<0) { \
- log(LOG_WARN,"Duplicate call to connection_mark_for_close at %s:%d (first at %s:%d)", \
- _SHORT_FILE_,__LINE__, \
- c->marked_for_close_file,c->marked_for_close); \
- } else { \
- c->marked_for_close_file = _SHORT_FILE_; \
- c->marked_for_close = __LINE__; \
- } \
- } while (0)
+void _connection_mark_for_close(connection_t *conn,int line, const char *file);
+
+#define connection_mark_for_close(c) \
+ _connection_mark_for_close((c), __LINE__, _SHORT_FILE_)
void connection_expire_held_open(void);
@@ -1325,8 +1307,7 @@ int connection_or_nonopen_was_started_here(connection_t *conn);
/********************************* connection_edge.c ***************************/
#define connection_mark_unattached_ap(conn, endreason) \
- do { _connection_mark_unattached_ap(conn, endreason, __LINE__, _SHORT_FILE_);\
- } while (0)
+ _connection_mark_unattached_ap((conn), (endreason), __LINE__, _SHORT_FILE_)
void _connection_mark_unattached_ap(connection_t *conn, int endreason,
int line, const char *file);