libbinder: finalize connect/server APIs
Before, you needed to manually setup the required number of sockets on the client and server sides of a connection and manually setup threads. Now, you configure the thread count on RpcServer and call join once, and on the client side, you connect once, and the connection figured out how many connections it will make. Now, we will be able to manage how these sockets/threads get setup without affecting any client code in various tests. So, a server looks like this: sp<RpcServer> server = RpcServer::make(); // still until we are ready to open this up server->iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction(); server->setMaxThreads(3 /* for example */); // call this for each client (currently this must be setup in // advance) sp<RpcConnection> connection = server->addClientConnection(); // other server types are supported if (!connection->setupInetServer(1234 /*some port*/)) .. error .. // process requests for each client server->join(); And a client looks like this: sp<RpcConnection> connection = RpcConnection::make(); if (!connection->setupInetClient(/*some IP address*/, 1234 /*some port*/)) .. error .. The above code will create 3 threads on the server serving 3 separate socket connections that the client can use to make up to 3 simultaneous sets of syncrhonous calls (this can't be shared because the sockets may be needed for binder socket calls). This means that each address (ip + port) in this case can server a single process. Future considerations: - if we wanted, we could dynamically setup this connection, so that extra threads and sockets are only created as needed. This would be at parity with binder, but also it opens up the possibility for later errors. TODOs are added in the code for this. - a single server should be able to share a threadpool between multiple clients. Currently a new threadpool is created for each client. - new client connections should be able to be setup dynamically. Currently, once the threadpool is started, we don't support making more connections, but we should. Bug: 185167543 Test: binderRpcTest Change-Id: I4c11ab64bf7c1c19ca67f6a1c4be21de52358a5c
Loading
Please register or sign in to comment