mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Remove the connection_t.outbuf_flushlen field
This was once used for rate-limiting, but now it's only for accounting. It hasn't served a useful purpose in a long time. Closes ticket 33097.
This commit is contained in:
committed by
Alexander Færøy
parent
e8497bfaa7
commit
3cb9a9b8ce
@@ -685,17 +685,20 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen)
|
||||
}
|
||||
|
||||
/** Moves all data from <b>buf_in</b> to <b>buf_out</b>, without copying.
|
||||
* Return the number of bytes that were moved.
|
||||
*/
|
||||
void
|
||||
size_t
|
||||
buf_move_all(buf_t *buf_out, buf_t *buf_in)
|
||||
{
|
||||
tor_assert(buf_out);
|
||||
if (!buf_in)
|
||||
return;
|
||||
return 0;
|
||||
if (BUG(buf_out->datalen > BUF_MAX_LEN || buf_in->datalen > BUF_MAX_LEN))
|
||||
return;
|
||||
return 0;
|
||||
if (BUG(buf_out->datalen > BUF_MAX_LEN - buf_in->datalen))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
size_t n_bytes_moved = buf_in->datalen;
|
||||
|
||||
if (buf_out->head == NULL) {
|
||||
buf_out->head = buf_in->head;
|
||||
@@ -708,6 +711,8 @@ buf_move_all(buf_t *buf_out, buf_t *buf_in)
|
||||
buf_out->datalen += buf_in->datalen;
|
||||
buf_in->head = buf_in->tail = NULL;
|
||||
buf_in->datalen = 0;
|
||||
|
||||
return n_bytes_moved;
|
||||
}
|
||||
|
||||
/** Internal structure: represents a position in a buffer. */
|
||||
|
||||
@@ -46,7 +46,7 @@ void buf_add_printf(buf_t *buf, const char *format, ...)
|
||||
void buf_add_vprintf(buf_t *buf, const char *format, va_list args)
|
||||
CHECK_PRINTF(2, 0);
|
||||
int buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
|
||||
void buf_move_all(buf_t *buf_out, buf_t *buf_in);
|
||||
size_t buf_move_all(buf_t *buf_out, buf_t *buf_in);
|
||||
void buf_peek(const buf_t *buf, char *string, size_t string_len);
|
||||
void buf_drain(buf_t *buf, size_t n);
|
||||
int buf_get_bytes(buf_t *buf, char *string, size_t string_len);
|
||||
|
||||
+12
-21
@@ -137,13 +137,12 @@ buf_read_from_fd(buf_t *buf, int fd, size_t at_most,
|
||||
}
|
||||
|
||||
/** Helper for buf_flush_to_socket(): try to write <b>sz</b> bytes from chunk
|
||||
* <b>chunk</b> of buffer <b>buf</b> onto file descriptor <b>fd</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.
|
||||
* <b>chunk</b> of buffer <b>buf</b> onto file descriptor <b>fd</b>. Return
|
||||
* the number of bytes written on success, 0 on blocking, -1 on failure.
|
||||
*/
|
||||
static inline int
|
||||
flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
|
||||
size_t *buf_flushlen, bool is_socket)
|
||||
bool is_socket)
|
||||
{
|
||||
ssize_t write_result;
|
||||
|
||||
@@ -168,7 +167,6 @@ flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
|
||||
log_debug(LD_NET,"write() would block, returning.");
|
||||
return 0;
|
||||
} else {
|
||||
*buf_flushlen -= write_result;
|
||||
buf_drain(buf, write_result);
|
||||
tor_assert(write_result <= BUF_MAX_LEN);
|
||||
return (int)write_result;
|
||||
@@ -176,27 +174,22 @@ flush_chunk(tor_socket_t fd, buf_t *buf, chunk_t *chunk, size_t sz,
|
||||
}
|
||||
|
||||
/** Write data from <b>buf</b> to the file descriptor <b>fd</b>. Write at most
|
||||
* <b>sz</b> bytes, decrement *<b>buf_flushlen</b> by
|
||||
* the number of bytes actually written, and remove the written bytes
|
||||
* <b>sz</b> bytes, and remove the written bytes
|
||||
* from the buffer. Return the number of bytes written on success,
|
||||
* -1 on failure. Return 0 if write() would block.
|
||||
*/
|
||||
static int
|
||||
buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
|
||||
size_t *buf_flushlen, bool is_socket)
|
||||
bool is_socket)
|
||||
{
|
||||
/* XXXX 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);
|
||||
tor_assert(SOCKET_OK(fd));
|
||||
if (BUG(*buf_flushlen > buf->datalen)) {
|
||||
*buf_flushlen = buf->datalen;
|
||||
}
|
||||
if (BUG(sz > *buf_flushlen)) {
|
||||
sz = *buf_flushlen;
|
||||
if (BUG(sz > buf->datalen)) {
|
||||
sz = buf->datalen;
|
||||
}
|
||||
|
||||
check();
|
||||
@@ -208,7 +201,7 @@ buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
|
||||
else
|
||||
flushlen0 = buf->head->datalen;
|
||||
|
||||
r = flush_chunk(fd, buf, buf->head, flushlen0, buf_flushlen, is_socket);
|
||||
r = flush_chunk(fd, buf, buf->head, flushlen0, is_socket);
|
||||
check();
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -228,10 +221,9 @@ buf_flush_to_fd(buf_t *buf, int fd, size_t sz,
|
||||
* -1 on failure. Return 0 if write() would block.
|
||||
*/
|
||||
int
|
||||
buf_flush_to_socket(buf_t *buf, tor_socket_t s, size_t sz,
|
||||
size_t *buf_flushlen)
|
||||
buf_flush_to_socket(buf_t *buf, tor_socket_t s, size_t sz)
|
||||
{
|
||||
return buf_flush_to_fd(buf, s, sz, buf_flushlen, true);
|
||||
return buf_flush_to_fd(buf, s, sz, true);
|
||||
}
|
||||
|
||||
/** Read from socket <b>s</b>, writing onto end of <b>buf</b>. Read at most
|
||||
@@ -254,10 +246,9 @@ buf_read_from_socket(buf_t *buf, tor_socket_t s, size_t at_most,
|
||||
* -1 on failure. Return 0 if write() would block.
|
||||
*/
|
||||
int
|
||||
buf_flush_to_pipe(buf_t *buf, int fd, size_t sz,
|
||||
size_t *buf_flushlen)
|
||||
buf_flush_to_pipe(buf_t *buf, int fd, size_t sz)
|
||||
{
|
||||
return buf_flush_to_fd(buf, fd, sz, buf_flushlen, false);
|
||||
return buf_flush_to_fd(buf, fd, sz, false);
|
||||
}
|
||||
|
||||
/** Read from pipe <b>fd</b>, writing onto end of <b>buf</b>. Read at most
|
||||
|
||||
@@ -21,14 +21,12 @@ int buf_read_from_socket(struct buf_t *buf, tor_socket_t s, size_t at_most,
|
||||
int *reached_eof,
|
||||
int *socket_error);
|
||||
|
||||
int buf_flush_to_socket(struct buf_t *buf, tor_socket_t s, size_t sz,
|
||||
size_t *buf_flushlen);
|
||||
int buf_flush_to_socket(struct buf_t *buf, tor_socket_t s, size_t sz);
|
||||
|
||||
int buf_read_from_pipe(struct buf_t *buf, int fd, size_t at_most,
|
||||
int *reached_eof,
|
||||
int *socket_error);
|
||||
|
||||
int buf_flush_to_pipe(struct buf_t *buf, int fd, size_t sz,
|
||||
size_t *buf_flushlen);
|
||||
int buf_flush_to_pipe(struct buf_t *buf, int fd, size_t sz);
|
||||
|
||||
#endif /* !defined(TOR_BUFFERS_NET_H) */
|
||||
|
||||
@@ -418,7 +418,7 @@ process_unix_write(process_t *process, buf_t *buffer)
|
||||
/* We have data to write and the kernel have told us to write it. */
|
||||
return buf_flush_to_pipe(buffer,
|
||||
process_get_unix_process(process)->stdin_handle.fd,
|
||||
max_to_write, &buffer_flush_len);
|
||||
max_to_write);
|
||||
}
|
||||
|
||||
/** Read data from the given process's standard output and put it into
|
||||
|
||||
@@ -106,8 +106,7 @@ buf_read_from_tls(buf_t *buf, tor_tls_t *tls, size_t at_most)
|
||||
* written on success, and a TOR_TLS error code on failure or blocking.
|
||||
*/
|
||||
static inline int
|
||||
flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
|
||||
size_t sz, size_t *buf_flushlen)
|
||||
flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk, size_t sz)
|
||||
{
|
||||
int r;
|
||||
size_t forced;
|
||||
@@ -126,13 +125,9 @@ flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
|
||||
r = tor_tls_write(tls, data, sz);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (*buf_flushlen > (size_t)r)
|
||||
*buf_flushlen -= r;
|
||||
else
|
||||
*buf_flushlen = 0;
|
||||
buf_drain(buf, r);
|
||||
log_debug(LD_NET,"flushed %d bytes, %d ready to flush, %d remain.",
|
||||
r,(int)*buf_flushlen,(int)buf->datalen);
|
||||
log_debug(LD_NET,"flushed %d bytes, %d remain.",
|
||||
r,(int)buf->datalen);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -140,18 +135,13 @@ flush_chunk_tls(tor_tls_t *tls, buf_t *buf, chunk_t *chunk,
|
||||
* more than <b>flushlen</b> bytes.
|
||||
*/
|
||||
int
|
||||
buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
|
||||
size_t *buf_flushlen)
|
||||
buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen)
|
||||
{
|
||||
int r;
|
||||
size_t flushed = 0;
|
||||
ssize_t sz;
|
||||
tor_assert(buf_flushlen);
|
||||
IF_BUG_ONCE(*buf_flushlen > buf->datalen) {
|
||||
*buf_flushlen = buf->datalen;
|
||||
}
|
||||
IF_BUG_ONCE(flushlen > *buf_flushlen) {
|
||||
flushlen = *buf_flushlen;
|
||||
IF_BUG_ONCE(flushlen > buf->datalen) {
|
||||
flushlen = buf->datalen;
|
||||
}
|
||||
sz = (ssize_t) flushlen;
|
||||
|
||||
@@ -170,7 +160,7 @@ buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen,
|
||||
flushlen0 = 0;
|
||||
}
|
||||
|
||||
r = flush_chunk_tls(tls, buf, buf->head, flushlen0, buf_flushlen);
|
||||
r = flush_chunk_tls(tls, buf, buf->head, flushlen0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
flushed += r;
|
||||
|
||||
@@ -18,6 +18,6 @@ struct tor_tls_t;
|
||||
int buf_read_from_tls(struct buf_t *buf,
|
||||
struct tor_tls_t *tls, size_t at_most);
|
||||
int buf_flush_to_tls(struct buf_t *buf, struct tor_tls_t *tls,
|
||||
size_t sz, size_t *buf_flushlen);
|
||||
size_t sz);
|
||||
|
||||
#endif /* !defined(TOR_BUFFERS_TLS_H) */
|
||||
|
||||
Reference in New Issue
Block a user