joyent/node — pull request #5601 by indutny (2013-05-30 09:50:43+00:00)
Title: tls: proper .destroySoon

1. Emit `sslOutEnd` only when `_internallyPendingBytes() === 0`.
2. Read before checking `._halfRead`, otherwise we'll see only previous
value, and will invoke `._write` callback improperly.
3. Wait for both `end` and `finish` events in `.destroySoon`.
4. Unpipe encrypted stream from socket to prevent write after destroy.

/cc @isaacs @bnoordhuis

Fixes test-tls-client-destroy-soon.js in master.