Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move oi_buf creation to node.cc

  • Loading branch information...
commit 0ff62b2ea070aa4d1d3b11f6d7d71bc45643fecc 1 parent f56309d
@ry ry authored
Showing with 30 additions and 51 deletions.
  1. +2 −25 src/net.cc
  2. +24 −0 src/node.cc
  3. +2 −0  src/node.h
  4. +2 −26 src/process.cc
View
27 src/net.cc
@@ -374,29 +374,6 @@ Connection::ForceClose (const Arguments& args)
return Undefined();
}
-static void
-free_buf (oi_buf *b)
-{
- V8::AdjustAmountOfExternalAllocatedMemory(-b->len);
- free(b);
-}
-
-static oi_buf *
-new_buf (size_t size)
-{
- size_t total = sizeof(oi_buf) + size;
- void *p = malloc(total);
- if (p == NULL) return NULL;
-
- oi_buf *b = static_cast<oi_buf*>(p);
- b->base = static_cast<char*>(p) + sizeof(oi_buf);
-
- b->len = size;
- b->release = free_buf;
- V8::AdjustAmountOfExternalAllocatedMemory(total);
-
- return b;
-}
Handle<Value>
Connection::Send (const Arguments& args)
@@ -422,7 +399,7 @@ Connection::Send (const Arguments& args)
enum encoding enc = ParseEncoding(args[1]);
Local<String> s = args[0]->ToString();
size_t len = s->Utf8Length();
- oi_buf *buf = new_buf(len);
+ oi_buf *buf = node::buf_new(len);
switch (enc) {
case RAW:
case ASCII:
@@ -441,7 +418,7 @@ Connection::Send (const Arguments& args)
} else if (args[0]->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(args[0]);
size_t len = array->Length();
- oi_buf *buf = new_buf(len);
+ oi_buf *buf = node::buf_new(len);
for (size_t i = 0; i < len; i++) {
Local<Value> int_value = array->Get(Integer::New(i));
buf->base[i] = int_value->IntegerValue();
View
24 src/node.cc
@@ -97,6 +97,30 @@ ObjectWrap::InformV8ofAllocation (ObjectWrap *obj)
v8::V8::AdjustAmountOfExternalAllocatedMemory(obj->size());
}
+static void
+buf_free (oi_buf *b)
+{
+ V8::AdjustAmountOfExternalAllocatedMemory(-b->len);
+ free(b);
+}
+
+oi_buf *
+node::buf_new (size_t size)
+{
+ size_t total = sizeof(oi_buf) + size;
+ void *p = malloc(total);
+ if (p == NULL) return NULL;
+
+ oi_buf *b = static_cast<oi_buf*>(p);
+ b->base = static_cast<char*>(p) + sizeof(oi_buf);
+
+ b->len = size;
+ b->release = buf_free;
+ V8::AdjustAmountOfExternalAllocatedMemory(total);
+
+ return b;
+}
+
// Extracts a C string from a V8 Utf8Value.
const char*
ToCString(const v8::String::Utf8Value& value)
View
2  src/node.h
@@ -4,6 +4,7 @@
#include <ev.h>
#include <eio.h>
#include <v8.h>
+#include <oi_socket.h>
namespace node {
@@ -29,6 +30,7 @@ do { \
enum encoding {ASCII, UTF8, RAW};
enum encoding ParseEncoding (v8::Handle<v8::Value> encoding_v);
void FatalException (v8::TryCatch &try_catch);
+oi_buf * buf_new (size_t size);
class ObjectWrap {
public:
View
28 src/process.cc
@@ -71,30 +71,6 @@ Process::PIDGetter (Local<String> _, const AccessorInfo& info)
return scope.Close(pid);
}
-static void
-free_buf (oi_buf *b)
-{
- V8::AdjustAmountOfExternalAllocatedMemory(-b->len);
- free(b);
-}
-
-static oi_buf *
-new_buf (size_t size)
-{
- size_t total = sizeof(oi_buf) + size;
- void *p = malloc(total);
- if (p == NULL) return NULL;
-
- oi_buf *b = static_cast<oi_buf*>(p);
- b->base = static_cast<char*>(p) + sizeof(oi_buf);
-
- b->len = size;
- b->release = free_buf;
- V8::AdjustAmountOfExternalAllocatedMemory(total);
-
- return b;
-}
-
Handle<Value>
Process::Write (const Arguments& args)
{
@@ -117,7 +93,7 @@ Process::Write (const Arguments& args)
enum encoding enc = ParseEncoding(args[1]);
Local<String> s = args[0]->ToString();
len = s->Utf8Length();
- buf = new_buf(len);
+ buf = node::buf_new(len);
switch (enc) {
case RAW:
case ASCII:
@@ -135,7 +111,7 @@ Process::Write (const Arguments& args)
} else if (args[0]->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(args[0]);
len = array->Length();
- buf = new_buf(len);
+ buf = node::buf_new(len);
for (size_t i = 0; i < len; i++) {
Local<Value> int_value = array->Get(Integer::New(i));
buf->base[i] = int_value->IntegerValue();
Please sign in to comment.
Something went wrong with that request. Please try again.