Read all records to always empty the OpenSSL reading buffer.
This commit is contained in:
parent
3fed1cf36f
commit
430cfd1825
26
lib/net.js
26
lib/net.js
@ -296,11 +296,27 @@ function initStream (self) {
|
||||
try {
|
||||
if (self.secure) {
|
||||
if (!securePool) allocNewSecurePool();
|
||||
secureBytesRead = read(self.fd, securePool, 0, securePool.length);
|
||||
self.secureStream.readInject(securePool, 0, secureBytesRead);
|
||||
bytesRead = self.secureStream.readExtract(pool,
|
||||
pool.used,
|
||||
pool.length - pool.used);
|
||||
var calledByNextTick = (arguments.length == 0); // IOWatcher always passes arguments
|
||||
if (!calledByNextTick) {
|
||||
secureBytesRead = read(self.fd, securePool, 0, securePool.length);
|
||||
self.secureStream.readInject(securePool, 0, secureBytesRead);
|
||||
}
|
||||
var chunkBytes;
|
||||
bytesRead = 0;
|
||||
do {
|
||||
chunkBytes = self.secureStream.readExtract(pool,
|
||||
pool.used + bytesRead,
|
||||
pool.length - pool.used - bytesRead);
|
||||
bytesRead += chunkBytes;
|
||||
} while ((chunkBytes > 0) && (pool.used + bytesRead < pool.length));
|
||||
if (bytesRead == 0 && calledByNextTick)
|
||||
return;
|
||||
if (self.secureStream.readPending()) {
|
||||
process.nextTick(function () {
|
||||
if(self._readWatcher)
|
||||
self._readWatcher.callback();
|
||||
});
|
||||
}
|
||||
if (!self.secureEstablished) {
|
||||
if (self.secureStream.isInitFinished()) {
|
||||
self.secureEstablished = true;
|
||||
|
@ -566,6 +566,8 @@ void SecureStream::Initialize(Handle<Object> target) {
|
||||
SecureStream::WriteInject);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "writeExtract",
|
||||
SecureStream::WriteExtract);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "readPending",
|
||||
SecureStream::ReadPending);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "writeCanExtract",
|
||||
SecureStream::WriteCanExtract);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "getPeerCertificate",
|
||||
@ -717,6 +719,14 @@ Handle<Value> SecureStream::ReadExtract(const Arguments& args) {
|
||||
return scope.Close(Integer::New(bytes_read));
|
||||
}
|
||||
|
||||
Handle<Value> SecureStream::ReadPending(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
|
||||
int bytes_pending = BIO_pending(ss->pbioRead);
|
||||
return scope.Close(Integer::New(bytes_pending));
|
||||
}
|
||||
|
||||
Handle<Value> SecureStream::WriteCanExtract(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
|
@ -51,6 +51,7 @@ class SecureStream : ObjectWrap {
|
||||
static v8::Handle<v8::Value> New(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> ReadInject(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> ReadExtract(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> ReadPending(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> WriteCanExtract(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> WriteExtract(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> WriteInject(const v8::Arguments& args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user