* and the number of bytes read otherwise. */
static INLINE int
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;
#if 0 && defined(HAVE_READV) && !defined(WIN32)
if (e == WSAENOBUFS)
log_warn(LD_NET,"recv() failed: WSAENOBUFS. Not enough ram?");
#endif
+ *socket_error = e;
return -1;
}
return 0; /* would block. */
*/
/* XXXX021 indicate "read blocked" somehow? */
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:
* "error status" and "number of bytes read" are not mutually exclusive.
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();
if (r < 0)
return r; /* Error */
static int connection_flushed_some(connection_t *conn);
static int connection_finished_connecting(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 void client_check_address_changed(int sock);
static void set_constrained_socket_buffers(int sock, int size);
{
int max_to_read=-1, try_to_read;
size_t before, n_read = 0;
+ int socket_error = 0;
if (conn->marked_for_close)
return 0; /* do nothing */
tor_assert(!conn->marked_for_close);
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.*/
if (conn->type == CONN_TYPE_OR &&
conn->state == OR_CONN_STATE_CONNECTING) {
- int socket_error = tor_socket_errno(conn->s);
connection_or_connect_failed(TO_OR_CONN(conn),
errno_to_orconn_end_reason(socket_error),
tor_socket_strerror(socket_error));
* Return -1 if we want to break conn, else return 0.
*/
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;
ssize_t at_most = *max_to_read;
/* !connection_speaks_cells, !conn->linked_conn. */
int reached_eof = 0;
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)
conn->inbuf_reached_eof = 1;
size_t buf_slack(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 flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen);