Commit 0dc02328 authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

Move most of *_mark_for_close out of macros.


svn:r3992
parent 2a332bf0
Loading
Loading
Loading
Loading
+13 −4
Changes for src/or/circuitlist.c: 13 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -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. */
+10 −7
Changes for src/or/connection.c: 10 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -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
+3 −6
Changes for src/or/connection_edge.c: 3 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -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;
}

+5 −24
Changes for src/or/or.h: 5 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -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);
void _circuit_mark_for_close(circuit_t *circ, int line, const char *file);

#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)
  _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);
void _connection_mark_for_close(connection_t *conn,int line, const char *file);

#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)
  _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);