Permalink
Browse files

Merge pull request #16 from pccowboy/node_v0.10.0_libuv_changes

Node v0.10.0 libuv changes
  • Loading branch information...
2 parents 806d7b4 + 992282e commit 39d70412e1efcc83ad2cae5d4e12d1b907733f3f @mariano committed Mar 15, 2013
Showing with 37 additions and 8 deletions.
  1. +17 −5 binding.cc
  2. +4 −1 binding.h
  3. +13 −1 query.cc
  4. +3 −1 query.h
View
@@ -10,6 +10,8 @@ node_db::Binding::~Binding() {
}
}
+uv_async_t node_db::Binding::g_async;
+
void node_db::Binding::Init(v8::Handle<v8::Object> target, v8::Persistent<v8::FunctionTemplate> constructorTemplate) {
NODE_ADD_CONSTANT(constructorTemplate, COLUMN_TYPE_STRING, node_db::Result::Column::STRING);
NODE_ADD_CONSTANT(constructorTemplate, COLUMN_TYPE_BOOL, node_db::Result::Column::BOOL);
@@ -88,7 +90,12 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
req->data = request;
uv_queue_work(uv_default_loop(), req, uvConnect, uvConnectFinished);
- uv_ref(uv_default_loop());
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_ref((uv_handle_t *)&g_async);
+#else
+ uv_ref(uv_default_loop());
+#endif
+
} else {
connect(request);
connectFinished(request);
@@ -100,7 +107,7 @@ v8::Handle<v8::Value> node_db::Binding::Connect(const v8::Arguments& args) {
void node_db::Binding::connect(connect_request_t* request) {
try {
request->binding->connection->open();
- } catch(const node_db::Exception& exception) {
+ } catch(node_db::Exception const& exception) {
request->error = exception.what();
}
}
@@ -146,13 +153,18 @@ void node_db::Binding::uvConnect(uv_work_t* uvRequest) {
connect(request);
}
-void node_db::Binding::uvConnectFinished(uv_work_t* uvRequest) {
+void node_db::Binding::uvConnectFinished(uv_work_t* uvRequest, int status) {
v8::HandleScope scope;
connect_request_t* request = static_cast<connect_request_t*>(uvRequest->data);
assert(request);
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_unref((uv_handle_t *)&g_async);
+#else
uv_unref(uv_default_loop());
+#endif
+
request->binding->Unref();
connectFinished(request);
@@ -192,7 +204,7 @@ v8::Handle<v8::Value> node_db::Binding::Escape(const v8::Arguments& args) {
v8::String::Utf8Value string(args[0]->ToString());
std::string unescaped(*string);
escaped = binding->connection->escape(unescaped);
- } catch(const node_db::Exception& exception) {
+ } catch(node_db::Exception const& exception) {
THROW_EXCEPTION(exception.what())
}
@@ -213,7 +225,7 @@ v8::Handle<v8::Value> node_db::Binding::Name(const v8::Arguments& args) {
v8::String::Utf8Value string(args[0]->ToString());
std::string unescaped(*string);
escaped << binding->connection->escapeName(unescaped);
- } catch(const node_db::Exception& exception) {
+ } catch(node_db::Exception const& exception) {
THROW_EXCEPTION(exception.what())
}
View
@@ -2,7 +2,9 @@
#ifndef BINDING_H_
#define BINDING_H_
+#include <v8.h>
#include <node.h>
+#include <node_buffer.h>
#include <node_version.h>
#include <string>
#include "./node_defs.h"
@@ -33,8 +35,9 @@ class Binding : public EventEmitter {
static v8::Handle<v8::Value> Escape(const v8::Arguments& args);
static v8::Handle<v8::Value> Name(const v8::Arguments& args);
static v8::Handle<v8::Value> Query(const v8::Arguments& args);
+ static uv_async_t g_async;
static void uvConnect(uv_work_t* uvRequest);
- static void uvConnectFinished(uv_work_t* uvRequest);
+ static void uvConnectFinished(uv_work_t* uvRequest, int status);
static void connect(connect_request_t* request);
static void connectFinished(connect_request_t* request);
virtual v8::Handle<v8::Value> set(const v8::Local<v8::Object> options) = 0;
View
@@ -5,6 +5,8 @@
bool node_db::Query::gmtDeltaLoaded = false;
int node_db::Query::gmtDelta;
+uv_async_t node_db::Query::g_async;
+
void node_db::Query::Init(v8::Handle<v8::Object> target, v8::Persistent<v8::FunctionTemplate> constructorTemplate) {
NODE_ADD_PROTOTYPE_METHOD(constructorTemplate, "select", Select);
NODE_ADD_PROTOTYPE_METHOD(constructorTemplate, "from", From);
@@ -649,7 +651,12 @@ v8::Handle<v8::Value> node_db::Query::Execute(const v8::Arguments& args) {
req->data = request;
uv_queue_work(uv_default_loop(), req, uvExecute, uvExecuteFinished);
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_ref((uv_handle_t *)&g_async);
+#else
uv_ref(uv_default_loop());
+#endif
+
} else {
request->query->executeAsync(request);
}
@@ -728,7 +735,7 @@ void node_db::Query::uvExecute(uv_work_t* uvRequest) {
}
}
-void node_db::Query::uvExecuteFinished(uv_work_t* uvRequest) {
+void node_db::Query::uvExecuteFinished(uv_work_t* uvRequest, int status) {
v8::HandleScope scope;
execute_request_t *request = static_cast<execute_request_t *>(uvRequest->data);
@@ -813,7 +820,12 @@ void node_db::Query::uvExecuteFinished(uv_work_t* uvRequest) {
}
}
+#if NODE_VERSION_AT_LEAST(0, 7, 9)
+ uv_unref((uv_handle_t *)&g_async);
+#else
uv_unref(uv_default_loop());
+#endif
+
request->query->Unref();
Query::freeRequest(request);
View
@@ -2,6 +2,7 @@
#ifndef QUERY_H_
#define QUERY_H_
+#include <v8.h>
#include <stdlib.h>
#include <node.h>
#include <node_buffer.h>
@@ -66,8 +67,9 @@ class Query : public EventEmitter {
static v8::Handle<v8::Value> Delete(const v8::Arguments& args);
static v8::Handle<v8::Value> Sql(const v8::Arguments& args);
static v8::Handle<v8::Value> Execute(const v8::Arguments& args);
+ static uv_async_t g_async;
static void uvExecute(uv_work_t* uvRequest);
- static void uvExecuteFinished(uv_work_t* uvRequest);
+ static void uvExecuteFinished(uv_work_t* uvRequest, int status);
void executeAsync(execute_request_t* request);
static void freeRequest(execute_request_t* request, bool freeAll = true);
std::string fieldName(v8::Local<v8::Value> value) const throw(Exception&);

0 comments on commit 39d7041

Please sign in to comment.