Permalink
Browse files

Move cb_persist functions out of dns module

  • Loading branch information...
1 parent e2569c4 commit 3377a30fb844a9804b895e20d702bbfc865fb70e @ry ry committed Dec 13, 2009
Showing with 23 additions and 30 deletions.
  1. +19 −0 src/node.h
  2. +1 −18 src/node_dns.cc
  3. +3 −12 src/node_file.cc
View
@@ -58,5 +58,24 @@ ssize_t DecodeWrite(char *buf,
v8::Local<v8::Object> BuildStatsObject(struct stat * s);
+static inline v8::Persistent<v8::Function>* cb_persist(
+ const v8::Local<v8::Value> &v) {
+ v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
+ *fn = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(v));
+ return fn;
+}
+
+static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) {
+ v8::Persistent<v8::Function> *cb =
+ reinterpret_cast<v8::Persistent<v8::Function>*>(data);
+ assert((*cb)->IsFunction());
+ return cb;
+}
+
+static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
+ cb->Dispose();
+ delete cb;
+}
+
} // namespace node
#endif // SRC_NODE_H_
View
@@ -1,5 +1,6 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <node_dns.h>
+#include <node.h>
#include <stdlib.h> /* exit() */
#include <sys/types.h>
@@ -21,24 +22,6 @@ static ev_timer timer_watcher;
static Persistent<String> errno_symbol;
-static inline Persistent<Function>* cb_persist(const Local<Value> &v) {
- Persistent<Function> *fn = new Persistent<Function>();
- *fn = Persistent<Function>::New(Local<Function>::Cast(v));
- return fn;
-}
-
-static inline Persistent<Function>* cb_unwrap(void *data) {
- Persistent<Function> *cb =
- reinterpret_cast<Persistent<Function>*>(data);
- assert((*cb)->IsFunction());
- return cb;
-}
-
-static inline void cb_destroy(Persistent<Function> * cb) {
- cb->Dispose();
- delete cb;
-}
-
static inline void set_timeout() {
int maxwait = 20;
int wait = dns_timeouts(NULL, maxwait, ev_now(EV_DEFAULT_UC));
View
@@ -30,9 +30,7 @@ static inline Local<Value> errno_exception(int errorno) {
static int After(eio_req *req) {
HandleScope scope;
- Persistent<Function> *callback =
- reinterpret_cast<Persistent<Function>*>(req->data);
- assert((*callback)->IsFunction());
+ Persistent<Function> *callback = cb_unwrap(req->data);
ev_unref(EV_DEFAULT_UC);
@@ -124,21 +122,14 @@ static int After(eio_req *req) {
}
// Dispose of the persistent handle
- callback->Dispose();
- delete callback;
+ cb_destroy(callback);
return 0;
}
-static Persistent<Function>* persistent_callback(const Local<Value> &v) {
- Persistent<Function> *fn = new Persistent<Function>();
- *fn = Persistent<Function>::New(Local<Function>::Cast(v));
- return fn;
-}
-
#define ASYNC_CALL(func, callback, ...) \
eio_req *req = eio_##func(__VA_ARGS__, EIO_PRI_DEFAULT, After, \
- persistent_callback(callback)); \
+ cb_persist(callback)); \
assert(req); \
ev_ref(EV_DEFAULT_UC); \
return Undefined();

0 comments on commit 3377a30

Please sign in to comment.