Commit 232861ba authored by Nick Mathewson's avatar Nick Mathewson 🥄
Browse files

Docment or add DOCDOC comments to undocumented functions in src/or. Make...

Docment or add DOCDOC comments to undocumented functions in src/or.  Make function definition format uniform.


svn:r4411
parent df029fc9
...@@ -101,7 +101,8 @@ const char compat_c_id[] = "$Id$"; ...@@ -101,7 +101,8 @@ const char compat_c_id[] = "$Id$";
* easiest to emulate "return -1" with conformant implementations than * easiest to emulate "return -1" with conformant implementations than
* it is to emulate "return number that would be written" with * it is to emulate "return number that would be written" with
* non-conformant implementations.) */ * non-conformant implementations.) */
int tor_snprintf(char *str, size_t size, const char *format, ...) int
tor_snprintf(char *str, size_t size, const char *format, ...)
{ {
va_list ap; va_list ap;
int r; int r;
...@@ -114,7 +115,8 @@ int tor_snprintf(char *str, size_t size, const char *format, ...) ...@@ -114,7 +115,8 @@ int tor_snprintf(char *str, size_t size, const char *format, ...)
/** Replacement for vsnprintf; behavior differs as tor_snprintf differs from /** Replacement for vsnprintf; behavior differs as tor_snprintf differs from
* snprintf. * snprintf.
*/ */
int tor_vsnprintf(char *str, size_t size, const char *format, va_list args) int
tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
{ {
int r; int r;
if (size == 0) if (size == 0)
...@@ -162,7 +164,8 @@ _tor_fix_source_file(const char *fname) ...@@ -162,7 +164,8 @@ _tor_fix_source_file(const char *fname)
* *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid * *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid
* unaligned memory access. * unaligned memory access.
*/ */
uint16_t get_uint16(const char *cp) uint16_t
get_uint16(const char *cp)
{ {
uint16_t v; uint16_t v;
memcpy(&v,cp,2); memcpy(&v,cp,2);
...@@ -173,7 +176,8 @@ uint16_t get_uint16(const char *cp) ...@@ -173,7 +176,8 @@ uint16_t get_uint16(const char *cp)
* *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid * *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid
* unaligned memory access. * unaligned memory access.
*/ */
uint32_t get_uint32(const char *cp) uint32_t
get_uint32(const char *cp)
{ {
uint32_t v; uint32_t v;
memcpy(&v,cp,4); memcpy(&v,cp,4);
...@@ -183,7 +187,8 @@ uint32_t get_uint32(const char *cp) ...@@ -183,7 +187,8 @@ uint32_t get_uint32(const char *cp)
* Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to * Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
* *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid * *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */ * unaligned memory access. */
void set_uint16(char *cp, uint16_t v) void
set_uint16(char *cp, uint16_t v)
{ {
memcpy(cp,&v,2); memcpy(cp,&v,2);
} }
...@@ -191,7 +196,8 @@ void set_uint16(char *cp, uint16_t v) ...@@ -191,7 +196,8 @@ void set_uint16(char *cp, uint16_t v)
* Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to * Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
* *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid * *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */ * unaligned memory access. */
void set_uint32(char *cp, uint32_t v) void
set_uint32(char *cp, uint32_t v)
{ {
memcpy(cp,&v,4); memcpy(cp,&v,4);
} }
...@@ -202,7 +208,8 @@ void set_uint32(char *cp, uint32_t v) ...@@ -202,7 +208,8 @@ void set_uint32(char *cp, uint32_t v)
* rename(2). On windows, this removes 'to' first if it already exists. * rename(2). On windows, this removes 'to' first if it already exists.
* Returns 0 on success. Returns -1 and sets errno on failure. * Returns 0 on success. Returns -1 and sets errno on failure.
*/ */
int replace_file(const char *from, const char *to) int
replace_file(const char *from, const char *to)
{ {
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
return rename(from,to); return rename(from,to);
...@@ -226,7 +233,8 @@ int replace_file(const char *from, const char *to) ...@@ -226,7 +233,8 @@ int replace_file(const char *from, const char *to)
/** Turn <b>socket</b> into a nonblocking socket. /** Turn <b>socket</b> into a nonblocking socket.
*/ */
void set_socket_nonblocking(int socket) void
set_socket_nonblocking(int socket)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
int nonblocking = 1; int nonblocking = 1;
...@@ -419,7 +427,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) { ...@@ -419,7 +427,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) {
/** Call setuid and setgid to run as <b>user</b>:<b>group</b>. Return 0 on /** Call setuid and setgid to run as <b>user</b>:<b>group</b>. Return 0 on
* success. On failure, log and return -1. * success. On failure, log and return -1.
*/ */
int switch_id(char *user, char *group) { int
switch_id(char *user, char *group) {
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
struct passwd *pw = NULL; struct passwd *pw = NULL;
struct group *gr = NULL; struct group *gr = NULL;
...@@ -490,7 +499,8 @@ get_user_homedir(const char *username) ...@@ -490,7 +499,8 @@ get_user_homedir(const char *username)
* Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr), * Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr),
* but works on Windows and Solaris.) * but works on Windows and Solaris.)
*/ */
int tor_inet_aton(const char *c, struct in_addr* addr) int
tor_inet_aton(const char *c, struct in_addr* addr)
{ {
#ifdef HAVE_INET_ATON #ifdef HAVE_INET_ATON
return inet_aton(c, addr); return inet_aton(c, addr);
...@@ -517,7 +527,8 @@ int tor_inet_aton(const char *c, struct in_addr* addr) ...@@ -517,7 +527,8 @@ int tor_inet_aton(const char *c, struct in_addr* addr)
* (This function exists because standard windows gethostbyname * (This function exists because standard windows gethostbyname
* doesn't treat raw IP addresses properly.) * doesn't treat raw IP addresses properly.)
*/ */
int tor_lookup_hostname(const char *name, uint32_t *addr) int
tor_lookup_hostname(const char *name, uint32_t *addr)
{ {
/* Perhaps eventually this should be replaced by a tor_getaddrinfo or /* Perhaps eventually this should be replaced by a tor_getaddrinfo or
* something. * something.
...@@ -744,7 +755,8 @@ spawn_func(int (*func)(void *), void *data) ...@@ -744,7 +755,8 @@ spawn_func(int (*func)(void *), void *data)
/** End the current thread/process. /** End the current thread/process.
*/ */
void spawn_exit() void
spawn_exit()
{ {
#if defined(USE_WIN32_THREADS) #if defined(USE_WIN32_THREADS)
_endthread(); _endthread();
...@@ -760,7 +772,9 @@ void spawn_exit() ...@@ -760,7 +772,9 @@ void spawn_exit()
/** Set *timeval to the current time of day. On error, log and terminate. /** Set *timeval to the current time of day. On error, log and terminate.
* (Same as gettimeofday(timeval,NULL), but never returns -1.) * (Same as gettimeofday(timeval,NULL), but never returns -1.)
*/ */
void tor_gettimeofday(struct timeval *timeval) { void
tor_gettimeofday(struct timeval *timeval)
{
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
if (gettimeofday(timeval, NULL)) { if (gettimeofday(timeval, NULL)) {
log_fn(LOG_ERR, "gettimeofday failed."); log_fn(LOG_ERR, "gettimeofday failed.");
...@@ -785,7 +799,8 @@ void tor_gettimeofday(struct timeval *timeval) { ...@@ -785,7 +799,8 @@ void tor_gettimeofday(struct timeval *timeval) {
#ifndef HAVE_LOCALTIME_R #ifndef HAVE_LOCALTIME_R
#ifdef TIME_FNS_NEED_LOCKS #ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_localtime_r(const time_t *timep, struct tm *result) struct tm *
tor_localtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
static tor_mutex_t *m=NULL; static tor_mutex_t *m=NULL;
...@@ -798,7 +813,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result) ...@@ -798,7 +813,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
return result; return result;
} }
#else #else
struct tm *tor_localtime_r(const time_t *timep, struct tm *result) struct tm *
tor_localtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
tor_assert(result); tor_assert(result);
...@@ -811,7 +827,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result) ...@@ -811,7 +827,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
#ifndef HAVE_GMTIME_R #ifndef HAVE_GMTIME_R
#ifdef TIME_FNS_NEED_LOCKS #ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) struct tm *
tor_gmtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
static tor_mutex_t *m=NULL; static tor_mutex_t *m=NULL;
...@@ -824,7 +841,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) ...@@ -824,7 +841,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
return result; return result;
} }
#else #else
struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) struct tm *
tor_gmtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
tor_assert(result); tor_assert(result);
...@@ -839,7 +857,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) ...@@ -839,7 +857,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
struct tor_mutex_t { struct tor_mutex_t {
HANDLE handle; HANDLE handle;
}; };
tor_mutex_t *tor_mutex_new(void) tor_mutex_t *
tor_mutex_new(void)
{ {
tor_mutex_t *m; tor_mutex_t *m;
m = tor_malloc_zero(sizeof(tor_mutex_t)); m = tor_malloc_zero(sizeof(tor_mutex_t));
...@@ -847,12 +866,14 @@ tor_mutex_t *tor_mutex_new(void) ...@@ -847,12 +866,14 @@ tor_mutex_t *tor_mutex_new(void)
tor_assert(m->handle != NULL); tor_assert(m->handle != NULL);
return m; return m;
} }
void tor_mutex_free(tor_mutex_t *m) void
tor_mutex_free(tor_mutex_t *m)
{ {
CloseHandle(m->handle); CloseHandle(m->handle);
tor_free(m); tor_free(m);
} }
void tor_mutex_acquire(tor_mutex_t *m) void
tor_mutex_acquire(tor_mutex_t *m)
{ {
DWORD r; DWORD r;
r = WaitForSingleObject(m->handle, INFINITE); r = WaitForSingleObject(m->handle, INFINITE);
...@@ -867,7 +888,8 @@ void tor_mutex_acquire(tor_mutex_t *m) ...@@ -867,7 +888,8 @@ void tor_mutex_acquire(tor_mutex_t *m)
log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError()); log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
} }
} }
void tor_mutex_release(tor_mutex_t *m) void
tor_mutex_release(tor_mutex_t *m)
{ {
BOOL r; BOOL r;
r = ReleaseMutex(m->handle); r = ReleaseMutex(m->handle);
...@@ -884,23 +906,27 @@ tor_get_thread_id(void) ...@@ -884,23 +906,27 @@ tor_get_thread_id(void)
struct tor_mutex_t { struct tor_mutex_t {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
tor_mutex_t *tor_mutex_new(void) tor_mutex_t *
tor_mutex_new(void)
{ {
tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t)); tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t));
pthread_mutex_init(&mutex->mutex, NULL); pthread_mutex_init(&mutex->mutex, NULL);
return mutex; return mutex;
} }
void tor_mutex_acquire(tor_mutex_t *m) void
tor_mutex_acquire(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_lock(&m->mutex); pthread_mutex_lock(&m->mutex);
} }
void tor_mutex_release(tor_mutex_t *m) void
tor_mutex_release(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_unlock(&m->mutex); pthread_mutex_unlock(&m->mutex);
} }
void tor_mutex_free(tor_mutex_t *m) void
tor_mutex_free(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_destroy(&m->mutex); pthread_mutex_destroy(&m->mutex);
...@@ -1007,7 +1033,8 @@ struct { int code; const char *msg; } windows_socket_errors[] = { ...@@ -1007,7 +1033,8 @@ struct { int code; const char *msg; } windows_socket_errors[] = {
/** There does not seem to be a strerror equivalent for winsock errors. /** There does not seem to be a strerror equivalent for winsock errors.
* Naturally, we have to roll our own. * Naturally, we have to roll our own.
*/ */
const char *tor_socket_strerror(int e) const char *
tor_socket_strerror(int e)
{ {
int i; int i;
for (i=0; windows_socket_errors[i].code >= 0; ++i) { for (i=0; windows_socket_errors[i].code >= 0; ++i) {
...@@ -1021,7 +1048,8 @@ const char *tor_socket_strerror(int e) ...@@ -1021,7 +1048,8 @@ const char *tor_socket_strerror(int e)
/** Called before we make any calls to network-related functions. /** Called before we make any calls to network-related functions.
* (Some operating systems require their network libraries to be * (Some operating systems require their network libraries to be
* initialized.) */ * initialized.) */
int network_init(void) int
network_init(void)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
/* This silly exercise is necessary before windows will allow gethostbyname to work. /* This silly exercise is necessary before windows will allow gethostbyname to work.
......
...@@ -76,7 +76,8 @@ static INLINE void peek_from_buf(char *string, size_t string_len, buf_t *buf); ...@@ -76,7 +76,8 @@ static INLINE void peek_from_buf(char *string, size_t string_len, buf_t *buf);
* beginning. This operation is relatively expensive, so it shouldn't * beginning. This operation is relatively expensive, so it shouldn't
* be used e.g. for every single read or write. * be used e.g. for every single read or write.
*/ */
static void buf_normalize(buf_t *buf) static void
buf_normalize(buf_t *buf)
{ {
check(); check();
if (buf->cur + buf->datalen <= buf->mem+buf->len) { if (buf->cur + buf->datalen <= buf->mem+buf->len) {
...@@ -96,7 +97,8 @@ static void buf_normalize(buf_t *buf) ...@@ -96,7 +97,8 @@ static void buf_normalize(buf_t *buf)
} }
/** Return the point in the buffer where the next byte will get stored. */ /** Return the point in the buffer where the next byte will get stored. */
static INLINE char *_buf_end(buf_t *buf) static INLINE char *
_buf_end(buf_t *buf)
{ {
char *next = buf->cur + buf->datalen; char *next = buf->cur + buf->datalen;
char *end = buf->mem + buf->len; char *end = buf->mem + buf->len;
...@@ -105,7 +107,8 @@ static INLINE char *_buf_end(buf_t *buf) ...@@ -105,7 +107,8 @@ static INLINE char *_buf_end(buf_t *buf)
/** If the pointer <b>cp</b> has passed beyond the end of the buffer, wrap it /** If the pointer <b>cp</b> has passed beyond the end of the buffer, wrap it
* around. */ * around. */
static INLINE char *_wrap_ptr(buf_t *buf, char *cp) { static INLINE char *
_wrap_ptr(buf_t *buf, char *cp) {
return (cp >= buf->mem + buf->len) ? (cp - buf->len) : cp; return (cp >= buf->mem + buf->len) ? (cp - buf->len) : cp;
} }
...@@ -114,7 +117,8 @@ static INLINE char *_wrap_ptr(buf_t *buf, char *cp) { ...@@ -114,7 +117,8 @@ static INLINE char *_wrap_ptr(buf_t *buf, char *cp) {
* at <b>at</b>, and set *<b>more_len</b> to the number of bytes starting * at <b>at</b>, and set *<b>more_len</b> to the number of bytes starting
* at <b>buf-&gt;mem</b>. Otherwise, set *<b>more_len</b> to 0. * at <b>buf-&gt;mem</b>. Otherwise, set *<b>more_len</b> to 0.
*/ */
static INLINE void _split_range(buf_t *buf, char *at, size_t *len, static INLINE void
_split_range(buf_t *buf, char *at, size_t *len,
size_t *more_len) size_t *more_len)
{ {
char *eos = at + *len; char *eos = at + *len;
...@@ -128,7 +132,8 @@ static INLINE void _split_range(buf_t *buf, char *at, size_t *len, ...@@ -128,7 +132,8 @@ static INLINE void _split_range(buf_t *buf, char *at, size_t *len,
} }
/** Change a buffer's capacity. <b>new_capacity</b> must be \>= buf->datalen. */ /** Change a buffer's capacity. <b>new_capacity</b> must be \>= buf->datalen. */
static void buf_resize(buf_t *buf, size_t new_capacity) static void
buf_resize(buf_t *buf, size_t new_capacity)
{ {
off_t offset; off_t offset;
#ifdef CHECK_AFTER_RESIZE #ifdef CHECK_AFTER_RESIZE
...@@ -225,7 +230,8 @@ static void buf_resize(buf_t *buf, size_t new_capacity) ...@@ -225,7 +230,8 @@ static void buf_resize(buf_t *buf, size_t new_capacity)
* it so that it can. (The new size will be a power of 2 times the old * it so that it can. (The new size will be a power of 2 times the old
* size.) * size.)
*/ */
static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity) static INLINE int
buf_ensure_capacity(buf_t *buf, size_t capacity)
{ {
size_t new_len; size_t new_len;
if (buf->len >= capacity) /* Don't grow if we're already big enough. */ if (buf->len >= capacity) /* Don't grow if we're already big enough. */
...@@ -251,7 +257,8 @@ static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity) ...@@ -251,7 +257,8 @@ static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity)
* one of the above no longer holds. (We shrink the buffer by * one of the above no longer holds. (We shrink the buffer by
* dividing by powers of 2.) * dividing by powers of 2.)
*/ */
static INLINE void buf_shrink_if_underfull(buf_t *buf) { static INLINE void
buf_shrink_if_underfull(buf_t *buf) {
size_t new_len; size_t new_len;
/* If the buffer is at least 1/8 full, or if shrinking the buffer would /* If the buffer is at least 1/8 full, or if shrinking the buffer would
* put it under MIN_GREEDY_SHRINK_SIZE, don't do it. */ * put it under MIN_GREEDY_SHRINK_SIZE, don't do it. */
...@@ -298,7 +305,8 @@ buf_shrink(buf_t *buf) ...@@ -298,7 +305,8 @@ buf_shrink(buf_t *buf)
/** Remove the first <b>n</b> bytes from buf. /** Remove the first <b>n</b> bytes from buf.
*/ */
static INLINE void buf_remove_from_front(buf_t *buf, size_t n) { static INLINE void
buf_remove_from_front(buf_t *buf, size_t n) {
tor_assert(buf->datalen >= n); tor_assert(buf->datalen >= n);
buf->datalen -= n; buf->datalen -= n;
buf_total_used -= n; buf_total_used -= n;
...@@ -312,7 +320,8 @@ static INLINE void buf_remove_from_front(buf_t *buf, size_t n) { ...@@ -312,7 +320,8 @@ static INLINE void buf_remove_from_front(buf_t *buf, size_t n) {
} }
/** Make sure that the memory in buf ends with a zero byte. */ /** Make sure that the memory in buf ends with a zero byte. */
static INLINE int buf_nul_terminate(buf_t *buf) static INLINE int
buf_nul_terminate(buf_t *buf)
{ {
if (buf_ensure_capacity(buf,buf->datalen+1)<0) if (buf_ensure_capacity(buf,buf->datalen+1)<0)
return -1; return -1;
...@@ -322,7 +331,8 @@ static INLINE int buf_nul_terminate(buf_t *buf) ...@@ -322,7 +331,8 @@ static INLINE int buf_nul_terminate(buf_t *buf)
/** Create and return a new buf with capacity <b>size</b>. /** Create and return a new buf with capacity <b>size</b>.
*/ */
buf_t *buf_new_with_capacity(size_t size) { buf_t *
buf_new_with_capacity(size_t size) {
buf_t *buf; buf_t *buf;
buf = tor_malloc_zero(sizeof(buf_t)); buf = tor_malloc_zero(sizeof(buf_t));
buf->magic = BUFFER_MAGIC; buf->magic = BUFFER_MAGIC;
...@@ -336,13 +346,15 @@ buf_t *buf_new_with_capacity(size_t size) { ...@@ -336,13 +346,15 @@ buf_t *buf_new_with_capacity(size_t size) {
} }
/** Allocate and return a new buffer with default capacity. */ /** Allocate and return a new buffer with default capacity. */
buf_t *buf_new() buf_t *
buf_new(void)
{ {
return buf_new_with_capacity(INITIAL_BUF_SIZE); return buf_new_with_capacity(INITIAL_BUF_SIZE);
} }
/** Remove all data from <b>buf</b> */ /** Remove all data from <b>buf</b> */
void buf_clear(buf_t *buf) void
buf_clear(buf_t *buf)
{ {
buf_total_used -= buf->datalen; buf_total_used -= buf->datalen;
buf->datalen = 0; buf->datalen = 0;
...@@ -350,28 +362,33 @@ void buf_clear(buf_t *buf) ...@@ -350,28 +362,33 @@ void buf_clear(buf_t *buf)
} }
/** Return the number of bytes stored in <b>buf</b> */ /** Return the number of bytes stored in <b>buf</b> */
size_t buf_datalen(const buf_t *buf) size_t
buf_datalen(const buf_t *buf)
{ {
return buf->datalen; return buf->datalen;
} }
/** Return the maximum bytes that can be stored in <b>buf</b> before buf /** Return the maximum bytes that can be stored in <b>buf</b> before buf
* needs to resize. */ * needs to resize. */
size_t buf_capacity(const buf_t *buf) size_t
buf_capacity(const buf_t *buf)
{ {
return buf->len; return buf->len;
} }
/** For testing only: Return a pointer to the raw memory stored in <b>buf</b>. /** For testing only: Return a pointer to the raw memory stored in <b>buf</b>.
*/ */
const char *_buf_peek_raw_buffer(const buf_t *buf) const char *
_buf_peek_raw_buffer(const buf_t *buf)
{ {
return buf->cur; return buf->cur;
} }
/** Release storage held by <b>buf</b>. /** Release storage held by <b>buf</b>.
*/ */
void buf_free(buf_t *buf) { void
buf_free(buf_t *buf)
{
assert_buf_ok(buf); assert_buf_ok(buf);
buf->magic = 0xDEADBEEF; buf->magic = 0xDEADBEEF;
free(RAW_MEM(buf->mem)); free(RAW_MEM(buf->mem));
...@@ -380,8 +397,15 @@ void buf_free(buf_t *buf) { ...@@ -380,8 +397,15 @@ void buf_free(buf_t *buf) {
tor_free(buf); tor_free(buf);
} }
static INLINE int read_to_buf_impl(int s, size_t at_most, buf_t *buf, /** Helper for read_to_buf: read no more than at_most bytes from
char *pos, int *reached_eof) * socket s into buffer buf, starting at the position pos. (Does not
* check for overflow.) Set *reached_eof to true on EOF. Return
* number of bytes read on success, 0 if the read would block, -1 on
* failure.
*/
static INLINE int
read_to_buf_impl(int s, size_t at_most, buf_t *buf,
char *pos, int *reached_eof)
{ {
int read_result; int read_result;
...@@ -414,7 +438,8 @@ static INLINE int read_to_buf_impl(int s, size_t at_most, buf_t *buf, ...@@ -414,7 +438,8 @@ static INLINE int read_to_buf_impl(int s, size_t at_most, buf_t *buf,
* else return the number of bytes read. Return 0 if recv() would * else return the number of bytes read. Return 0 if recv() would
* block. * block.
*/ */
int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) int
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
{ {
int r; int r;
char *next; char *next;
...@@ -456,6 +481,11 @@ int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) ...@@ -456,6 +481,11 @@ int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
return r; return r;
} }
/** Helper for read_to_buf_tls: read no more than at_most bytes from
* the TLS connection tlsinto buffer buf, starting at the position
* next. (Does not check for overflow.) Return number of bytes read
* on success, 0 if the read would block, -1 on failure.
*/
static INLINE int