Commit d86bd67b authored by Kenton Varda's avatar Kenton Varda

Merge pull request #240 from chris-turner137/master

Added method accept() to TwoPartyServer for servicing arbitrary AsyncIoStreams.
parents 88966adf c565ce2b
...@@ -159,15 +159,19 @@ struct TwoPartyServer::AcceptedConnection { ...@@ -159,15 +159,19 @@ struct TwoPartyServer::AcceptedConnection {
rpcSystem(makeRpcServer(network, kj::mv(bootstrapInterface))) {} rpcSystem(makeRpcServer(network, kj::mv(bootstrapInterface))) {}
}; };
kj::Promise<void> TwoPartyServer::listen(kj::ConnectionReceiver& listener) { void TwoPartyServer::accept(kj::Own<kj::AsyncIoStream>&& connection)
return listener.accept() {
.then([this,&listener](kj::Own<kj::AsyncIoStream>&& connection) mutable {
auto connectionState = kj::heap<AcceptedConnection>(bootstrapInterface, kj::mv(connection)); auto connectionState = kj::heap<AcceptedConnection>(bootstrapInterface, kj::mv(connection));
// Run the connection until disconnect. // Run the connection until disconnect.
auto promise = connectionState->network.onDisconnect(); auto promise = connectionState->network.onDisconnect();
tasks.add(promise.attach(kj::mv(connectionState))); tasks.add(promise.attach(kj::mv(connectionState)));
}
kj::Promise<void> TwoPartyServer::listen(kj::ConnectionReceiver& listener) {
return listener.accept()
.then([this,&listener](kj::Own<kj::AsyncIoStream>&& connection) mutable {
accept(kj::mv(connection));
return listen(listener); return listen(listener);
}); });
} }
......
...@@ -119,6 +119,9 @@ class TwoPartyServer: private kj::TaskSet::ErrorHandler { ...@@ -119,6 +119,9 @@ class TwoPartyServer: private kj::TaskSet::ErrorHandler {
public: public:
explicit TwoPartyServer(Capability::Client bootstrapInterface); explicit TwoPartyServer(Capability::Client bootstrapInterface);
void accept(kj::Own<kj::AsyncIoStream>&& connection);
// Accepts the connection for servicing.
kj::Promise<void> listen(kj::ConnectionReceiver& listener); kj::Promise<void> listen(kj::ConnectionReceiver& listener);
// Listens for connections on the given listener. The returned promise never resolves unless an // Listens for connections on the given listener. The returned promise never resolves unless an
// exception is thrown while trying to accept. You may discard the returned promise to cancel // exception is thrown while trying to accept. You may discard the returned promise to cancel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment