Browse code

tcp: don't reset read_flags on RD_CONN_REPEAT_READ

Allow flags value propagation between tcp_read*() that asked to be
repeated (RD_CONN_REPEAT_READ). This allows an optimization in the
tls read code: when repeating a tls_read, don't try a tcp read
syscall if the previous attempt did get the whole socket receive
buffer (RD_CONN_SHORT_READ) or detected EOF (use only the buffered
data if any).

Andrei Pelinescu-Onciul authored on 20/06/2010 17:20:12
Showing 1 changed files
... ...
@@ -137,8 +137,8 @@ static ticks_t tcp_reader_prev_ticks;
137 137
  *                           RD_CONN_FORCE_EOF.
138 138
  *             RD_CONN_REPEAT_READ - the read should be repeated immediately
139 139
  *                                   (used only by the tls code for now).
140
- *     Note: RD_CONN_SHORT_READ & RD_CONN_EOF must be cleared
141
- *           before calling this function.
140
+ *     Note: RD_CONN_SHORT_READ & RD_CONN_EOF _are_ not cleared internally,
141
+ *           so one should clear them before calling this function.
142 142
  * @return number of bytes read, 0 on EOF or -1 on error,
143 143
  * on EOF it also sets c->state to S_CONN_EOF.
144 144
  * (to distinguish from reads that would block which could return 0)
... ...
@@ -955,14 +955,14 @@ again:
955 955
 							con, con->id, atomic_get(&con->refcnt));
956 956
 				goto con_error;
957 957
 			}
958
-#ifdef USE_TLS
959
-repeat_1st_read:
960
-#endif /* USE_TLS */
961 958
 			/* if we received the fd there is most likely data waiting to
962 959
 			 * be read => process it first to avoid extra sys calls */
963 960
 			read_flags=((con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)) &&
964 961
 						!(con->flags & F_CONN_OOB_DATA))? RD_CONN_FORCE_EOF
965 962
 						:0;
963
+#ifdef USE_TLS
964
+repeat_1st_read:
965
+#endif /* USE_TLS */
966 966
 			resp=tcp_read_req(con, &n, &read_flags);
967 967
 			if (unlikely(resp<0)){
968 968
 				/* some error occured, but on the new fd, not on the tcp
... ...
@@ -1011,9 +1011,6 @@ repeat_1st_read:
1011 1011
 							con, con->id, atomic_get(&con->refcnt));
1012 1012
 				goto read_error;
1013 1013
 			}
1014
-#ifdef USE_TLS
1015
-repeat_read:
1016
-#endif /* USE_TLS */
1017 1014
 #ifdef POLLRDHUP
1018 1015
 			read_flags=(((events & POLLRDHUP) |
1019 1016
 							(con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)))
... ...
@@ -1021,6 +1018,9 @@ repeat_read:
1021 1021
 #else /* POLLRDHUP */
1022 1022
 			read_flags=0;
1023 1023
 #endif /* POLLRDHUP */
1024
+#ifdef USE_TLS
1025
+repeat_read:
1026
+#endif /* USE_TLS */
1024 1027
 			resp=tcp_read_req(con, &ret, &read_flags);
1025 1028
 			if (unlikely(resp<0)){
1026 1029
 read_error: