[or-cvs] r13407: Add more documentation; change the behavior of read_to_buf_t (in tor/trunk: . src/common src/or)
nickm at seul.org
nickm at seul.org
Wed Feb 6 19:34:33 UTC 2008
Author: nickm
Date: 2008-02-06 14:34:32 -0500 (Wed, 06 Feb 2008)
New Revision: 13407
Modified:
tor/trunk/
tor/trunk/src/common/mempool.c
tor/trunk/src/or/buffers.c
tor/trunk/src/or/connection.c
tor/trunk/src/or/rephist.c
Log:
r17951 at catbus: nickm | 2008-02-06 14:34:13 -0500
Add more documentation; change the behavior of read_to_buf_tls to be more consistent. Note a longstanding problem with current read/write interfaces.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r17951] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/src/common/mempool.c
===================================================================
--- tor/trunk/src/common/mempool.c 2008-02-06 18:21:16 UTC (rev 13406)
+++ tor/trunk/src/common/mempool.c 2008-02-06 19:34:32 UTC (rev 13407)
@@ -400,6 +400,9 @@
void
mp_pool_clean(mp_pool_t *pool, int n)
{
+ /* XXXX020 this is stupid. We shouldn't care about empty chunks if there
+ * is lots of space in used chunks. */
+
mp_chunk_t *chunk, **first_to_free;
if (n < 0) {
/* As said in the documentation, "negative n" means "leave an additional
Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c 2008-02-06 18:21:16 UTC (rev 13406)
+++ tor/trunk/src/or/buffers.c 2008-02-06 19:34:32 UTC (rev 13407)
@@ -548,7 +548,10 @@
return chunk;
}
-/** DOCDOC */
+/** Read up to <b>at_most</b> bytes from the socket <b>fd</b> into
+ * <b>chunk</b> (which must be on <b>buf/b>). If we get an EOF, set
+ * *<b>reached_eof</b> to 1. Return -1 on error, 0 on eof or blocking,
+ * and the number of bytes read otherwise. */
static INLINE int
read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
int *reached_eof)
@@ -580,7 +583,8 @@
}
}
-/** DOCDOC */
+/** As read_to_chunk(), but return (negative) error code on error, blocking,
+ * or TLS, and the number of bytes read otherwise. */
static INLINE int
read_to_chunk_tls(buf_t *buf, chunk_t *chunk, tor_tls_t *tls,
size_t at_most)
@@ -597,16 +601,17 @@
}
/** Read from socket <b>s</b>, writing onto end of <b>buf</b>. Read at most
- * <b>at_most</b> bytes, resizing the buffer as necessary. If recv()
- * returns 0, set *<b>reached_eof</b> to 1 and return 0. Return -1 on error;
- * else return the number of bytes read. Return 0 if recv() would
- * block.
- *
- * DOCDOC revise
+ * <b>at_most</b> bytes, growing the buffer as necessary. If recv() returns 0
+ * (because of EOF), set *<b>reached_eof</b> to 1 and return 0. Return -1 on
+ * error; else return the number of bytes read.
*/
+/* XXXX020 indicate "read blocked" somehow? */
int
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
{
+ /* XXXX020 It's stupid to overload the return values for these functions:
+ * "error status" and "number of bytes read" are not mutually exclusive.
+ */
int r = 0;
size_t total_read = 0;
@@ -639,7 +644,8 @@
return r;
}
-/** As read_to_buf, but reads from a TLS connection.
+/** As read_to_buf, but reads from a TLS connection, and returns a TLS
+ * status value rather than the number of bytes read.
*
* Using TLS on OR connections complicates matters in two ways.
*
@@ -657,8 +663,6 @@
* Second, the TLS stream's events do not correspond directly to network
* events: sometimes, before a TLS stream can read, the network must be
* ready to write -- or vice versa.
- *
- * DOCDOC revise
*/
int
read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf)
@@ -686,20 +690,20 @@
if (r < 0)
return r; /* Error */
else if ((size_t)r < readlen) /* eof, block, or no more to read. */
- return r + total_read;
+ return r;
total_read += r;
}
return r;
}
-/** Helper for flush_buf(): try to write <b>sz</b> bytes from buffer
- * <b>buf</b> onto socket <b>s</b>. On success, deduct the bytes written
- * from *<b>buf_flushlen</b>.
- * Return the number of bytes written on success, -1 on failure.
+/** Helper for flush_buf(): try to write <b>sz</b> bytes from chunk
+ * <b>chunk</b> of buffer <b>buf</b> onto socket <b>s</b>. On success, deduct
+ * the bytes written from *<b>buf_flushlen</b>. Return the number of bytes
+ * written on success, 0 on blocking, -1 on failure.
*/
static INLINE int
flush_chunk(int s, buf_t *buf, chunk_t *chunk, size_t sz,
- size_t *buf_flushlen)
+ size_t *buf_flushlen)
{
int write_result;
@@ -764,6 +768,9 @@
int
flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
{
+ /* XXXX020 It's stupid to overload the return values for these functions:
+ * "error status" and "number of bytes flushed" are not mutually exclusive.
+ */
int r;
size_t flushed = 0;
tor_assert(buf_flushlen);
Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c 2008-02-06 18:21:16 UTC (rev 13406)
+++ tor/trunk/src/or/connection.c 2008-02-06 19:34:32 UTC (rev 13407)
@@ -1912,6 +1912,7 @@
conn->state > OR_CONN_STATE_PROXY_READING) {
int pending;
or_connection_t *or_conn = TO_OR_CONN(conn);
+ size_t initial_size;
if (conn->state == OR_CONN_STATE_TLS_HANDSHAKING ||
conn->state == OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING) {
/* continue handshaking even if global token bucket is empty */
@@ -1924,6 +1925,7 @@
conn->s,(int)buf_datalen(conn->inbuf),
tor_tls_get_pending_bytes(or_conn->tls), at_most);
+ initial_size = buf_datalen(conn->inbuf);
/* else open, or closing */
result = read_to_buf_tls(or_conn->tls, at_most, conn->inbuf);
if (TOR_TLS_IS_ERROR(result) || result == TOR_TLS_CLOSE)
@@ -1963,11 +1965,9 @@
if (r2<0) {
log_warn(LD_BUG, "apparently, reading pending bytes can fail.");
return -1;
- } else {
- result += r2;
}
}
-
+ result = (int)(buf_datalen(conn->inbuf)-initial_size);
tor_tls_get_n_raw_bytes(or_conn->tls, &n_read, &n_written);
log_debug(LD_GENERAL, "After TLS read of %d: %ld read, %ld written",
result, (long)n_read, (long)n_written);
Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c 2008-02-06 18:21:16 UTC (rev 13406)
+++ tor/trunk/src/or/rephist.c 2008-02-06 19:34:32 UTC (rev 13407)
@@ -19,6 +19,7 @@
static void predicted_ports_init(void);
static void hs_usage_init(void);
+/**DOCDOC*/
uint64_t rephist_total_alloc=0;
uint32_t rephist_total_num=0;
@@ -732,8 +733,10 @@
return -1;
}
+/** How many bad times has parse_possibly_bad_iso_time parsed? */
static int n_bogus_times = 0;
-/** DOCDOC */
+/** Parse the ISO-formatted time in <b>s</b> into *<b>time_out</b>, but
+ * rounds any pre-1970 date to Jan 1, 1970. */
static int
parse_possibly_bad_iso_time(const char *s, time_t *time_out)
{
More information about the tor-commits
mailing list