AntelopeIO / spring

C++ implementation of the Antelope protocol with Savanna consensus
Other
10 stars 5 forks source link

P2P, HTTP, SHiP: Change fc::create_listener to use strand #819

Closed heifner closed 1 month ago

heifner commented 1 month ago

Currently fc::create_listener creates sockets with the provided executor. For our use cases, it would be nice if fc::create_listener would create a strand for each socket. The users of fc::create_listener could then retrieve the strand from the socket.get_executor() for use.

Something like: https://github.com/AntelopeIO/spring/commit/438ae6223d7012f75f41b8332a0becda79ef723d

Then:

spoonincode commented 1 month ago

create_listener shouldn't blanket do this because some users of it (http) don't actually need the per connection strand. It should be driven by a parameter or different function name

spoonincode commented 1 month ago

Actually, because of https://github.com/AntelopeIO/spring/pull/816#discussion_r1774606535 I'm not sure create_listener should simply make the strand on the same executor it's using for listening. For this particular case it really seems best for the listener to remain on the main thread and have the socket with a strand in ship's thread. So maybe create_listener needs to take a functor that is called on each async_accept() that returns the executor for that call. To provide the most flexibility.