Hi Jens, Sorry for the slow reply, I've been on leave.
In general, KJ async I/O objects are tied to the thread / event loop where they were created. This means you cannot pass an AsyncIoStream between threads. You can, however, pass a file descriptor. If you are careful, you could tear down the AsyncIoStream wrapping your socket, pass the socket file descriptor to another thread, and construct a new AsyncIoStream around it there. -Kenton On Wed, Nov 9, 2022 at 12:19 PM Jens Alfke <[email protected]> wrote: > > On Nov 9, 2022, at 6:47 AM, 'Kenton Varda' via Cap'n Proto < > [email protected]> wrote: > > Have you tested whether your server is able to accept concurrent > connections normally? E.g. if you open a connection with telnet or > something without sending any bytes, leave that open, and then try to use > your server, does it work? > > > *Thanks! That was indeed the problem.* The telnet test showed my server > would accept multiple connections at once, but would only authenticate one > of them at a time, so a client that didn’t send the right handshake would > block others. > > (I’m using custom code, largely copied from rpc.c++ and tls.c++, but > substituting the SecretHandshake protocol (from Scuttlebutt) for TLS. When > I adapted TlsConnectionReceiver::acceptLoop, I got things in the wrong > order, so the tail-recursion back to acceptLoop didn’t occur until the > secure handshake finished.) > > I’ve fixed it now. Next question: *if I want to run client connections on > multiple threads*, I presume that after the accept-and-handshake > finishes, I would create a new thread with an event loop, then use an > Executor to pass the AsyncIoStream to it, and then do the magic RPC setup > on that thread. On disconnect I’d either exit the thread or return it to a > pool for reuse. Most of this seems like boilerplate … are there any working > examples I could steal from? > > (Why would I want multiple threads when CapnP is async? Because my actual > RPC methods do SQLite queries, which are blocking and sometimes slow, and > I’d rather not create async wrappers for my entire complicated database > API.) > > —Jens > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/CAJouXQ%3DZfFUQYcFzKfUtJ57KuXH5Jpbd2HqX4Hbh8wLGdW8-Hw%40mail.gmail.com.
