taocpp / taopq

C++ client library for PostgreSQL
Boost Software License 1.0
265 stars 40 forks source link

Support for Pluggable I/O Polling #70

Closed ghost closed 10 months ago

ghost commented 10 months ago

Default connection implementation is using poll/WSAPoll functions for waiting connection socket to become readable/writable. While this approach works perfectly fine, it does not allow client application to do something else while waiting for connection socket.

In this pull request, I have introduced an abstract base class custom_io_poller, where concrete implementations of this class is responsible for monitoring a socket with timeout. Each connection keeps a pointer to the associated I/O poller, which is set to nullptr by default. On each invocation of connection::wait, connection will either call external I/O poller or poll the socket by itself.

This would make it possible to integrate taoPQ with Asio/Boost.Asio or similar async I/O frameworks. Could you consider adding such custom polling support to taoPQ prior to first public release?

Thanks.

d-frey commented 10 months ago

Looks interesting, but I think the implementation could probably be improved a bit, unifying it with the existing poll implementation. I will have a look when I have more time.

d-frey commented 10 months ago

I committed a more general version, putting the existing poll implementation(s) into a default_poll callback that you can overwrite. You can also set your own callback for a connection pool, which will then be used for all connections opened by the pool. Let me know if this works for you or if you have any other feedback.

ghost commented 10 months ago

Hello,

I think your version is fine too for general use. But it looks like "include/tao/pq/poll.hpp" is missing from the commit.

Thank you.

d-frey commented 10 months ago

My bad, I forgot the git add ... - should be fixed now.