Use connection_mark_and_flush consistently.

This commit is contained in:
Nick Mathewson 2010-10-13 13:08:38 -04:00
parent 5710d99f00
commit a0c1c2ac01
5 changed files with 20 additions and 18 deletions

View File

@ -34,15 +34,21 @@ 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_)
#define connection_mark_and_flush(c) \
/**
* Mark 'c' for close, but try to hold it open until all the data is written.
*/
#define _connection_mark_and_flush(c,line,file) \
do { \
connection_t *tmp_conn_ = (c); \
_connection_mark_for_close(tmp_conn_, __LINE__, _SHORT_FILE_); \
_connection_mark_for_close(tmp_conn_, (line), (file)); \
tmp_conn_->hold_open_until_flushed = 1; \
IF_HAS_BUFFEREVENT(tmp_conn_, \
connection_start_writing(tmp_conn_)); \
} while (0)
#define connection_mark_and_flush(c) \
_connection_mark_and_flush((c), __LINE__, _SHORT_FILE_)
void connection_expire_held_open(void);
int connection_connect(connection_t *conn, const char *address,

View File

@ -90,9 +90,8 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
conn->socks_request->has_finished = 1;
}
_connection_mark_for_close(TO_CONN(conn), line, file);
conn->_base.hold_open_until_flushed = 1;
IF_HAS_BUFFEREVENT(TO_CONN(conn), connection_start_writing(TO_CONN(conn)));
_connection_mark_and_flush(TO_CONN(conn), line, file);
conn->end_reason = endreason;
}

View File

@ -2798,8 +2798,8 @@ connection_control_process_inbuf(control_connection_t *conn)
body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
set_uint16(buf+0, htons(body_len));
connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
connection_mark_for_close(TO_CONN(conn));
conn->_base.hold_open_until_flushed = 1;
connection_mark_and_flush(TO_CONN(conn));
return 0;
}
@ -2820,8 +2820,7 @@ connection_control_process_inbuf(control_connection_t *conn)
if (data_len + conn->incoming_cmd_cur_len > MAX_COMMAND_LINE_LENGTH) {
connection_write_str_to_buf("500 Line too long.\r\n", conn);
connection_stop_reading(TO_CONN(conn));
connection_mark_for_close(TO_CONN(conn));
conn->_base.hold_open_until_flushed = 1;
connection_mark_and_flush(TO_CONN(conn));
}
while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
conn->incoming_cmd_len *= 2;
@ -2880,8 +2879,7 @@ connection_control_process_inbuf(control_connection_t *conn)
/* Otherwise, Quit is always valid. */
if (!strcasecmp(conn->incoming_cmd, "QUIT")) {
connection_write_str_to_buf("250 closing connection\r\n", conn);
connection_mark_for_close(TO_CONN(conn));
conn->_base.hold_open_until_flushed = 1;
connection_mark_and_flush(TO_CONN(conn));
return 0;
}

View File

@ -949,8 +949,7 @@ run_connection_housekeeping(int i, time_t now)
connection_or_connect_failed(TO_OR_CONN(conn),
END_OR_CONN_REASON_TIMEOUT,
"Tor gave up on the connection");
connection_mark_for_close(conn);
conn->hold_open_until_flushed = 1;
connection_mark_and_flush(conn);
} else if (!connection_state_is_open(conn)) {
if (past_keepalive) {
/* We never managed to actually get this connection open and happy. */

View File

@ -3216,13 +3216,13 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
/* Make sure that we haven't already got this exact descriptor. */
if (sdmap_get(routerlist->desc_digest_map,
router->cache_info.signed_descriptor_digest)) {
/* If we have this descriptor already and the new descriptor is a bridge
/* If we have this descriptor already but the new descriptor is a bridge
* descriptor, replace it. If we had a bridge descriptor before and the
* new one is not a bridge descriptor, don't replace it. */
tor_assert(old_router);
if (! (routerinfo_is_a_configured_bridge(router) &&
(router->purpose == ROUTER_PURPOSE_BRIDGE ||
old_router->purpose != ROUTER_PURPOSE_BRIDGE))) {
const int had_as_bridge = old_router &&
old_router->purpose == ROUTER_PURPOSE_BRIDGE;
if (! routerinfo_is_a_configured_bridge(router) ||
(router->purpose != ROUTER_PURPOSE_BRIDGE && had_as_bridge)) {
log_info(LD_DIR,
"Dropping descriptor that we already have for router '%s'",
router->nickname);