]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
read_to_buf should take an int *error_socket and return it.
authorRoger Dingledine <arma@torproject.org>
Sun, 14 Sep 2008 08:35:41 +0000 (08:35 +0000)
committerRoger Dingledine <arma@torproject.org>
Sun, 14 Sep 2008 08:35:41 +0000 (08:35 +0000)
svn:r16909

src/or/buffers.c
src/or/connection.c
src/or/or.h

index 61d4b9d7f798d4460457de37ed05acd8292db3da..634df13b10575ca1a747cfdc7c5b631ddfae0d3f 100644 (file)
@@ -562,7 +562,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
  * 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)
@@ -592,6 +592,7 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
       if (e == WSAENOBUFS)
         log_warn(LD_NET,"recv() failed: WSAENOBUFS. Not enough ram?");
 #endif
+      *socket_error = e;
       return -1;
     }
     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? */
 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.
@@ -667,7 +669,7 @@ read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
         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 */
index fac73b52fd5fdbefc1e042cfb1c5dd8c7aa8127c..41d7020bd924909b89c787dfd01810dfdbe4924d 100644 (file)
@@ -28,7 +28,8 @@ static int connection_finished_flushing(connection_t *conn);
 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);
@@ -1910,6 +1911,7 @@ connection_handle_read(connection_t *conn)
 {
   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 */
@@ -1938,11 +1940,10 @@ loop_again:
   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));
@@ -2022,7 +2023,7 @@ loop_again:
  * 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;
@@ -2129,7 +2130,8 @@ connection_read_to_buf(connection_t *conn, int *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;
 
index 81345e2f2f3b0c29a4dee7204474bea209b44f69..5ad3d59b2142a90b870f3e9253c515d23152e11f 100644 (file)
@@ -2558,7 +2558,8 @@ size_t buf_allocation(const buf_t *buf);
 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);