Browse Source

Move cb_persist functions out of dns module

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
3377a30fb8
  1. 19
      src/node.h
  2. 19
      src/node_dns.cc
  3. 15
      src/node_file.cc

19
src/node.h

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

19
src/node_dns.cc

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

15
src/node_file.cc

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

Loading…
Cancel
Save