Stiffstream / sobjectizer

An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
https://stiffstream.com/en/products/sobjectizer.html
Other
481 stars 47 forks source link

Template error on redirecting signals #35

Closed ilpropheta closed 3 years ago

ilpropheta commented 3 years ago

Hi everyone, just to report that redirecting a signal gives a compilation error on Visual Studio 2019 with C++17 enabled (tested on version 16.10.1):

class redirector : public so_5::agent_t {
    ...
    void on_some_immutable_signal(mhood_t<some_signal> cmd) {
        so_5::send(another_mbox, cmd);
        ...
    }
};

This causes the compiler to complain on line 297 of send_functions.hpp:

error C2059: syntax error: 'template'

I'm using the latest version of SObjectizer (5.7.2.5).

I have not investigated the issue but it seems a bug of the compiler. Is that something happening also on others?

eao197 commented 3 years ago

Hi!

I don't think that it's a compiler bug. It seems to be a missed case inside template magic around send functions. Redirection of signals usually doesn't have a sense, and I think that there is no such test case in our codebase yet.

I'll check it more carefully.

eao197 commented 3 years ago

@ilpropheta the fix is in the master branch.

ilpropheta commented 3 years ago

Hi @eao197, you are right, it's not the compiler. I had a too quick look at the issue!

I totally agree with you that it's not useful to redirect signals, however I would like to give you some context. Basically, as mentioned in #30, I have designed a sort of Parrot agent that is able to redirect any messages of a set of types to a mchain_t. Imagine something like that:

auto chain = context.AddParrot<int, std::string, MyMessage>(mbox);

This above registers a special agent that redirects any int, std::string, and MyMessage from the given mbox to chain. In my scenario, this simple agent is useful for many things (unit testing, load-balancing schemes, etc).

Today I have tried redirecting a signal but I got the mentioned error because my generic implementation was simply implemented in terms of two-argument so_5::send. E.g.:

so_5::send(dst, message);

Fixing the issue on my side was very simple (I just added a specialization for signals) but I think it was worth mentioning to you :)

Many thanks for your quick fix!

eao197 commented 3 years ago

Writing template agents that are parametrized by types of messages/signals received is, maybe, the only sensible case for redirection of signals. That code works in older versions of SObjectizer but was broken during the development of SO-5.6. And we didn't encounter that bug because that redirection wasn't used in our projects nor SObjectizer's tests.

Thanks for reporting!