mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
clean read_to_buf more
svn:r428
This commit is contained in:
parent
77dfd7826d
commit
99035f3520
@ -50,18 +50,6 @@ int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, i
|
|||||||
if(at_most == 0)
|
if(at_most == 0)
|
||||||
return 0; /* we shouldn't read anything */
|
return 0; /* we shouldn't read anything */
|
||||||
|
|
||||||
if(!options.LinkPadding && at_most > 10*sizeof(cell_t)) {
|
|
||||||
/* if no linkpadding: do a rudimentary round-robin so one
|
|
||||||
* connection can't hog a thickpipe
|
|
||||||
*/
|
|
||||||
at_most = 10*(CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE);
|
|
||||||
/* XXX this still isn't perfect. now we read 10 relay data payloads per read --
|
|
||||||
* but if we're reading from a connection that speaks cells, we always
|
|
||||||
* read a partial cell from the network and can't process it yet. Good
|
|
||||||
* enough for now though. (And maybe best, to stress our code more.)
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
|
// log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
|
||||||
read_result = read(s, *buf+*buf_datalen, at_most);
|
read_result = read(s, *buf+*buf_datalen, at_most);
|
||||||
if (read_result < 0) {
|
if (read_result < 0) {
|
||||||
|
@ -305,8 +305,8 @@ int connection_handle_read(connection_t *conn) {
|
|||||||
/* XXX I suspect pollerr may make Windows not get to this point. :( */
|
/* XXX I suspect pollerr may make Windows not get to this point. :( */
|
||||||
router_forget_router(conn->addr,conn->port);
|
router_forget_router(conn->addr,conn->port);
|
||||||
/* FIXME i don't think router_forget_router works. */
|
/* FIXME i don't think router_forget_router works. */
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(connection_process_inbuf(conn) < 0) {
|
if(connection_process_inbuf(conn) < 0) {
|
||||||
//log_fn(LOG_DEBUG,"connection_process_inbuf returned %d.",retval);
|
//log_fn(LOG_DEBUG,"connection_process_inbuf returned %d.",retval);
|
||||||
@ -322,12 +322,23 @@ int connection_handle_read(connection_t *conn) {
|
|||||||
|
|
||||||
int connection_read_to_buf(connection_t *conn) {
|
int connection_read_to_buf(connection_t *conn) {
|
||||||
int read_result;
|
int read_result;
|
||||||
int at_most = global_read_bucket;
|
int at_most;
|
||||||
|
|
||||||
if(connection_speaks_cells(conn)) {
|
assert((connection_speaks_cells(conn) && conn->receiver_bucket >= 0) ||
|
||||||
assert(conn->receiver_bucket >= 0);
|
(!connection_speaks_cells(conn) && conn->receiver_bucket < 0));
|
||||||
|
|
||||||
|
if(options.LinkPadding) {
|
||||||
|
at_most = global_read_bucket;
|
||||||
} else {
|
} else {
|
||||||
assert(conn->receiver_bucket < 0);
|
/* do a rudimentary round-robin so one connection can't hog a thickpipe */
|
||||||
|
if(connection_speaks_cells(conn)) {
|
||||||
|
at_most = 10*(CELL_NETWORK_SIZE);
|
||||||
|
} else {
|
||||||
|
at_most = 10*(CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(at_most > global_read_bucket)
|
||||||
|
at_most = global_read_bucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(conn->receiver_bucket >= 0 && at_most > conn->receiver_bucket)
|
if(conn->receiver_bucket >= 0 && at_most > conn->receiver_bucket)
|
||||||
@ -348,7 +359,7 @@ int connection_read_to_buf(connection_t *conn) {
|
|||||||
/* If we're not in 'open' state here, then we're never going to finish the
|
/* If we're not in 'open' state here, then we're never going to finish the
|
||||||
* handshake, because we'll never increment the receiver_bucket. But we
|
* handshake, because we'll never increment the receiver_bucket. But we
|
||||||
* can't check for that here, because the buf we just read might have enough
|
* can't check for that here, because the buf we just read might have enough
|
||||||
* on it to finish the handshake. So we check for that in conn_read().
|
* on it to finish the handshake. So we check for that in connection_handle_read().
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include "../common/fakepoll.h"
|
#include "../common/fakepoll.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h> /* Must be included before sys/stat.h for Ultrix */
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
#ifdef HAVE_SYS_WAIT_H
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -489,7 +489,7 @@ void buf_free(char *buf);
|
|||||||
int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof);
|
int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof);
|
||||||
/* grab from s, put onto buf, return how many bytes read */
|
/* grab from s, put onto buf, return how many bytes read */
|
||||||
int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen);
|
int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen);
|
||||||
/* grab from s, put onto buf, return how many bytes read or a TLS
|
/* grab from tls, put onto buf, return how many bytes read or a TLS
|
||||||
* status (same status codes as tor_tls_read) */
|
* status (same status codes as tor_tls_read) */
|
||||||
|
|
||||||
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
|
int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
|
||||||
|
Loading…
Reference in New Issue
Block a user