diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-07-31 13:44:43 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-09-27 12:28:43 -0400 |
commit | 051491780090c610c06882ead4b2cf17bc6c93df (patch) | |
tree | ea8d881bc7c290e692e5ba6ed7af188032c6ba3f /src/or/connection.c | |
parent | 5448501479b61c0ed365b4a96ce9442125c397b9 (diff) | |
download | tor-051491780090c610c06882ead4b2cf17bc6c93df.tar.gz tor-051491780090c610c06882ead4b2cf17bc6c93df.zip |
Add a new connection_fetch_from_buf_line() that can handle bufferevents
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index d6b89f1f7d..db51bbe534 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -2616,6 +2616,32 @@ connection_fetch_from_buf(char *string, size_t len, connection_t *conn) } } +/** As fetch_from_buf_line(), but read from a connection's input buffer. */ +int +connection_fetch_from_buf_line(connection_t *conn, char *data, + size_t *data_len) +{ + IF_HAS_BUFFEREVENT(conn, { + int r; + size_t eol_len=0; + struct evbuffer *input = bufferevent_get_input(conn->bufev); + struct evbuffer_ptr ptr = + evbuffer_search_eol(input, NULL, &eol_len, EVBUFFER_EOL_LF); + if (ptr.pos == -1) + return 0; /* No EOL found. */ + if ((size_t)ptr.pos+eol_len >= *data_len) { + return -1; /* Too long */ + } + *data_len = ptr.pos+eol_len; + r = evbuffer_remove(input, data, ptr.pos+eol_len); + tor_assert(r >= 0); + data[ptr.pos+eol_len] = '\0'; + return 1; + }) ELSE_IF_NO_BUFFEREVENT { + return fetch_from_buf_line(conn->inbuf, data, data_len); + } +} + /** Return conn-\>outbuf_flushlen: how many bytes conn wants to flush * from its outbuf. */ int |