소스 검색

r11566@Kushana: nickm | 2006-12-13 17:46:24 -0500
Try to fix an assert failure in new write limiting code: make buffers.c aware of previous "forced" write sizes from tortls.


svn:r9105

Nick Mathewson 17 년 전
부모
커밋
43e06eba8b
3개의 변경된 파일17개의 추가작업 그리고 4개의 파일을 삭제
  1. 7 0
      src/common/tortls.c
  2. 1 0
      src/common/tortls.h
  3. 9 4
      src/or/buffers.c

+ 7 - 0
src/common/tortls.c

@@ -850,7 +850,14 @@ tor_tls_get_pending_bytes(tor_tls_t *tls)
     return 0;
 #endif
   return SSL_pending(tls->ssl);
+}
 
+/** If <b>tls</b> requires that the next write be of a particular size,
+ * return that size.  Otherwise, return 0. */
+size_t
+tor_tls_get_forced_write_size(tor_tls_t *tls)
+{
+  return tls->wantwrite_n;
 }
 
 /** Return the number of bytes read across the underlying socket. */

+ 1 - 0
src/common/tortls.h

@@ -41,6 +41,7 @@ int tor_tls_write(tor_tls_t *tls, char *cp, size_t n);
 int tor_tls_handshake(tor_tls_t *tls);
 int tor_tls_shutdown(tor_tls_t *tls);
 int tor_tls_get_pending_bytes(tor_tls_t *tls);
+size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
 
 unsigned long tor_tls_get_n_bytes_read(tor_tls_t *tls);
 unsigned long tor_tls_get_n_bytes_written(tor_tls_t *tls);

+ 9 - 4
src/or/buffers.c

@@ -648,16 +648,21 @@ flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
   return flushed;
 }
 
-/** Helper for flush_buf_tls(): try to write <b>sz</b> bytes from buffer
- * <b>buf</b> onto TLS object <b>tls</b>.  On success, deduct the bytes
- * written from *<b>buf_flushlen</b>.
- * Return the number of bytes written on success, -1 on failure.
+/** Helper for flush_buf_tls(): try to write <b>sz</b> bytes (or more if
+ * required by a previous write) from buffer <b>buf</b> onto TLS object
+ * <b>tls</b>.  On success, deduct the bytes written from
+ * *<b>buf_flushlen</b>.  Return the number of bytes written on success, -1 on
+ * failure.
  */
 static INLINE int
 flush_buf_tls_impl(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen)
 {
   int r;
+  size_t forced;
 
+  forced = tor_tls_get_forced_write_size(tls);
+  if (forced < sz)
+    sz = forced;
   r = tor_tls_write(tls, buf->cur, sz);
   if (r < 0) {
     return r;