mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
read_to_buf should take an int *error_socket and return it.
svn:r16909
This commit is contained in:
parent
7f2fd34645
commit
2bde30efa6
@ -562,7 +562,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
|
|||||||
* and the number of bytes read otherwise. */
|
* and the number of bytes read otherwise. */
|
||||||
static INLINE int
|
static INLINE int
|
||||||
read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
|
read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
|
||||||
int *reached_eof)
|
int *reached_eof, int *socket_error)
|
||||||
{
|
{
|
||||||
ssize_t read_result;
|
ssize_t read_result;
|
||||||
#if 0 && defined(HAVE_READV) && !defined(WIN32)
|
#if 0 && defined(HAVE_READV) && !defined(WIN32)
|
||||||
@ -592,6 +592,7 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
|
|||||||
if (e == WSAENOBUFS)
|
if (e == WSAENOBUFS)
|
||||||
log_warn(LD_NET,"recv() failed: WSAENOBUFS. Not enough ram?");
|
log_warn(LD_NET,"recv() failed: WSAENOBUFS. Not enough ram?");
|
||||||
#endif
|
#endif
|
||||||
|
*socket_error = e;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0; /* would block. */
|
return 0; /* would block. */
|
||||||
@ -641,7 +642,8 @@ read_to_chunk_tls(buf_t *buf, chunk_t *chunk, tor_tls_t *tls,
|
|||||||
*/
|
*/
|
||||||
/* XXXX021 indicate "read blocked" somehow? */
|
/* XXXX021 indicate "read blocked" somehow? */
|
||||||
int
|
int
|
||||||
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
|
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof,
|
||||||
|
int *socket_error)
|
||||||
{
|
{
|
||||||
/* XXXX021 It's stupid to overload the return values for these functions:
|
/* XXXX021 It's stupid to overload the return values for these functions:
|
||||||
* "error status" and "number of bytes read" are not mutually exclusive.
|
* "error status" and "number of bytes read" are not mutually exclusive.
|
||||||
@ -667,7 +669,7 @@ read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
|
|||||||
readlen = cap;
|
readlen = cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = read_to_chunk(buf, chunk, s, readlen, reached_eof);
|
r = read_to_chunk(buf, chunk, s, readlen, reached_eof, socket_error);
|
||||||
check();
|
check();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r; /* Error */
|
return r; /* Error */
|
||||||
|
@ -28,7 +28,8 @@ static int connection_finished_flushing(connection_t *conn);
|
|||||||
static int connection_flushed_some(connection_t *conn);
|
static int connection_flushed_some(connection_t *conn);
|
||||||
static int connection_finished_connecting(connection_t *conn);
|
static int connection_finished_connecting(connection_t *conn);
|
||||||
static int connection_reached_eof(connection_t *conn);
|
static int connection_reached_eof(connection_t *conn);
|
||||||
static int connection_read_to_buf(connection_t *conn, int *max_to_read);
|
static int connection_read_to_buf(connection_t *conn, int *max_to_read,
|
||||||
|
int *socket_error);
|
||||||
static int connection_process_inbuf(connection_t *conn, int package_partial);
|
static int connection_process_inbuf(connection_t *conn, int package_partial);
|
||||||
static void client_check_address_changed(int sock);
|
static void client_check_address_changed(int sock);
|
||||||
static void set_constrained_socket_buffers(int sock, int size);
|
static void set_constrained_socket_buffers(int sock, int size);
|
||||||
@ -1910,6 +1911,7 @@ connection_handle_read(connection_t *conn)
|
|||||||
{
|
{
|
||||||
int max_to_read=-1, try_to_read;
|
int max_to_read=-1, try_to_read;
|
||||||
size_t before, n_read = 0;
|
size_t before, n_read = 0;
|
||||||
|
int socket_error = 0;
|
||||||
|
|
||||||
if (conn->marked_for_close)
|
if (conn->marked_for_close)
|
||||||
return 0; /* do nothing */
|
return 0; /* do nothing */
|
||||||
@ -1938,11 +1940,10 @@ loop_again:
|
|||||||
tor_assert(!conn->marked_for_close);
|
tor_assert(!conn->marked_for_close);
|
||||||
|
|
||||||
before = buf_datalen(conn->inbuf);
|
before = buf_datalen(conn->inbuf);
|
||||||
if (connection_read_to_buf(conn, &max_to_read) < 0) {
|
if (connection_read_to_buf(conn, &max_to_read, &socket_error) < 0) {
|
||||||
/* There's a read error; kill the connection.*/
|
/* There's a read error; kill the connection.*/
|
||||||
if (conn->type == CONN_TYPE_OR &&
|
if (conn->type == CONN_TYPE_OR &&
|
||||||
conn->state == OR_CONN_STATE_CONNECTING) {
|
conn->state == OR_CONN_STATE_CONNECTING) {
|
||||||
int socket_error = tor_socket_errno(conn->s);
|
|
||||||
connection_or_connect_failed(TO_OR_CONN(conn),
|
connection_or_connect_failed(TO_OR_CONN(conn),
|
||||||
errno_to_orconn_end_reason(socket_error),
|
errno_to_orconn_end_reason(socket_error),
|
||||||
tor_socket_strerror(socket_error));
|
tor_socket_strerror(socket_error));
|
||||||
@ -2022,7 +2023,7 @@ loop_again:
|
|||||||
* Return -1 if we want to break conn, else return 0.
|
* Return -1 if we want to break conn, else return 0.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
connection_read_to_buf(connection_t *conn, int *max_to_read)
|
connection_read_to_buf(connection_t *conn, int *max_to_read, int *socket_error)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
ssize_t at_most = *max_to_read;
|
ssize_t at_most = *max_to_read;
|
||||||
@ -2129,7 +2130,8 @@ connection_read_to_buf(connection_t *conn, int *max_to_read)
|
|||||||
/* !connection_speaks_cells, !conn->linked_conn. */
|
/* !connection_speaks_cells, !conn->linked_conn. */
|
||||||
int reached_eof = 0;
|
int reached_eof = 0;
|
||||||
CONN_LOG_PROTECT(conn,
|
CONN_LOG_PROTECT(conn,
|
||||||
result = read_to_buf(conn->s, at_most, conn->inbuf, &reached_eof));
|
result = read_to_buf(conn->s, at_most, conn->inbuf, &reached_eof,
|
||||||
|
socket_error));
|
||||||
if (reached_eof)
|
if (reached_eof)
|
||||||
conn->inbuf_reached_eof = 1;
|
conn->inbuf_reached_eof = 1;
|
||||||
|
|
||||||
|
@ -2558,7 +2558,8 @@ size_t buf_allocation(const buf_t *buf);
|
|||||||
size_t buf_slack(const buf_t *buf);
|
size_t buf_slack(const buf_t *buf);
|
||||||
const char *_buf_peek_raw_buffer(const buf_t *buf);
|
const char *_buf_peek_raw_buffer(const buf_t *buf);
|
||||||
|
|
||||||
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 *socket_error);
|
||||||
int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf);
|
int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf);
|
||||||
|
|
||||||
int flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen);
|
int flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen);
|
||||||
|
Loading…
Reference in New Issue
Block a user