Move cb_persist functions out of dns module
authorRyan Dahl <ry@tinyclouds.org>
Sun, 13 Dec 2009 07:58:12 +0000 (08:58 +0100)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 29 Dec 2009 20:12:29 +0000 (21:12 +0100)
src/node.h
src/node_dns.cc
src/node_file.cc

index fd872a0..44cf0db 100644 (file)
@@ -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_
index 1dadab2..f173e7e 100644 (file)
@@ -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));
index 1289064..c378cab 100644 (file)
@@ -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();