[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r16909: {tor} read_to_buf should take an int *error_socket and return it. (tor/trunk/src/or)



Author: arma
Date: 2008-09-14 04:35:41 -0400 (Sun, 14 Sep 2008)
New Revision: 16909

Modified:
   tor/trunk/src/or/buffers.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/or.h
Log:
read_to_buf should take an int *error_socket and return it.


Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c	2008-09-14 07:17:44 UTC (rev 16908)
+++ tor/trunk/src/or/buffers.c	2008-09-14 08:35:41 UTC (rev 16909)
@@ -562,7 +562,7 @@
  * 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 @@
       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 @@
  */
 /* 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 @@
         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 */

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2008-09-14 07:17:44 UTC (rev 16908)
+++ tor/trunk/src/or/connection.c	2008-09-14 08:35:41 UTC (rev 16909)
@@ -28,7 +28,8 @@
 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 @@
 {
   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 @@
   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 @@
  * 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_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;
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-09-14 07:17:44 UTC (rev 16908)
+++ tor/trunk/src/or/or.h	2008-09-14 08:35:41 UTC (rev 16909)
@@ -2558,7 +2558,8 @@
 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);