@@ -21,6 +21,7 @@ using v8::Exception; |
21 | 21 | using v8::Function; |
22 | 22 | using v8::FunctionCallbackInfo; |
23 | 23 | using v8::FunctionTemplate; |
| 24 | +using v8::Integer; |
24 | 25 | using v8::Local; |
25 | 26 | using v8::Object; |
26 | 27 | using v8::String; |
@@ -276,6 +277,7 @@ void TLSWrap::EncOut() { |
276 | 277 |
|
277 | 278 | // No data to write |
278 | 279 | if (BIO_pending(enc_out_) == 0) { |
| 280 | + UpdateWriteQueueSize(); |
279 | 281 | if (clear_in_->Length() == 0) |
280 | 282 | InvokeQueued(0); |
281 | 283 | return; |
@@ -530,6 +532,18 @@ bool TLSWrap::IsClosing() { |
530 | 532 | } |
531 | 533 |
|
532 | 534 |
|
| 535 | +uint32_t TLSWrap::UpdateWriteQueueSize(uint32_t write_queue_size) { |
| 536 | + HandleScope scope(env()->isolate()); |
| 537 | + if (write_queue_size == 0) |
| 538 | + write_queue_size = BIO_pending(enc_out_); |
| 539 | + object()->Set(env()->context(), |
| 540 | + env()->write_queue_size_string(), |
| 541 | + Integer::NewFromUnsigned(env()->isolate(), |
| 542 | + write_queue_size)).FromJust(); |
| 543 | + return write_queue_size; |
| 544 | +} |
| 545 | + |
| 546 | + |
533 | 547 | int TLSWrap::ReadStart() { |
534 | 548 | return stream_->ReadStart(); |
535 | 549 | } |
@@ -570,8 +584,12 @@ int TLSWrap::DoWrite(WriteWrap* w, |
570 | 584 | ClearOut(); |
571 | 585 | // However, if there is any data that should be written to the socket, |
572 | 586 | // the callback should not be invoked immediately |
573 | | - if (BIO_pending(enc_out_) == 0) |
| 587 | + if (BIO_pending(enc_out_) == 0) { |
| 588 | + // net.js expects writeQueueSize to be > 0 if the write isn't |
| 589 | + // immediately flushed |
| 590 | + UpdateWriteQueueSize(1); |
574 | 591 | return stream_->DoWrite(w, bufs, count, send_handle); |
| 592 | + } |
575 | 593 | } |
576 | 594 |
|
577 | 595 | // Queue callback to execute it on next tick |
@@ -621,13 +639,15 @@ int TLSWrap::DoWrite(WriteWrap* w, |
621 | 639 |
|
622 | 640 | // Try writing data immediately |
623 | 641 | EncOut(); |
| 642 | + UpdateWriteQueueSize(); |
624 | 643 |
|
625 | 644 | return 0; |
626 | 645 | } |
627 | 646 |
|
628 | 647 |
|
629 | 648 | void TLSWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) { |
630 | | - // Intentionally empty |
| 649 | + TLSWrap* wrap = static_cast<TLSWrap*>(ctx); |
| 650 | + wrap->UpdateWriteQueueSize(); |
631 | 651 | } |
632 | 652 |
|
633 | 653 |
|
|