You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@0x8314444a113b636e;
interface Foo {
bar @0 () -> ();
}
test-server.c++:
#include "test.capnp.h"
#include <capnp/ez-rpc.h>
#include <iostream>
#include <unistd.h>
class FooImpl final: public Foo::Server {
public:
kj::Promise<void> bar(BarContext context) override {
std::cout << "inside of bar\n";
usleep(1000000);
return kj::READY_NOW;
}
};
int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: " << argv[0] << " ADDRESS[:PORT]\n"
"Runs the server bound to the given address/port.\n"
"ADDRESS may be '*' to bind to all local addresses.\n"
":PORT may be omitted to choose a port automatically." << std::endl;
return 1;
}
capnp::EzRpcServer server(argv[1]);
server.exportCap("foo", kj::heap<FooImpl>());
auto& waitScope = server.getWaitScope();
uint port = server.getPort().wait(waitScope);
std::cout << "Listening on port " << port << "..." << std::endl;
kj::NEVER_DONE.wait(waitScope);
}
Ugh. There's no good way in the C++ API to track which capabilities need which connections to stay open, so we can't really do the GC "correctly". I think what we probably need to do is maintain a singleton connection pool. Connections are kept in a map and a second attempt to connect to the same destination returns the same connection, until you explicitly call close().
test.capnp:
test-server.c++:
test.js:
I start the server in one terminal:
And in the other I start the client:
Sometimes, instead of the segfault I get:
The problem goes away if I force
conn
to live long enough, e.g. by puttingvar x = conn;
inside thethen
callback.The text was updated successfully, but these errors were encountered: