[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r13002: Remove need for buf_pullup in fetch_line_from_buf(). (in tor/trunk: . src/or)
Author: nickm
Date: 2007-12-28 21:33:42 -0500 (Fri, 28 Dec 2007)
New Revision: 13002
Modified:
tor/trunk/
tor/trunk/src/or/buffers.c
tor/trunk/src/or/control.c
Log:
r17426@catbus: nickm | 2007-12-28 21:12:29 -0500
Remove need for buf_pullup in fetch_line_from_buf().
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r17426] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c 2007-12-28 11:13:25 UTC (rev 13001)
+++ tor/trunk/src/or/buffers.c 2007-12-29 02:33:42 UTC (rev 13002)
@@ -1398,6 +1398,22 @@
return 0;
}
+/** DOCDOC */
+static int
+buf_find_offset_of_char(buf_t *buf, char ch)
+{
+ chunk_t *chunk;
+ int offset = 0;
+ for (chunk = buf->head; chunk; chunk = chunk->next) {
+ char *cp = memchr(chunk->data, ch, chunk->datalen);
+ if (cp)
+ return offset + (cp - chunk->data);
+ else
+ offset += chunk->datalen;
+ }
+ return -1;
+}
+
/** Try to read a single LF-terminated line from <b>buf</b>, and write it,
* NUL-terminated, into the *<b>data_len</b> byte buffer at <b>data_out</b>.
* Set *<b>data_len</b> to the number of bytes in the line, not counting the
@@ -1408,21 +1424,18 @@
int
fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
{
- char *cp;
size_t sz;
+ int offset;
if (!buf->head)
return 0;
- /* XXXX020 pull up less aggressively. And implement setting *data_len
- * properly in cases where we return -1. */
- buf_pullup(buf, *data_len, 0);
- cp = memchr(buf->head->data, '\n', buf->head->datalen);
- if (!cp) {
+
+ offset = buf_find_offset_of_char(buf, '\n');
+ if (offset < 0)
return 0;
- }
- sz = cp - buf->head->data;
+ sz = (size_t) offset;
if (sz+2 > *data_len) {
- *data_len = sz+2;
+ *data_len = sz + 2;
return -1;
}
fetch_from_buf(data_out, sz+1, buf);
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2007-12-28 11:13:25 UTC (rev 13001)
+++ tor/trunk/src/or/control.c 2007-12-29 02:33:42 UTC (rev 13002)
@@ -2631,10 +2631,11 @@
/* Line not all here yet. Wait. */
return 0;
else if (r == -1) {
- while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
- conn->incoming_cmd_len *= 2;
- conn->incoming_cmd = tor_realloc(conn->incoming_cmd,
- conn->incoming_cmd_len);
+ /*XXXX020 impose some maximum on length! */
+ while (conn->incoming_cmd_len < data_len+conn->incoming_cmd_cur_len)
+ conn->incoming_cmd_len *= 2;
+ conn->incoming_cmd = tor_realloc(conn->incoming_cmd,
+ conn->incoming_cmd_len);
}
} while (r != 1);