protobuf_grpc: google serializing and RPC library

protobuf : 3.9.1
grpc     : 1.24.0

Issue #190
This commit is contained in:
Pirmin Duss
2019-09-20 11:18:30 +02:00
committed by Norman Feske
parent f957aa538f
commit 5587d78e89
37 changed files with 2018 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
commit b4f45e0fa3e07a91623b1039dfea8dfa77f792e0
Author: Pirmin Duss <pirmin.duss@gapfruit.com>
Date: Mon Sep 23 15:15:49 2019 +0200
mutex fixes
diff --git a/include/grpc/impl/codegen/sync_custom.h b/include/grpc/impl/codegen/sync_custom.h
index 69b1bf6..dd0bb95 100644
--- a/include/grpc/impl/codegen/sync_custom.h
+++ b/include/grpc/impl/codegen/sync_custom.h
@@ -21,15 +21,15 @@
#include <grpc/impl/codegen/port_platform.h>
-#include <grpc/impl/codegen/sync_generic.h>
+#include <base/lock.h>
/* Users defining GPR_CUSTOM_SYNC need to define the following macros. */
#ifdef GPR_CUSTOM_SYNC
-typedef GPR_CUSTOM_MU_TYPE gpr_mu;
-typedef GPR_CUSTOM_CV_TYPE gpr_cv;
-typedef GPR_CUSTOM_ONCE_TYPE gpr_once;
+typedef Genode::Lock gpr_mu;
+typedef pthread_cond_t gpr_cv;
+typedef pthread_once_t gpr_once;
#define GPR_ONCE_INIT GPR_CUSTOM_ONCE_INIT
diff --git a/include/grpcpp/impl/codegen/sync.h b/include/grpcpp/impl/codegen/sync.h
index 146f182..d1a60cb 100644
--- a/include/grpcpp/impl/codegen/sync.h
+++ b/include/grpcpp/impl/codegen/sync.h
@@ -26,6 +26,7 @@
#endif
#include <mutex>
+#include <base/lock.h>
#include <grpc/impl/codegen/log.h>
#include <grpc/impl/codegen/sync.h>
@@ -58,7 +59,7 @@ class Mutex {
private:
union {
gpr_mu mu_;
- std::mutex do_not_use_sth_;
+ Genode::Lock do_not_use_sth_;
#ifdef GPR_HAS_PTHREAD_H
pthread_mutex_t do_not_use_pth_;
#endif
diff --git a/src/lib/grpc/src/cpp/server/external_connection_acceptor_impl.h b/src/lib/grpc/src/cpp/server/external_connection_acceptor_impl.h
index b5bd935..e835bbf 100644
--- a/src/cpp/server/external_connection_acceptor_impl.h
+++ b/src/cpp/server/external_connection_acceptor_impl.h
@@ -20,7 +20,7 @@
#define SRC_CPP_SERVER_EXTERNAL_CONNECTION_ACCEPTOR_IMPL_H_
#include <memory>
-#include <mutex>
+#include <base/lock.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpcpp/security/server_credentials.h>
@@ -60,7 +60,7 @@ class ExternalConnectionAcceptorImpl
const grpc::string name_;
std::shared_ptr<ServerCredentials> creds_;
grpc_core::TcpServerFdHandler* handler_ = nullptr; // not owned
- std::mutex mu_;
+ Genode::Lock mu_;
bool has_acceptor_ = false;
bool started_ = false;
bool shutdown_ = false;
diff --git a/src/lib/grpc/src/cpp/server/external_connection_acceptor_impl.cc b/src/lib/grpc/src/cpp/server/external_connection_acceptor_impl.cc
index 7f0e2dc..a788b0d 100644
--- a/src/cpp/server/external_connection_acceptor_impl.cc
+++ b/src/cpp/server/external_connection_acceptor_impl.cc
@@ -52,7 +52,7 @@ ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl(
std::unique_ptr<experimental::ExternalConnectionAcceptor>
ExternalConnectionAcceptorImpl::GetAcceptor() {
- std::lock_guard<std::mutex> lock(mu_);
+ std::lock_guard<Genode::Lock> lock(mu_);
GPR_ASSERT(!has_acceptor_);
has_acceptor_ = true;
return std::unique_ptr<experimental::ExternalConnectionAcceptor>(
@@ -61,7 +61,7 @@ ExternalConnectionAcceptorImpl::GetAcceptor() {
void ExternalConnectionAcceptorImpl::HandleNewConnection(
experimental::ExternalConnectionAcceptor::NewConnectionParameters* p) {
- std::lock_guard<std::mutex> lock(mu_);
+ std::lock_guard<Genode::Lock> lock(mu_);
if (shutdown_ || !started_) {
// TODO(yangg) clean up.
gpr_log(
@@ -76,12 +76,12 @@ void ExternalConnectionAcceptorImpl::HandleNewConnection(
}
void ExternalConnectionAcceptorImpl::Shutdown() {
- std::lock_guard<std::mutex> lock(mu_);
+ std::lock_guard<Genode::Lock> lock(mu_);
shutdown_ = true;
}
void ExternalConnectionAcceptorImpl::Start() {
- std::lock_guard<std::mutex> lock(mu_);
+ std::lock_guard<Genode::Lock> lock(mu_);
GPR_ASSERT(!started_);
GPR_ASSERT(has_acceptor_);
GPR_ASSERT(!shutdown_);

View File

@@ -0,0 +1,39 @@
diff --git a/src/cpp/util/core_stats.h b/src/cpp/util/core_stats.h
index 6366d7d..0f0e2ee 100644
--- a/src/cpp/util/core_stats.h
+++ b/src/cpp/util/core_stats.h
@@ -19,7 +19,7 @@
#ifndef GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H
#define GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H
-#include "src/proto/grpc/core/stats.pb.h"
+#include "stats.pb.h"
#include "src/core/lib/debug/stats.h"
diff --git a/src/cpp/util/error_details.cc b/src/cpp/util/error_details.cc
index a1aafcb..6be9390 100644
--- a/src/cpp/util/error_details.cc
+++ b/src/cpp/util/error_details.cc
@@ -18,7 +18,7 @@
#include <grpcpp/support/error_details.h>
-#include "src/proto/grpc/status/status.pb.h"
+#include "status.pb.h"
namespace grpc_impl {
diff --git a/src/cpp/ext/proto_server_reflection.h b/src/cpp/ext/proto_server_reflection.h
index bf40c3c180..69f36c3e96 100644
--- a/src/cpp/ext/proto_server_reflection.h
+++ b/src/cpp/ext/proto_server_reflection.h
@@ -23,7 +23,7 @@
#include <vector>
#include <grpcpp/grpcpp.h>
-#include "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h"
+#include "reflection.grpc.pb.h"
namespace grpc {

View File

@@ -0,0 +1,20 @@
diff --git a/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc b/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc
index f1ba20dcec..0d94d79246 100644
--- a/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc
+++ b/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc
@@ -29,13 +29,8 @@
#include <grpc/support/log.h>
-uint32_t grpc_if_nametoindex(char* name) {
- uint32_t out = if_nametoindex(name);
- if (out == 0) {
- gpr_log(GPR_DEBUG, "if_nametoindex failed for name %s. errno %d", name,
- errno);
- }
- return out;
+uint32_t grpc_if_nametoindex(char*) {
+ return 1;
}
#endif /* GRPC_IF_NAMETOINDEX == 1 && \

View File

@@ -0,0 +1,152 @@
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc
index 47d9f51b09..66abe6982a 100644
--- a/src/core/lib/iomgr/socket_utils_common_posix.cc
+++ b/src/core/lib/iomgr/socket_utils_common_posix.cc
@@ -70,21 +70,21 @@ grpc_error* grpc_set_socket_nonblocking(int fd, int non_blocking) {
return GRPC_ERROR_NONE;
}
-grpc_error* grpc_set_socket_no_sigpipe_if_possible(int fd) {
-#ifdef GRPC_HAVE_SO_NOSIGPIPE
- int val = 1;
- int newval;
- socklen_t intlen = sizeof(newval);
- if (0 != setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val))) {
- return GRPC_OS_ERROR(errno, "setsockopt(SO_NOSIGPIPE)");
- }
- if (0 != getsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &newval, &intlen)) {
- return GRPC_OS_ERROR(errno, "getsockopt(SO_NOSIGPIPE)");
- }
- if ((newval != 0) != (val != 0)) {
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_NOSIGPIPE");
- }
-#endif
+grpc_error* grpc_set_socket_no_sigpipe_if_possible(int /*fd*/) {
+//#ifdef GRPC_HAVE_SO_NOSIGPIPE
+// int val = 1;
+// int newval;
+// socklen_t intlen = sizeof(newval);
+// if (0 != setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val))) {
+// return GRPC_OS_ERROR(errno, "setsockopt(SO_NOSIGPIPE)");
+// }
+// if (0 != getsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &newval, &intlen)) {
+// return GRPC_OS_ERROR(errno, "getsockopt(SO_NOSIGPIPE)");
+// }
+// if ((newval != 0) != (val != 0)) {
+// return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_NOSIGPIPE");
+// }
+//#endif
return GRPC_ERROR_NONE;
}
@@ -125,22 +125,22 @@ grpc_error* grpc_set_socket_rcvbuf(int fd, int buffer_size_bytes) {
}
/* set a socket to close on exec */
-grpc_error* grpc_set_socket_cloexec(int fd, int close_on_exec) {
- int oldflags = fcntl(fd, F_GETFD, 0);
- if (oldflags < 0) {
- return GRPC_OS_ERROR(errno, "fcntl");
- }
-
- if (close_on_exec) {
- oldflags |= FD_CLOEXEC;
- } else {
- oldflags &= ~FD_CLOEXEC;
- }
-
- if (fcntl(fd, F_SETFD, oldflags) != 0) {
- return GRPC_OS_ERROR(errno, "fcntl");
- }
-
+grpc_error* grpc_set_socket_cloexec(int /*fd*/, int /*close_on_exec*/) {
+// int oldflags = fcntl(fd, F_GETFD, 0);
+// if (oldflags < 0) {
+// return GRPC_OS_ERROR(errno, "fcntl");
+// }
+//
+// if (close_on_exec) {
+// oldflags |= FD_CLOEXEC;
+// } else {
+// oldflags &= ~FD_CLOEXEC;
+// }
+//
+// if (fcntl(fd, F_SETFD, oldflags) != 0) {
+// return GRPC_OS_ERROR(errno, "fcntl");
+// }
+//
return GRPC_ERROR_NONE;
}
@@ -163,24 +163,24 @@ grpc_error* grpc_set_socket_reuse_addr(int fd, int reuse) {
}
/* set a socket to reuse old addresses */
-grpc_error* grpc_set_socket_reuse_port(int fd, int reuse) {
+grpc_error* grpc_set_socket_reuse_port(int /*fd*/, int /*reuse*/) {
#ifndef SO_REUSEPORT
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"SO_REUSEPORT unavailable on compiling system");
#else
- int val = (reuse != 0);
- int newval;
- socklen_t intlen = sizeof(newval);
- if (0 != setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val))) {
- return GRPC_OS_ERROR(errno, "setsockopt(SO_REUSEPORT)");
- }
- if (0 != getsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &newval, &intlen)) {
- return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEPORT)");
- }
- if ((newval != 0) != val) {
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEPORT");
- }
-
+// int val = (reuse != 0);
+// int newval;
+// socklen_t intlen = sizeof(newval);
+// if (0 != setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val))) {
+// return GRPC_OS_ERROR(errno, "setsockopt(SO_REUSEPORT)");
+// }
+// if (0 != getsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &newval, &intlen)) {
+// return GRPC_OS_ERROR(errno, "getsockopt(SO_REUSEPORT)");
+// }
+// if ((newval != 0) != val) {
+// return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set SO_REUSEPORT");
+// }
+//
return GRPC_ERROR_NONE;
#endif
}
@@ -210,19 +210,19 @@ bool grpc_is_socket_reuse_port_supported() {
}
/* disable nagle */
-grpc_error* grpc_set_socket_low_latency(int fd, int low_latency) {
- int val = (low_latency != 0);
- int newval;
- socklen_t intlen = sizeof(newval);
- if (0 != setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val))) {
- return GRPC_OS_ERROR(errno, "setsockopt(TCP_NODELAY)");
- }
- if (0 != getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &newval, &intlen)) {
- return GRPC_OS_ERROR(errno, "getsockopt(TCP_NODELAY)");
- }
- if ((newval != 0) != val) {
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set TCP_NODELAY");
- }
+grpc_error* grpc_set_socket_low_latency(int /*fd*/, int /*low_latency*/) {
+// int val = (low_latency != 0);
+// int newval;
+// socklen_t intlen = sizeof(newval);
+// if (0 != setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val))) {
+// return GRPC_OS_ERROR(errno, "setsockopt(TCP_NODELAY)");
+// }
+// if (0 != getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &newval, &intlen)) {
+// return GRPC_OS_ERROR(errno, "getsockopt(TCP_NODELAY)");
+// }
+// if ((newval != 0) != val) {
+// return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set TCP_NODELAY");
+// }
return GRPC_ERROR_NONE;
}

View File

@@ -0,0 +1,26 @@
diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc
index 932583c84a..0fa38aac38 100644
--- a/examples/cpp/helloworld/greeter_client.cc
+++ b/examples/cpp/helloworld/greeter_client.cc
@@ -77,7 +77,7 @@ int main(int argc, char** argv) {
// localhost at port 50051). We indicate that the channel isn't authenticated
// (use of InsecureChannelCredentials()).
GreeterClient greeter(grpc::CreateChannel(
- "localhost:50051", grpc::InsecureChannelCredentials()));
+ "10.10.10.55:50051", grpc::InsecureChannelCredentials()));
std::string user("world");
std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl;
diff --git a/examples/cpp/helloworld/greeter_server.cc b/examples/cpp/helloworld/greeter_server.cc
index f36ad906a2..03025b7920 100644
--- a/examples/cpp/helloworld/greeter_server.cc
+++ b/examples/cpp/helloworld/greeter_server.cc
@@ -47,7 +47,7 @@ class GreeterServiceImpl final : public Greeter::Service {
};
void RunServer() {
- std::string server_address("0.0.0.0:50051");
+ std::string server_address("10.10.10.55:50051");
GreeterServiceImpl service;
ServerBuilder builder;

View File

@@ -0,0 +1,12 @@
diff --git a/third_party/genode/if_indextoname.c b/third_party/genode/if_indextoname.c
new file mode 100644
index 0000000000..9ea67cee0c
--- /dev/null
+++ b/third_party/genode/if_indextoname.c
@@ -0,0 +1,6 @@
+char * if_indextoname(unsigned int ifindex, char *ifname)
+{
+ const char* name = "eth0";
+ ifname = name;
+ return ifname;
+}

View File

@@ -0,0 +1,28 @@
commit 3a55e1d3c8ab37fb14a9a2875db0e031044d4863
Author: Pirmin Duss <pirmin.duss@gapfruit.com>
Date: Mon Sep 23 16:16:57 2019 +0200
Mutex fixes
diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h
index a311889..967be6a 100644
--- a/src/google/protobuf/stubs/mutex.h
+++ b/src/google/protobuf/stubs/mutex.h
@@ -30,7 +30,7 @@
#ifndef GOOGLE_PROTOBUF_STUBS_MUTEX_H_
#define GOOGLE_PROTOBUF_STUBS_MUTEX_H_
-#include <mutex>
+#include <base/lock.h>
#ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
@@ -104,7 +104,7 @@ class PROTOBUF_EXPORT GOOGLE_PROTOBUF_CAPABILITY("mutex") WrappedMutex {
private:
#ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
- std::mutex mu_;
+ Genode::Lock mu_;
#else // ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
CriticalSectionLock mu_;
#endif // #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP

View File

@@ -0,0 +1,34 @@
commit 420f5bb78bfd61825ad5d3bc52a27469f298d17b
Author: Pirmin Duss <pirmin.duss@gapfruit.com>
Date: Mon Sep 23 16:33:08 2019 +0200
run_once fix
diff --git a/src/google/protobuf/stubs/once.h b/src/google/protobuf/stubs/once.h
index 070d36d..3602ee7 100644
--- a/src/google/protobuf/stubs/once.h
+++ b/src/google/protobuf/stubs/once.h
@@ -31,19 +31,16 @@
#ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__
#define GOOGLE_PROTOBUF_STUBS_ONCE_H__
-#include <mutex>
-#include <utility>
-
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace internal {
-using once_flag = std::once_flag;
-template <typename... Args>
-void call_once(Args&&... args ) {
- std::call_once(std::forward<Args>(args)...);
+using once_flag = int;
+template <typename FN, typename... Args>
+void call_once(once_flag, FN fn, Args&&... args ) {
+ fn(std::forward<Args>(args)...);
}
} // namespace internal

View File

@@ -0,0 +1,45 @@
diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc
index 36d7307..04a565b 100644
--- a/src/google/protobuf/generated_message_util.cc
+++ b/src/google/protobuf/generated_message_util.cc
@@ -799,8 +799,8 @@ void InitSCCImpl(SCCInfoBase* scc) {
// Either the default in case no initialization is running or the id of the
// thread that is currently initializing.
#ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
- static std::atomic<std::thread::id> runner;
- auto me = std::this_thread::get_id();
+ static std::atomic<long long> runner = -1LL;
+ auto me = 1LL;
#else
// This is a lightweight replacement for std::thread::id. std::thread does not
// work on Windows XP SP2 with the latest VC++ libraries, because it utilizes
@@ -811,20 +811,20 @@ void InitSCCImpl(SCCInfoBase* scc) {
// This will only happen because the constructor will call InitSCC while
// constructing the default instance.
- if (runner.load(std::memory_order_relaxed) == me) {
- // Because we're in the process of constructing the default instance.
- // We can be assured that we're already exploring this SCC.
- GOOGLE_CHECK_EQ(scc->visit_status.load(std::memory_order_relaxed),
- SCCInfoBase::kRunning);
- return;
- }
+ if (runner.load(std::memory_order_relaxed) == me) {
+ // Because we're in the process of constructing the default instance.
+ // We can be assured that we're already exploring this SCC.
+ GOOGLE_CHECK_EQ(scc->visit_status.load(std::memory_order_relaxed),
+ SCCInfoBase::kRunning);
+ return;
+ }
InitProtobufDefaults();
mu.Lock();
- runner.store(me, std::memory_order_relaxed);
+ runner.store(me, std::memory_order_relaxed);
InitSCC_DFS(scc);
#ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
- runner.store(std::thread::id{}, std::memory_order_relaxed);
+ runner.store(0, std::memory_order_relaxed);
#else
runner.store(-1, std::memory_order_relaxed);
#endif // #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP

View File

@@ -0,0 +1,34 @@
GRPC_DIR := $(call select_from_ports,protobuf_grpc)/src/lib/grpc
PROTO_DIR := $(GRPC_DIR)/examples/protos
TARGET := grpc_client
LIBS := posix
LIBS += protobuf
LIBS += stdcxx
LIBS += grpc
LIBS += libc_pipe
CC_CXX_WARN_STRICT :=
PROTOC := /usr/local/genode/protobuf_grpc/current/bin/protoc
GRPC_PLUGIN := /usr/local/genode/protobuf_grpc/current/bin/grpc_cpp_plugin
SRC_CC := greeter_client.cc
SRC_CC += helloworld.pb.cc
SRC_CC += helloworld.grpc.pb.cc
vpath greeter_client.cc $(GRPC_DIR)/examples/cpp/helloworld
vpath helloworld.proto $(PROTO_DIR)
$(SRC_CC): helloworld.grpc.pb.h
helloworld.pb.h: helloworld.proto
$(VERBOSE)$(PROTOC) --proto_path=$(PROTO_DIR) \
--cpp_out=. \
$<
helloworld.grpc.pb.h: helloworld.proto helloworld.pb.h
$(VERBOSE)$(PROTOC) --plugin=protoc-gen-grpc=$(GRPC_PLUGIN) \
--proto_path=$(PROTO_DIR) \
--grpc_out=. \
$<

View File

@@ -0,0 +1,70 @@
/*
*
* Copyright 2015 gRPC authors.
*
* 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.
*
*/
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp/grpcpp.h>
#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif
#include "greeter_server.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
using helloworld::Greeter;
// Logic and data behind the server's behavior.
class GreeterServiceImpl final : public Greeter::Service {
Status SayHello(ServerContext* context, const HelloRequest* request,
HelloReply* reply) override {
printf("say hello\n");
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
return Status::OK;
}
};
void RunServer() {
std::string server_address("10.10.10.55:50051");
GreeterServiceImpl service;
ServerBuilder builder;
// Listen on the given address without any authentication mechanism.
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
// Register "service" as the instance through which we'll communicate with
// clients. In this case it corresponds to an *synchronous* service.
builder.RegisterService(&service);
// Finally assemble the server.
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
// Wait for the server to shutdown. Note that some other thread must be
// responsible for shutting down the server for this call to ever return.
server->Wait();
}

View File

@@ -0,0 +1,4 @@
#pragma once
void RunServer();

View File

@@ -0,0 +1,50 @@
#include <base/attached_rom_dataspace.h>
#include <libc/component.h>
#include <base/heap.h>
#include <base/log.h>
#include <base/thread.h>
#include "greeter_server.h"
enum { STACK_SIZE = 0xF000 };
namespace Tee_server {
using namespace Genode;
class Runner;
class Server_main;
}
class Tee_server::Runner : public Thread
{
public:
Runner(Env& env)
: Thread(env, "runner", STACK_SIZE)
{
}
void entry() override
{
Libc::with_libc([] () {
RunServer();
});
}
};
class Tee_server::Server_main
{
private:
Env& _env;
Runner _runner { _env };
public:
Server_main(Env& env)
: _env(env)
{
_runner.start();
}
};
void Libc::Component::construct(Libc::Env &env)
{
static Tee_server::Server_main main(env);
}

View File

@@ -0,0 +1,35 @@
GRPC_DIR := $(call select_from_ports,protobuf_grpc)/src/lib/grpc
PROTO_DIR := $(GRPC_DIR)/examples/protos
TARGET := grpc_server
LIBS += protobuf
LIBS += stdcxx
LIBS += grpc
LIBS += libc_pipe
LIBS += vfs
LIBS += vfs_lwip
CC_CXX_WARN_STRICT :=
PROTOC := /usr/local/genode/protobuf_grpc/current/bin/protoc
GRPC_PLUGIN := /usr/local/genode/protobuf_grpc/current/bin/grpc_cpp_plugin
SRC_CC := main.cc
SRC_CC += greeter_server.cc
SRC_CC += helloworld.pb.cc
SRC_CC += helloworld.grpc.pb.cc
vpath helloworld.proto $(PROTO_DIR)
$(SRC_CC): helloworld.grpc.pb.h
helloworld.pb.h: helloworld.proto
$(VERBOSE)$(PROTOC) --proto_path=$(PROTO_DIR) \
--cpp_out=. \
$<
helloworld.grpc.pb.h: helloworld.proto helloworld.pb.h
$(VERBOSE)$(PROTOC) --plugin=protoc-gen-grpc=$(GRPC_PLUGIN) \
--proto_path=$(PROTO_DIR) \
--grpc_out=. \
$<

View File

@@ -0,0 +1,23 @@
PROTOBUF_DIR := $(call select_from_ports,protobuf_grpc)/src/lib/protobuf
TARGET := add_person
LIBS := posix protobuf stdcxx
SRC_CC += add_person.cc \
addressbook.pb.cc
PROTOC := /usr/local/genode/tool/current/bin/protoc
CC_CXX_WARN_STRICT =
vpath add_person.cc $(PROTOBUF_DIR)/examples
vpath addressbook.proto $(PROTOBUF_DIR)/examples
$(SRC_CC): addressbook.pb.h
addressbook.pb.h: addressbook.proto
$(VERBOSE)$(PROTOC) --proto_path=$(PROTOBUF_DIR)/examples \
--proto_path=$(PROTO_FILES_DIR) \
--cpp_out=$(shell pwd) \
$<

View File

@@ -0,0 +1,23 @@
PROTOBUF_DIR := $(call select_from_ports,protobuf_grpc)/src/lib/protobuf
TARGET := list_people
LIBS := posix protobuf stdcxx
SRC_CC += list_people.cc \
addressbook.pb.cc
PROTOC := /usr/local/genode/tool/current/bin/protoc
CC_CXX_WARN_STRICT =
vpath list_people.cc $(PROTOBUF_DIR)/examples
vpath addressbook.proto $(PROTOBUF_DIR)/examples
$(SRC_CC): addressbook.pb.h
addressbook.pb.h: addressbook.proto
$(VERBOSE)$(PROTOC) --proto_path=$(PROTOBUF_DIR)/examples \
--proto_path=$(PROTO_FILES_DIR) \
--cpp_out=$(shell pwd) \
$<