Open ibensw opened 2 months ago
Thanks for contributing!
However, your PR does not work with Windows, which does not have poll.h related stuffs. Also, even if you can check if it's available, you cannot run consuming in one thread, while call subscribe
in another thread. Since Subscriber
is not thread-safe.
Looks like this question is posted by you, and I've answered with 2 possible solutions to your problem. Please check if these solutions work with your case.
Regards
I agree that drawing in extra (posix) dependencies it not ideal. The solutions you provided do not fit our need. It looks like hiredis thought of this by providing a REDIS_OPT_NONBLOCK option which would solve my problem. However, this option should only be used on subscribers and if I understand the code directly all connections are created without knowledge of being used as a subscriber or not. I could dig into that direction if you think that is a viable option.
Another option hiredis provides is to create a connection by providing a fd, but since redis++ uses a connection pool this would require a create and destroy callback and might be to complicated for this task.
I am using redis++ for an application with a redis backend. We rely on pubsub for some communication between different processes.
Currently, we use socket_timeout and a loop to consume messages. This has some drawbacks however.
Therefor, I created a method in subscriber that calls a non-blocking poll call on the hiredis file descriptor.