| 595 | // Used by both client and server TLSSockets to start data flowing from _handle, |
| 596 | // read(0) causes a StreamBase::ReadStart, via Socket._read. |
| 597 | function initRead(tlsSocket, socket) { |
| 598 | debug('%s initRead', |
| 599 | tlsSocket._tlsOptions.isServer ? 'server' : 'client', |
| 600 | 'handle?', !!tlsSocket._handle, |
| 601 | 'buffered?', !!socket && socket.readableLength, |
| 602 | ); |
| 603 | // If we were destroyed already don't bother reading |
| 604 | if (!tlsSocket._handle) |
| 605 | return; |
| 606 | |
| 607 | // Socket already has some buffered data - emulate receiving it |
| 608 | if (socket?.readableLength) { |
| 609 | let buf; |
| 610 | while ((buf = socket.read()) !== null) |
| 611 | tlsSocket._handle.receive(buf); |
| 612 | } |
| 613 | |
| 614 | tlsSocket.read(0); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Provides a wrap of socket stream to do encrypted communication. |