Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

compatibility: simulate fast buffer

  • Loading branch information...
commit 09146e95cde0d3a98e3efdc4c5ef410e02f58e93 1 parent 7353411
@bnoordhuis authored
Showing with 15 additions and 0 deletions.
  1. +7 −0 mmap.cc
  2. +8 −0 test.js
View
7 mmap.cc
@@ -12,6 +12,8 @@ namespace {
using namespace v8;
using namespace node;
+Persistent<String> parent_sym;
+
void Unmap(char* data, void* hint) {
munmap(data, (size_t) hint);
}
@@ -41,6 +43,9 @@ Handle<Value> Map(const Arguments& args) {
Buffer* buffer = Buffer::New(
data, size, Unmap, (void *) size);
+ // simulate fast buffer
+ buffer->handle_->Set(parent_sym, buffer->handle_);
+
return buffer->handle_;
}
}
@@ -50,6 +55,8 @@ extern "C" void init(Handle<Object> target) {
const PropertyAttribute attribs = (PropertyAttribute) (ReadOnly | DontDelete);
+ parent_sym = Persistent<String>::New(String::NewSymbol("parent"));
+
target->Set(String::New("PROT_READ"), Integer::New(PROT_READ), attribs);
target->Set(String::New("PROT_WRITE"), Integer::New(PROT_WRITE), attribs);
target->Set(String::New("PROT_EXEC"), Integer::New(PROT_EXEC), attribs);
View
8 test.js
@@ -5,6 +5,7 @@ constants = require('constants');
PAGESIZE = mmap.PAGESIZE;
PROT_READ = mmap.PROT_READ;
+PROT_WRITE = mmap.PROT_WRITE;
MAP_SHARED = mmap.MAP_SHARED;
// open self (this script)
@@ -41,3 +42,10 @@ if (PAGESIZE != 1) {
assert.equal(e.errno, constants.EINVAL);
}
}
+
+// object should be fastbuffer-compatible
+ifd = fs.openSync('/dev/zero', 'r');
+size = 1024;
+ibuf = mmap.map(size, PROT_READ, MAP_SHARED, ifd);
+obuf = new Buffer(size);
+obuf.copy(ibuf);
Please sign in to comment.
Something went wrong with that request. Please try again.