summaryrefslogtreecommitdiff
path: root/src/node_crypto_bio.cc
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2013-11-28 00:11:17 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2013-12-07 03:48:43 +0400
commit06b194529828567086190681e2aee8ce2a00d760 (patch)
tree23844928c773fa97c8b12f9953750847394160d6 /src/node_crypto_bio.cc
parent03747f69fba646dc9902519c1736d5f4f267ef7b (diff)
downloadandroid-node-v8-06b194529828567086190681e2aee8ce2a00d760.tar.gz
android-node-v8-06b194529828567086190681e2aee8ce2a00d760.tar.bz2
android-node-v8-06b194529828567086190681e2aee8ce2a00d760.zip
crypto: fix moving read head
Fix various possible stalls of read head (i.e. try moving it after every write head update). NOTE: This is actually backported from `bud`.
Diffstat (limited to 'src/node_crypto_bio.cc')
-rw-r--r--src/node_crypto_bio.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc
index 84dc42b464..eaf8f76a51 100644
--- a/src/node_crypto_bio.cc
+++ b/src/node_crypto_bio.cc
@@ -223,17 +223,17 @@ void NodeBIO::TryMoveReadHead() {
// inside the buffer, respectively. When they're equal - its safe to reset
// them, because both reader and writer will continue doing their stuff
// from new (zero) positions.
- if (read_head_->read_pos_ != read_head_->write_pos_)
- return;
-
- // Reset positions
- read_head_->read_pos_ = 0;
- read_head_->write_pos_ = 0;
+ while (read_head_->read_pos_ != 0 &&
+ read_head_->read_pos_ == read_head_->write_pos_) {
+ // Reset positions
+ read_head_->read_pos_ = 0;
+ read_head_->write_pos_ = 0;
- // Move read_head_ forward, just in case if there're still some data to
- // read in the next buffer.
- if (read_head_ != write_head_)
- read_head_ = read_head_->next_;
+ // Move read_head_ forward, just in case if there're still some data to
+ // read in the next buffer.
+ if (read_head_ != write_head_)
+ read_head_ = read_head_->next_;
+ }
}
@@ -397,8 +397,13 @@ void NodeBIO::Commit(size_t size) {
// Allocate new buffer if write head is full,
// and there're no other place to go
TryAllocateForWrite();
- if (write_head_->write_pos_ == kBufferLength)
+ if (write_head_->write_pos_ == kBufferLength) {
write_head_ = write_head_->next_;
+
+ // Additionally, since we're moved to the next buffer, read head
+ // may be moved as well.
+ TryMoveReadHead();
+ }
}