Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v0.5 backport) src,build: improve the native module subsystem #110

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
{
'variables': {
'jstp_base_cflags': ['-Wall', '-Wextra', '-Wno-unused-parameter'],
'jstp_debug_cflags': ['-g', '-O0'],
'jstp_release_cflags': ['-O3']
},
'targets': [
{
'target_name': 'jsrs',
'cflags': ['-O3'],
'sources': ['src/jsrs-impl.cc']
'target_name': 'jstp',
'sources': [
'src/node_bindings.cc',
'src/jsrs_serializer.cc',
'src/jsrs_parser.cc',
'src/packet_parser.cc',
'src/unicode_utils.cc'
],
'configurations': {
'Debug': {
'cflags': ['<@(jstp_debug_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_debug_cflags)']
}
},
'Release': {
'cflags': ['<@(jstp_release_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_release_cflags)']
}
}
},
'cflags': ['<@(jstp_base_cflags)'],
'xcode_settings': {
'OTHER_CFLAGS': ['<@(jstp_base_cflags)']
}
}
]
}
20 changes: 8 additions & 12 deletions lib/record-serialization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var common = require('./common');
var serializerFactory = require('./serializer-factory');

var jsrs = {};
Expand All @@ -11,31 +12,26 @@ module.exports = jsrs;
// one of our priorities to optimize it.
var USE_NATIVE_SERIALIZER = false;

var jsrsNative;
var jstpNative;

try {
jsrsNative = require('../build/Release/jsrs');
jstpNative = require('../build/Release/jstp');
} catch (e) {
try {
jsrsNative = require('../build/Debug/jsrs');
jstpNative = require('../build/Debug/jstp');
} catch (e) {
console.warn(
'JSTP Record Serialization native module is not built. ' +
'JSTP native addon is not built. ' +
'Run `npm install` in order to build it, otherwise you will get ' +
'poor server performance under load.'
);
module.exports = require('./record-serialization-fallback');
}
}

if (jsrsNative) {
jsrs.parse = jsrsNative.parse;

if (USE_NATIVE_SERIALIZER) {
jsrs.stringify = jsrsNative.stringify;
} else {
if (jstpNative) {
common.extend(jsrs, jstpNative);
if (!USE_NATIVE_SERIALIZER) {
jsrs.stringify = serializerFactory.createSerializer();
}

jsrs.parseNetworkPackets = jsrsNative.parseNetworkPackets;
}
11 changes: 11 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2016-2017 JSTP project authors. Use of this source code is
// governed by the MIT license that can be found in the LICENSE file.

#ifndef SRC_COMMON_H_
#define SRC_COMMON_H_

#define THROW_EXCEPTION(ex_type, ex_msg) \
isolate->ThrowException(v8::Exception::ex_type( \
v8::String::NewFromUtf8(isolate, ex_msg)))

#endif // SRC_COMMON_H_
Loading