Created
January 25, 2012 15:49
-
-
Save shigeki/1676875 to your computer and use it in GitHub Desktop.
node module for uv_unref
This file contains hidden or 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
var unref = require('./build/Release/unref.node').unref; | |
var http = require('http'); | |
http.createServer(function(req,res){ | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Loop Counter='+unref()+'\n'); | |
}).listen(8080); |
This file contains hidden or 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
#define BUILDING_NODE_EXTENSION | |
#include <node.h> | |
#include <uv.h> | |
using namespace v8; | |
Handle<Value> Unref(const Arguments& args) { | |
HandleScope scope; | |
uv_unref(uv_default_loop()); | |
Local<Number> num = Number::New(uv_loop_refcount(uv_default_loop())); | |
return scope.Close(num); | |
} | |
void Init(Handle<Object> target) { | |
target->Set(String::NewSymbol("unref"), | |
FunctionTemplate::New(Unref)->GetFunction()); | |
} | |
NODE_MODULE(unref, Init) |
This file contains hidden or 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
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 = 'unref' | |
obj.source = ['unref.cc'] |
This file contains hidden or 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
unix:~/tmp/addon> node-waf configure build | |
Checking for program g++ or c++ : /usr/bin/g++ | |
Checking for program cpp : /usr/bin/cpp | |
Checking for program ar : /usr/bin/ar | |
Checking for program ranlib : /usr/bin/ranlib | |
Checking for g++ : ok | |
Checking for node path : not found | |
Checking for node prefix : ok /usr/local | |
'configure' finished successfully (0.025s) | |
Waf: Entering directory `/home/ohtsu/tmp/addon/build' | |
Waf: Leaving directory `/home/ohtsu/tmp/addon/build' | |
'build' finished successfully (0.005s) | |
unix:~/tmp/addon> node http_server.js | |
ブラウザーを使って port 8080 へアクセス。 | |
リロードを続けて画面に出力されるイベントループのカウンター値が0になると自動的に node が終了します。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment