Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update for nove v0.6.x and later compatibility #3

Open
wants to merge 1 commit into from

2 participants

@Sannis

No description provided.

@Filirom1

Hi,

Can, I use this project (with this pull-request) as a reference to create a C non-blocking addon, or should I use something else ?

Here are the other resources I found:

Cheers
Romain

@Sannis

These links are also outdated.

The best way is read migration guides in node.js wiki:

@Filirom1

Ok, I will try with this project and your links.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. @Sannis
This page is out of date. Refresh to see the latest.
View
6 README
@@ -1,10 +1,10 @@
-This is about the simplest reduction you can get for using eio_custom.
+This is about the simplest reduction you can get for using uv_queue_work.
To run:
- node-waf configure build && node test.js
+ npm install && node test.js
Or, you can link or install it with npm. Note that it has hardly anything
in the package.json, either.
- npm link && npm test async-simple
+ npm install && npm test async-simple
View
10 binding.gyp
@@ -0,0 +1,10 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'nas',
+ 'sources': [
+ 'nas.cc',
+ ]
+ }
+ ]
+}
View
23 nas.cc
@@ -10,13 +10,14 @@ using namespace node;
using namespace v8;
static Handle<Value> DoSomethingAsync (const Arguments&);
-static int DoSomething (eio_req *);
-static int DoSomething_After (eio_req *);
+static void DoSomething (uv_work_t *);
+static void DoSomething_After (uv_work_t *);
extern "C" void init (Handle<Object>);
struct simple_request {
int x;
int y;
+ int result;
Persistent<Function> cb;
// maybe it matters to put the char[] last? not sure.
char name[1];
@@ -41,27 +42,27 @@ static Handle<Value> DoSomethingAsync (const Arguments& args) {
sr->x = x;
sr->y = y;
- eio_custom(DoSomething, EIO_PRI_DEFAULT, DoSomething_After, sr);
- ev_ref(EV_DEFAULT_UC);
+ uv_work_t *_req = new uv_work_t;
+ _req->data = sr;
+ uv_queue_work(uv_default_loop(), _req, DoSomething, DoSomething_After);
+
return Undefined();
}
// this function happens on the thread pool
// doing v8 things in here will make bad happen.
-static int DoSomething (eio_req *req) {
+static void DoSomething (uv_work_t *req) {
struct simple_request * sr = (struct simple_request *)req->data;
sleep(2); // just to make it less pointless to be async.
- req->result = sr->x + sr->y;
- return 0;
+ sr->result = sr->x + sr->y;
}
-static int DoSomething_After (eio_req *req) {
+static void DoSomething_After (uv_work_t *req) {
HandleScope scope;
- ev_unref(EV_DEFAULT_UC);
struct simple_request * sr = (struct simple_request *)req->data;
Local<Value> argv[3];
argv[0] = Local<Value>::New(Null());
- argv[1] = Integer::New(req->result);
+ argv[1] = Integer::New(sr->result);
argv[2] = String::New(sr->name);
TryCatch try_catch;
sr->cb->Call(Context::GetCurrent()->Global(), 3, argv);
@@ -70,7 +71,7 @@ static int DoSomething_After (eio_req *req) {
}
sr->cb.Dispose();
free(sr);
- return 0;
+ delete req;
}
extern "C" void init (Handle<Object> target) {
View
5 package.json
@@ -1,7 +1,8 @@
{ "name" : "async-simple"
-, "description" : "An eio_custom example program"
+, "description" : "An uv_queue_work example program"
, "version" : "1.0.0"
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"
-, "main" : "build/default/nas.node"
+, "main" : "build/Release/nas.node"
, "scripts" : { "test" : "node test.js" }
+, "engines" : { "node" : ">= 0.5.6" }
}
View
2  test.js
@@ -1,4 +1,4 @@
-var nas = require("./build/default/nas")
+var nas = require("./build/Release/nas")
, start = Date.now()
console.log("js "+(Date.now() - start), "before hello")
View
17 wscript
@@ -1,17 +0,0 @@
-srcdir = "."
-blddir = "build"
-VERSION = "0.0.1"
-
-def set_options(opt):
- opt.tool_options("compiler_cxx")
-
-def configure(conf):
- conf.check_tool("compiler_cxx")
- conf.check_tool("node_addon")
-
-def build(bld):
- obj = bld.new_task_gen("cxx", "shlib", "node_addon")
- # without this, eio_custom doesn't keep a ref to the req->data
- obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE"]
- obj.target = "nas"
- obj.source = "nas.cc"
Something went wrong with that request. Please try again.