[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9208: Refactor _connection_controller_force_write back into connce (in tor/trunk: . src/or)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r9208: Refactor _connection_controller_force_write back into connce (in tor/trunk: . src/or)
- From: nickm@xxxxxxxx
- Date: Fri, 29 Dec 2006 00:06:59 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Fri, 29 Dec 2006 00:07:25 -0500
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2006-12-29 00:06:47 -0500 (Fri, 29 Dec 2006)
New Revision: 9208
Modified:
tor/trunk/
tor/trunk/src/or/connection.c
tor/trunk/src/or/connection_or.c
tor/trunk/src/or/control.c
tor/trunk/src/or/main.c
tor/trunk/src/or/or.h
Log:
r11743@Kushana: nickm | 2006-12-28 23:13:21 -0500
Refactor _connection_controller_force_write back into conncetion_handle_write. Again, the line count goes down: groovy!
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r11743] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c 2006-12-29 03:42:46 UTC (rev 9207)
+++ tor/trunk/src/or/connection.c 2006-12-29 05:06:47 UTC (rev 9208)
@@ -1575,11 +1575,15 @@
* more bytes on conn->outbuf, then call connection_finished_flushing
* on it too.
*
+ * If <b>force</b>, then write as many bytes as possible, ignoring bandwidth
+ * limits. (Used for flushing messages to controller connections on fatal
+ * errors.)
+ *
* Mark the connection and return -1 if you want to close it, else
* return 0.
*/
int
-connection_handle_write(connection_t *conn)
+connection_handle_write(connection_t *conn, int force)
{
int e;
socklen_t len=sizeof(e);
@@ -1590,7 +1594,7 @@
tor_assert(!connection_is_listener(conn));
- if (conn->marked_for_close)
+ if (conn->marked_for_close || conn->s < 0)
return 0; /* do nothing */
conn->timestamp_lastwritten = now;
@@ -1631,7 +1635,8 @@
return -1;
}
- max_to_write = connection_bucket_write_limit(conn);
+ max_to_write = force ? (int)conn->outbuf_flushlen
+ : connection_bucket_write_limit(conn);
if (connection_speaks_cells(conn) &&
conn->state > OR_CONN_STATE_PROXY_READING) {
@@ -1738,49 +1743,6 @@
return 0;
}
-/* A controller event has just happened with such urgency that we
- * need to write it onto controller <b>conn</b> immediately. */
-void
-_connection_controller_force_write(control_connection_t *control_conn)
-{
- /* XXXX012 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;
- connection_t *conn;
- tor_assert(control_conn);
- conn = TO_CONN(control_conn);
-
- if (conn->marked_for_close || conn->s < 0)
- return;
-
- CONN_LOG_PROTECT(conn,
- result = flush_buf(conn->s, conn->outbuf,
- conn->outbuf_flushlen, &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) {
- if (!is_internal_IP(conn->addr, 0)) { /* remember it */
- rep_hist_note_bytes_written(result, time(NULL));
- global_write_bucket -= result;
- }
- if (connection_flushed_some(conn) < 0)
- connection_mark_for_close(conn);
- }
-
- if (!connection_wants_to_flush(conn)) { /* it's done flushing */
- if (connection_finished_flushing(conn) < 0) {
- /* already marked */
- return;
- }
- }
-}
-
/** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s
* outbuf, and ask it to start writing.
*/
Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c 2006-12-29 03:42:46 UTC (rev 9207)
+++ tor/trunk/src/or/connection_or.c 2006-12-29 05:06:47 UTC (rev 9208)
@@ -717,7 +717,7 @@
int extra = conn->_base.outbuf_flushlen - MIN_TLS_FLUSHLEN;
conn->_base.outbuf_flushlen = MIN_TLS_FLUSHLEN;
connection_start_writing(TO_CONN(conn));
- if (connection_handle_write(TO_CONN(conn)) < 0) {
+ if (connection_handle_write(TO_CONN(conn), 0) < 0) {
if (!conn->_base.marked_for_close) {
/* this connection is broken. remove it. */
log_warn(LD_BUG,
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2006-12-29 03:42:46 UTC (rev 9207)
+++ tor/trunk/src/or/control.c 2006-12-29 05:06:47 UTC (rev 9208)
@@ -619,7 +619,7 @@
if (control_conn->event_mask & (1<<event)) {
send_control0_message(control_conn, CONTROL0_CMD_EVENT, buflen, buf);
if (event == EVENT_ERR_MSG)
- _connection_controller_force_write(control_conn);
+ connection_handle_write(TO_CONN(control_conn), 1);
}
}
}
@@ -663,7 +663,7 @@
if (control_conn->event_mask & (1<<event)) {
connection_write_to_buf(msg, strlen(msg), TO_CONN(control_conn));
if (event == EVENT_ERR_MSG)
- _connection_controller_force_write(control_conn);
+ connection_handle_write(TO_CONN(control_conn), 1);
}
}
}
Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c 2006-12-29 03:42:46 UTC (rev 9207)
+++ tor/trunk/src/or/main.c 2006-12-29 05:06:47 UTC (rev 9208)
@@ -440,7 +440,7 @@
assert_connection_ok(conn, time(NULL));
- if (connection_handle_write(conn) < 0) {
+ if (connection_handle_write(conn, 0) < 0) {
if (!conn->marked_for_close) {
/* this connection is broken. remove it. */
log_fn(LOG_WARN,LD_BUG,
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2006-12-29 03:42:46 UTC (rev 9207)
+++ tor/trunk/src/or/or.h 2006-12-29 05:06:47 UTC (rev 9208)
@@ -1999,8 +1999,7 @@
int connection_wants_to_flush(connection_t *conn);
int connection_outbuf_too_full(connection_t *conn);
-int connection_handle_write(connection_t *conn);
-void _connection_controller_force_write(control_connection_t *conn);
+int connection_handle_write(connection_t *conn, int force);
void connection_write_to_buf(const char *string, size_t len,
connection_t *conn);
void connection_write_to_buf_zlib(dir_connection_t *conn,