diff options
author | Roger Dingledine <arma@torproject.org> | 2003-03-04 04:36:37 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-03-04 04:36:37 +0000 |
commit | 1768f29d7e1fb01bbeaf282b7fcb00b8808bd89f (patch) | |
tree | 0c26c5e0790d42f58818b9b1c211913fb70ea099 /src/or/buffers.c | |
parent | c5e7d4ca7aabb848eb2a5502c93798b8a6e04b93 (diff) | |
download | tor-1768f29d7e1fb01bbeaf282b7fcb00b8808bd89f.tar.gz tor-1768f29d7e1fb01bbeaf282b7fcb00b8808bd89f.zip |
better comments and a few patches
svn:r164
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 45d2b74ddb..5bdc8e73eb 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -8,6 +8,10 @@ extern or_options_t options; /* command-line and config-file options */ +/* Create a new buf of size MAX_BUF_SIZE. Write a pointer to it + * into *buf, write MAX_BUF_SIZE into *buflen, and initialize + * *buf_datalen to 0. Return 0 if success, or -1 if malloc fails. + */ int buf_new(char **buf, int *buflen, int *buf_datalen) { assert(buf && buflen && buf_datalen); @@ -15,7 +19,7 @@ int buf_new(char **buf, int *buflen, int *buf_datalen) { *buf = (char *)malloc(MAX_BUF_SIZE); if(!*buf) return -1; - memset(*buf,0,MAX_BUF_SIZE); +// memset(*buf,0,MAX_BUF_SIZE); *buflen = MAX_BUF_SIZE; *buf_datalen = 0; @@ -26,14 +30,13 @@ void buf_free(char *buf) { free(buf); } +/* read from socket s, writing onto buf+buf_datalen. If at_most is >= 0 then + * read at most 'at_most' bytes, and in any case don't read more than will fit based on buflen. + * If read() returns 0, set *reached_eof to 1 and return 0. If you want to tear + * down the connection return -1, else return the number of bytes read. + */ int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof) { - /* read from socket s, writing onto buf+buf_datalen. If at_most is >= 0 then - * read at most 'at_most' bytes, and in any case don't read more than will fit based on buflen. - * If read() returns 0, set *reached_eof to 1 and return 0. If you want to tear - * down the connection return -1, else return the number of bytes read. - */ - int read_result; assert(buf && *buf && buflen && buf_datalen && reached_eof && (s>=0)); |