Permalink
Browse files

Added node v0.11 support.

Change-Id: I076aad52a12349417c33808dba25798211839fd9
Reviewed-on: http://review.couchbase.org/30486
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Tested-by: Brett Lawson <brett19@gmail.com>
  • Loading branch information...
1 parent 00fce25 commit 0beb117845e9b6a3ad48287062df94c7c9728a36 @brett19 brett19 committed Nov 23, 2013
View
@@ -102,6 +102,7 @@
'src/valueformat.cc'
],
'include_dirs': [
+ '<!(node -e "require(\'nan\')")',
'./',
'./src/io'
]
@@ -214,7 +214,8 @@
}, {
'files': [
'plugins/io/libuv/plugin-libuv.c',
- 'plugins/io/libuv/plugin-internal.h'
+ 'plugins/io/libuv/plugin-internal.h',
+ 'plugins/io/libuv/libuv_compat.h'
],
'destination': 'include/libcouchbase/plugins/io/libuv/'
}],
@@ -0,0 +1,156 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * Copyright 2013 Couchbase, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LIBUV_COMPAT_H
+#define LIBUV_COMPAT_H
+
+#ifdef UV_VERSION_MAJOR
+#define UV_VERSION ((UV_VERSION_MAJOR << 16) | \
+ (UV_VERSION_MINOR << 8) | \
+ (UV_VERSION_PATCH))
+#else
+#define UV_VERSION 0x000b00
+#endif
+
+#if defined(_WIN32) && defined(LIBCOUCHBASE_INTERNAL)
+#include "win32/win_errno_sock.h"
+#endif
+
+#ifndef UNKNOWN
+#define UNKNOWN -1
+#endif
+
+#ifndef EAIFAMNOSUPPORT
+#define EAIFAMNOSUPPORT EAI_FAMILY
+#endif
+
+#ifndef EAISERVICE
+#define EAISERVICE EAI_SERVICE
+#endif
+
+#ifndef EAI_SYSTEM
+#define EAI_SYSTEM -11
+#endif
+#ifndef EADDRINFO
+#define EADDRINFO EAI_SYSTEM
+#endif
+
+#ifndef EAISOCKTYPE
+#define EAISOCKTYPE EAI_SOCKTYPE
+#endif
+
+#ifndef ECHARSET
+#define ECHARSET 0
+#endif
+
+#ifndef EOF
+#define EOF -1
+#endif
+
+#ifndef ENONET
+#define ENONET ENETDOWN
+#endif
+
+#ifndef ESHUTDOWN
+#define ESHUTDOWN WSAESHUTDOWN
+#endif
+
+#ifndef EAI_CANCELED
+#define EAI_CANCELED -101
+#endif
+
+#ifndef EAI_ADDRFAMILY
+#define EAI_ADDRFAMILY -9
+#endif
+
+#define OK 0
+
+#if UV_VERSION < 0x000900
+ #define UVC_RUN_ONCE(l) uv_run_once(l)
+ #define UVC_RUN_DEFAULT(l) uv_run(l)
+#else
+ #define UVC_RUN_ONCE(l) uv_run(l, UV_RUN_ONCE)
+ #define UVC_RUN_DEFAULT(l) uv_run(l, UV_RUN_DEFAULT)
+#endif
+
+#if UV_VERSION < 0x000b00
+
+ #define UVC_TCP_CONNECT(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, *(struct sockaddr_in *)addr, cb);
+
+ #define UVC_TCP_CONNECT6(req, handle, addr, cb) \
+ uv_tcp_connect6(req, handle, *(struct sockaddr_in6 *)addr, cb);
+
+ #define UVC_ALLOC_CB(func) \
+ uv_buf_t func(uv_handle_t *handle, size_t suggested_size)
+
+ #define UVC_ALLOC_CB_VARS() \
+ uv_buf_t _buf; uv_buf_t *buf = &_buf;
+
+ #define UVC_ALLOC_CB_RETURN() \
+ return _buf;
+
+ #define UVC_READ_CB(func) \
+ void func(uv_stream_t *stream, ssize_t nread, const uv_buf_t _buf)
+
+ #define UVC_READ_CB_VARS() \
+ const uv_buf_t *buf = &_buf;
+
+ static int uvc_last_errno(uv_loop_t *loop, int error) {
+ int uverr = 0;
+
+ if (!error) {
+ return 0;
+ }
+
+ uverr = uv_last_error(loop).code;
+#define X(errnum,errname,errdesc) \
+ if (uverr == UV_##errname) { \
+ return errname; \
+ }
+ UV_ERRNO_MAP(X);
+#undef X
+
+ return 0;
+ }
+
+#else
+
+ #define UVC_TCP_CONNECT(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, addr, cb);
+
+ #define UVC_TCP_CONNECT6(req, handle, addr, cb) \
+ uv_tcp_connect(req, handle, addr, cb);
+
+ #define UVC_ALLOC_CB(func) \
+ void func(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
+
+ #define UVC_ALLOC_CB_VARS()
+
+ #define UVC_ALLOC_CB_RETURN()
+
+ #define UVC_READ_CB(func) \
+ void func(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
+
+ #define UVC_READ_CB_VARS()
+
+ static int uvc_last_errno(uv_loop_t *loop, int error) {
+ return error;
+ }
+
+#endif
+#endif
@@ -28,6 +28,8 @@
#include <string.h>
#include <sys/types.h>
+#include "libuv_compat.h"
+
#ifdef LCBUV_EMBEDDED_SOURCE
#include <libcouchbase/libuv_io_opts.h>
#else
@@ -158,14 +160,6 @@ typedef struct {
#define incref_iops(io) (io)->iops_refcount++
-#if (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 10)
-#define LCBUV_LOOP_ONCE(l) uv_run_once(l)
-#define LCBUV_LOOP_DEFL(l) uv_run(l)
-#else
-#define LCBUV_LOOP_ONCE(l) uv_run(l, UV_RUN_ONCE)
-#define LCBUV_LOOP_DEFL(l) uv_run(l, UV_RUN_DEFAULT)
-#endif
-
#ifdef _WIN32
typedef ULONG lcb_uvbuf_len_t;
#else
@@ -47,7 +47,7 @@ static void iops_lcb_dtor(lcb_io_opt_t iobase)
}
while (io->iops_refcount > 1) {
- LCBUV_LOOP_ONCE(io->loop);
+ UVC_RUN_ONCE(io->loop);
}
if (io->external_loop == 0) {
@@ -63,7 +63,7 @@ static void iops_lcb_dtor(lcb_io_opt_t iobase)
******************************************************************************
******************************************************************************/
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 10
+#if UV_VERSION < 0x000900
static void do_run_loop(my_iops_t *io)
{
while (uv_run_once(io->loop) && io->do_stop == 0) {
@@ -358,15 +358,15 @@ static int start_connect(lcb_io_opt_t iobase,
}
if (namelen == sizeof(struct sockaddr_in)) {
- ret = uv_tcp_connect(&uvr->uvreq.conn,
+ ret = UVC_TCP_CONNECT(&uvr->uvreq.conn,
&sock->tcp.t,
- *(struct sockaddr_in *)name,
+ name,
connect_callback);
} else if (namelen == sizeof(struct sockaddr_in6)) {
- ret = uv_tcp_connect6(&uvr->uvreq.conn,
+ ret = UVC_TCP_CONNECT6(&uvr->uvreq.conn,
&sock->tcp.t,
- *(struct sockaddr_in6 *)name,
+ name,
connect_callback);
} else {
@@ -478,26 +478,29 @@ static int start_write(lcb_io_opt_t iobase,
** Read Functions **
******************************************************************************
******************************************************************************/
-static uv_buf_t alloc_cb(uv_handle_t *handle, size_t suggested_size)
+static UVC_ALLOC_CB(alloc_cb)
{
- uv_buf_t ret;
+ UVC_ALLOC_CB_VARS()
+
my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, handle, tcp);
struct lcb_buf_info *bi = &sock->base.read_buffer;
lcb_assert(sock->cur_iov == 0);
- ret.base = bi->iov[0].iov_base;
- ret.len = (lcb_uvbuf_len_t)bi->iov[0].iov_len;
+ buf->base = bi->iov[0].iov_base;
+ buf->len = (lcb_uvbuf_len_t)bi->iov[0].iov_len;
sock->cur_iov++;
sock->read_done = 1;
(void)suggested_size;
- return ret;
+ UVC_ALLOC_CB_RETURN();
}
-static void read_cb(uv_stream_t *stream, ssize_t nread, uv_buf_t buf)
+static UVC_READ_CB(read_cb)
{
+ UVC_READ_CB_VARS()
+
my_tcp_t *mt = (my_tcp_t *)stream;
my_sockdata_t *sock = PTR_FROM_FIELD(my_sockdata_t, mt, tcp);
@@ -709,75 +712,6 @@ static void wire_timer_ops(lcb_io_opt_t iop)
iop->v.v1.destroy_timer = destroy_timer;
}
-#if defined(_WIN32) && defined(LIBCOUCHBASE_INTERNAL)
-#include "win32/win_errno_sock.h"
-#endif
-
-static int errno_map(int uverr)
-{
-
-#ifndef UNKNOWN
-#define UNKNOWN -1
-#endif
-
-#ifndef EAIFAMNOSUPPORT
-#define EAIFAMNOSUPPORT EAI_FAMILY
-#endif
-
-#ifndef EAISERVICE
-#define EAISERVICE EAI_SERVICE
-#endif
-
-#ifndef EAI_SYSTEM
-#define EAI_SYSTEM -11
-#endif
-#ifndef EADDRINFO
-#define EADDRINFO EAI_SYSTEM
-#endif
-
-#ifndef EAISOCKTYPE
-#define EAISOCKTYPE EAI_SOCKTYPE
-#endif
-
-#ifndef ECHARSET
-#define ECHARSET 0
-#endif
-
-#ifndef EOF
-#define EOF -1
-#endif
-
-#ifndef ENONET
-#define ENONET ENETDOWN
-#endif
-
-#ifndef ESHUTDOWN
-#define ESHUTDOWN WSAESHUTDOWN
-#endif
-
-#ifndef EAI_CANCELED
-#define EAI_CANCELED -101
-#endif
-
-#ifndef EAI_ADDRFAMILY
-#define EAI_ADDRFAMILY -9
-#endif
-
-#define OK 0
-
- int ret = 0;
-#define X(errnum,errname,errdesc) \
- if (uverr == UV_##errname) { \
- return errname; \
- }
- UV_ERRNO_MAP(X);
-
- return ret;
-
-#undef X
-}
-
-
static my_uvreq_t *alloc_uvreq(my_sockdata_t *sock, generic_callback_t callback)
{
my_uvreq_t *ret = calloc(1, sizeof(*ret));
@@ -793,11 +727,7 @@ static my_uvreq_t *alloc_uvreq(my_sockdata_t *sock, generic_callback_t callback)
static void set_last_error(my_iops_t *io, int error)
{
- if (!error) {
- io->base.v.v1.error = 0;
- return;
- }
- io->base.v.v1.error = errno_map(uv_last_error(io->loop).code);
+ io->base.v.v1.error = uvc_last_errno(io->loop, error);
}
static void generic_close_cb(uv_handle_t *handle)
View
@@ -9,7 +9,8 @@
"license" : "Apache2",
"name": "couchbase",
"dependencies": {
- "bindings": "~1.0.0"
+ "bindings": "~1.0.0",
+ "nan": "git+https://github.com/brett19/nan.git#b0e8b0fe1bfd4518f2417ce81e06be26dc22c3d1"
},
"devDependencies": {
"async": "0.2.9",
Oops, something went wrong.

2 comments on commit 0beb117

just wanted to say super awesome and thank you for this, I can now start pushing our company to start using couchbase

Owner

brett19 replied Dec 10, 2013

Glad to hear it!

Please sign in to comment.