aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-02-10 09:19:06 -0800
committerGravatar murgatroid99 <mlumish@google.com>2015-02-10 09:19:06 -0800
commit7dcc363aa714575c9377800f6499366cf9079819 (patch)
treef6046fa205141a563a4c2e0da0c4a680d10da66e /src/node
parentcd0b90621dd2b404d93b169836f02b1694b1f45c (diff)
parent3116d4f0fef9ac1e39a434dc6521109f1e0cffbf (diff)
Resolved merge conflicts
Diffstat (limited to 'src/node')
-rw-r--r--src/node/examples/math_server.js3
-rw-r--r--src/node/examples/stock.proto14
-rw-r--r--src/node/examples/stock_client.js3
-rw-r--r--src/node/examples/stock_server.js11
-rw-r--r--src/node/ext/event.cc29
5 files changed, 33 insertions, 27 deletions
diff --git a/src/node/examples/math_server.js b/src/node/examples/math_server.js
index e65cfe3002..e1bd11b5a6 100644
--- a/src/node/examples/math_server.js
+++ b/src/node/examples/math_server.js
@@ -128,7 +128,8 @@ var server = new Server({
});
if (require.main === module) {
- server.bind('localhost:7070').listen();
+ server.bind('0.0.0.0:7070');
+ server.listen();
}
/**
diff --git a/src/node/examples/stock.proto b/src/node/examples/stock.proto
index efe98d84ff..2bc5c29d17 100644
--- a/src/node/examples/stock.proto
+++ b/src/node/examples/stock.proto
@@ -35,28 +35,28 @@ package examples;
message StockRequest {
optional string symbol = 1;
optional int32 num_trades_to_watch = 2 [default=0];
-};
+}
message StockReply {
optional float price = 1;
optional string symbol = 2;
-};
+}
// Interface exported by the server
service Stock {
// Simple blocking RPC
rpc GetLastTradePrice(StockRequest) returns (StockReply) {
- };
+ }
// Bidirectional streaming RPC
rpc GetLastTradePriceMultiple(stream StockRequest) returns
(stream StockReply) {
- };
+ }
// Unidirectional server-to-client streaming RPC
rpc WatchFutureTrades(StockRequest) returns (stream StockReply) {
- };
+ }
// Unidirectional client-to-server streaming RPC
rpc GetHighestTradePrice(stream StockRequest) returns (StockReply) {
- };
+ }
-}; \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/node/examples/stock_client.js b/src/node/examples/stock_client.js
index 8e99090f35..b37e66df07 100644
--- a/src/node/examples/stock_client.js
+++ b/src/node/examples/stock_client.js
@@ -39,5 +39,8 @@ var examples = grpc.load(__dirname + '/stock.proto').examples;
*
* var StockClient = require('stock_client.js');
* var stockClient = new StockClient(server_address);
+ * stockClient.getLastTradePrice({symbol: 'GOOG'}, function(error, response) {
+ * console.log(error || response);
+ * });
*/
module.exports = examples.Stock;
diff --git a/src/node/examples/stock_server.js b/src/node/examples/stock_server.js
index c188181b77..b226a71573 100644
--- a/src/node/examples/stock_server.js
+++ b/src/node/examples/stock_server.js
@@ -35,10 +35,10 @@ var _ = require('underscore');
var grpc = require('..');
var examples = grpc.load(__dirname + '/stock.proto').examples;
-var StockServer = grpc.makeServerConstructor([examples.Stock.service]);
+var StockServer = grpc.buildServer([examples.Stock.service]);
function getLastTradePrice(call, callback) {
- callback(null, {price: 88});
+ callback(null, {symbol: call.request.symbol, price: 88});
}
function watchFutureTrades(call) {
@@ -80,4 +80,9 @@ var stockServer = new StockServer({
}
});
-exports.module = stockServer;
+if (require.main === module) {
+ stockServer.bind('0.0.0.0:8080');
+ stockServer.listen();
+}
+
+module.exports = stockServer;
diff --git a/src/node/ext/event.cc b/src/node/ext/event.cc
index b9446062d7..d59b68fb40 100644
--- a/src/node/ext/event.cc
+++ b/src/node/ext/event.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2014, Google Inc.
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,11 +58,11 @@ using v8::Value;
Handle<Value> ParseMetadata(grpc_metadata *metadata_elements, size_t length) {
NanEscapableScope();
- std::map<char*, size_t> size_map;
- std::map<char*, size_t> index_map;
+ std::map<const char*, size_t> size_map;
+ std::map<const char*, size_t> index_map;
for (unsigned int i = 0; i < length; i++) {
- char *key = metadata_elements[i].key;
+ const char *key = metadata_elements[i].key;
if (size_map.count(key)) {
size_map[key] += 1;
}
@@ -97,8 +97,6 @@ Handle<Value> GetEventData(grpc_event *event) {
switch (event->type) {
case GRPC_READ:
return NanEscapeScope(ByteBufferToBuffer(event->data.read));
- case GRPC_INVOKE_ACCEPTED:
- return NanEscapeScope(NanNew<Number>(event->data.invoke_accepted));
case GRPC_WRITE_ACCEPTED:
return NanEscapeScope(NanNew<Number>(event->data.write_accepted));
case GRPC_FINISH_ACCEPTED:
@@ -124,12 +122,12 @@ Handle<Value> GetEventData(grpc_event *event) {
return NanEscapeScope(NanNull());
}
rpc_new->Set(
- NanNew<String, const char *>("method"),
- NanNew<String, const char *>(event->data.server_rpc_new.method));
+ NanNew("method"),
+ NanNew(event->data.server_rpc_new.method));
rpc_new->Set(
- NanNew<String, const char *>("host"),
- NanNew<String, const char *>(event->data.server_rpc_new.host));
- rpc_new->Set(NanNew<String, const char *>("absolute_deadline"),
+ NanNew("host"),
+ NanNew(event->data.server_rpc_new.host));
+ rpc_new->Set(NanNew("absolute_deadline"),
NanNew<Date>(TimespecToMilliseconds(
event->data.server_rpc_new.deadline)));
count = event->data.server_rpc_new.metadata_count;
@@ -137,12 +135,11 @@ Handle<Value> GetEventData(grpc_event *event) {
metadata = NanNew<Array>(static_cast<int>(count));
for (unsigned int i = 0; i < count; i++) {
Handle<Object> item_obj = Object::New();
- item_obj->Set(NanNew<String, const char *>("key"),
- NanNew<String, char *>(items[i].key));
+ item_obj->Set(NanNew("key"),
+ NanNew(items[i].key));
item_obj->Set(
- NanNew<String, const char *>("value"),
- NanNew<String, char *>(items[i].value,
- static_cast<int>(items[i].value_length)));
+ NanNew("value"),
+ NanNew(items[i].value, static_cast<int>(items[i].value_length)));
metadata->Set(i, item_obj);
}
rpc_new->Set(NanNew("metadata"), ParseMetadata(items, count));