From 74dc7eedc510d70ea600dd5938f45947a314bc24 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 8 Apr 2005 03:36:39 +0000 Subject: Add kludgy function to force controllers to flush EVENT_ERR_MSG events. svn:r4057 --- src/or/connection.c | 34 ++++++++++++++++++++++++++++++++++ src/or/control.c | 3 +++ src/or/or.h | 1 + 3 files changed, 38 insertions(+) (limited to 'src/or') diff --git a/src/or/connection.c b/src/or/connection.c index 1775f122e..c19c9b9dd 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1265,6 +1265,40 @@ int connection_handle_write(connection_t *conn) { return 0; } +/* DOCDOC */ +void _connection_controller_force_write(connection_t *conn) +{ + /* XXX This is hideous code duplication, but raising it seems a little + * tricky for now. Think more about this one. We only call it for + * EVENT_ERR_MSG, so messing with buckets a little isn't such a big problem. + */ + int result; + tor_assert(conn); + tor_assert(!conn->tls); + tor_assert(conn->type == CONN_TYPE_CONTROL); + if (conn->marked_for_close || conn->s < 0) + return; + + result = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); + if (result < 0) { + connection_close_immediate(conn); /* Don't flush; connection is dead. */ + connection_mark_for_close(conn); + return; + } + + if (result > 0 && !is_local_IP(conn->addr)) { /* remember it */ + rep_hist_note_bytes_written(result, time(NULL)); + global_write_bucket -= result; + } + + if (!connection_wants_to_flush(conn)) { /* it's done flushing */ + if (connection_finished_flushing(conn) < 0) { + /* already marked */ + return; + } + } +} + /** Append len bytes of string onto conn's * outbuf, and ask it to start writing. */ diff --git a/src/or/control.c b/src/or/control.c index 514ff0c6b..d85d31506 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -330,6 +330,9 @@ send_control_event(uint16_t event, uint32_t len, const char *body) conns[i]->state == CONTROL_CONN_STATE_OPEN && conns[i]->event_mask & (1<