Browse Source

Read all records to always empty the OpenSSL reading buffer.

v0.7.4-release
Paulo Matias 15 years ago
committed by Ryan Dahl
parent
commit
430cfd1825
  1. 22
      lib/net.js
  2. 10
      src/node_crypto.cc
  3. 1
      src/node_crypto.h

22
lib/net.js

@ -296,11 +296,27 @@ function initStream (self) {
try {
if (self.secure) {
if (!securePool) allocNewSecurePool();
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);
bytesRead = self.secureStream.readExtract(pool,
pool.used,
pool.length - pool.used);
}
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;

10
src/node_crypto.cc

@ -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;

1
src/node_crypto.h

@ -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…
Cancel
Save