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

Add gRPC support for WASM #55

Merged
merged 14 commits into from
May 8, 2019
Merged
3 changes: 1 addition & 2 deletions api/wasm/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ proxy_wasm_intrinsics.pb.h: proxy_wasm_intrinsics.proto
protoc --cpp_out=. proxy_wasm_intrinsics.proto

proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. -I. proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. struct_lite.proto

37 changes: 37 additions & 0 deletions api/wasm/cpp/proxy_wasm_intrinsics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,40 @@ extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onDelete(uint32_t context_id) {
c->onDelete();
context_map.erase(context_id);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcCreateInitialMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing curly brackets (here and throughout the code).

return;
c->onGrpcCreateInitialMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceiveInitialMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceiveInitialMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceiveTrailingMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceiveTrailingMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceive(uint32_t context_id, uint32_t token,
uint32_t response_ptr, uint32_t response_size) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceive(token, std::make_unique<WasmData>(reinterpret_cast<char*>(response_ptr), response_size));
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcClose(uint32_t context_id, uint32_t token,
uint32_t status_code, uint32_t status_message_ptr, uint32_t status_message_size) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcClose(token, static_cast<GrpcStatus>(status_code), std::make_unique<WasmData>(reinterpret_cast<char*>(status_message_ptr), status_message_size));
}
616 changes: 511 additions & 105 deletions api/wasm/cpp/proxy_wasm_intrinsics.h

Large diffs are not rendered by default.

30 changes: 10 additions & 20 deletions api/wasm/cpp/proxy_wasm_intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@ mergeInto(LibraryManager.library, {
proxy_setMetadataStruct: function () {},
proxy_continueRequest: function () {},
proxy_continueResponse: function () {},
proxy_addRequestHeader: function () {},
proxy_getRequestHeader: function () {},
proxy_getRequestHeaderPairs: function () {},
proxy_replaceRequestHeader: function () {},
proxy_removeRequestHeader: function () {},
proxy_addRequestTrailer: function () {},
proxy_getRequestTrailer: function () {},
proxy_getRequestTrailerPairs: function () {},
proxy_replaceRequestTrailer: function () {},
proxy_removeRequestTrailer: function () {},
proxy_addHeaderMapValue: function () {},
proxy_getHeaderMapValue: function () {},
proxy_getHeaderMapPairs: function () {},
proxy_replaceHeaderMapValue: function () {},
proxy_removeHeaderMapValue: function () {},
proxy_getRequestBodyBufferBytes: function () {},
proxy_addResponseHeader: function () {},
proxy_getResponseHeader: function () {},
proxy_getResponseHeaderPairs: function () {},
proxy_replaceResponseHeader: function () {},
proxy_removeResponseHeader: function () {},
proxy_addResponseTrailer: function () {},
proxy_getResponseTrailer: function () {},
proxy_getResponseTrailerPairs: function () {},
proxy_replaceResponseTrailer: function () {},
proxy_removeResponseTrailer: function () {},
proxy_getResponseBodyBufferBytes: function () {},
proxy_httpCall: function () {},
proxy_defineMetric: function () {},
proxy_incrementMetric: function () {},
proxy_recordMetric: function () {},
proxy_getMetric: function () {},
proxy_grpcCall : function () {},
proxy_grpcStream : function () {},
proxy_grpcSend : function () {},
proxy_grpcClose : function () {},
proxy_grpcCancel : function () {},
});
Loading