This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.lock-wscript | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
This is about the simplest reduction you can get for using eio_custom. | ||
|
||
Unfortunately, it blows up on Solaris, and I can't seem to figure out why. | ||
|
||
To run: | ||
|
||
node-waf configure build && node test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
#include <v8.h> | ||
#include <node.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
using namespace std; | ||
using namespace node; | ||
using namespace v8; | ||
|
||
static Handle<Value> DoSomethingAsync (const Arguments&); | ||
static int DoSomething (eio_req *); | ||
static int DoSomething_After (eio_req *); | ||
extern "C" void init (Handle<Object>); | ||
|
||
struct simple_request { | ||
int x; | ||
int y; | ||
char name[1]; | ||
Persistent<Function> cb; | ||
}; | ||
|
||
static Handle<Value> DoSomethingAsync (const Arguments& args) { | ||
HandleScope scope; | ||
const char *usage = "usage: doSomething(x, y, name, cb)"; | ||
if (args.Length() != 4) { | ||
return ThrowException(Exception::Error(String::New(usage))); | ||
} | ||
int x = args[0]->Int32Value(); | ||
int y = args[1]->Int32Value(); | ||
String::Utf8Value name(args[2]); | ||
fprintf(stderr, " >>>DoSomethingAsync %d %d %s\n", x, y, *name); | ||
Local<Function> cb = Local<Function>::Cast(args[3]); | ||
|
||
simple_request *sr = (simple_request *) | ||
malloc(sizeof(struct simple_request) + name.length() + 1); | ||
|
||
sr->cb = Persistent<Function>::New(cb); | ||
strncpy(sr->name, *name, name.length() + 1); | ||
sr->x = x; | ||
sr->y = y; | ||
|
||
fprintf(stderr, " >>>about to eio_custom\n"); | ||
eio_custom(DoSomething, EIO_PRI_DEFAULT, DoSomething_After, sr); | ||
ev_ref(EV_DEFAULT_UC); | ||
fprintf(stderr, " >>>returning\n"); | ||
return Undefined(); | ||
} | ||
|
||
// this function happens on the thread pool | ||
static int DoSomething (eio_req *req) { | ||
fprintf(stderr, " >>>DoSomething %d\n", req); | ||
struct simple_request * sr = (struct simple_request *)req->data; | ||
fprintf(stderr, " >>>about to sleep\n"); | ||
sleep(2); | ||
fprintf(stderr, " >>>read req, about to set result\n"); | ||
// Why does this crash in Solaris? | ||
req->result = sr->x + sr->y; | ||
fprintf(stderr, " >>>returning\n"); | ||
return 0; | ||
} | ||
|
||
static int DoSomething_After (eio_req *req) { | ||
fprintf(stderr, " >>>DoSomething_After %d\n", 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[2] = String::New(sr->name); | ||
TryCatch try_catch; | ||
sr->cb->Call(Context::GetCurrent()->Global(), 3, argv); | ||
if (try_catch.HasCaught()) { | ||
FatalException(try_catch); | ||
} | ||
sr->cb.Dispose(); | ||
free(sr); | ||
return 0; | ||
} | ||
|
||
extern "C" void init (Handle<Object> target) { | ||
HandleScope scope; | ||
NODE_SET_METHOD(target, "doSomething", DoSomethingAsync); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var nas = require("./build/default/nas") | ||
, sys = require("sys") | ||
|
||
if (typeof console === "undefined") { | ||
global.console = { log : function () { | ||
sys.debug(sys.inspect([].slice.call(arguments))) | ||
}} | ||
} | ||
|
||
|
||
console.log(Date.now(), "before hello") | ||
nas.doSomething(1, 2, "hello", function (er, res, n) { | ||
console.log(Date.now(), er, res, n) | ||
}) | ||
console.log(Date.now(), "before goodbye") | ||
nas.doSomething(3, 4, "goodbye", function (er, res, n) { | ||
console.log(Date.now(), er, res, n) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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") | ||
obj.target = "nas" | ||
obj.source = "nas.cc" |