Greetings,

I have some test code that is failing with a "Context was terminated" error 
from zmq. Here is the high-level overview of my code. I took the Broker example 
in the zmq documentation, modified it a bit, and wrapped a class around it. 
Then I have some test code that creates a connection to my Broker to test 
functionality. But both my Broker class and client connection all live in the 
same process (maybe this has something to do with it?)

More details: I have a poll function in my code that looks very similar to the 
example code:

bool Blackboard::poll_comm_interfaces()
{
        try {
                zmq::pollitem_t primary[] = {
                        { cloudbe, 0, ZMQ_POLLIN, 0 },
                        { statefe, 0, ZMQ_POLLIN, 0 },
                        { monitor, 0, ZMQ_POLLIN, 0 }
                };

                // Fails here
                zmq::poll(primary, 3, 0);

                ....
}

The "Context was terminated" error gets thrown at the zmq::poll(primary, 3, 0). 
And the blackboard class looks like:

class Blackboard : public IBroker, public ResourceMap
{
public:
        Blackboard();
        virtual ~Blackboard();

        ...

        virtual bool poll_comm_interfaces();

        ...

        zmq::context_t context;
        zmq::socket_t* local;
        zmq::socket_t* cloudfe;
        zmq::socket_t* cloudbe;
        zmq::socket_t* statefe;
        zmq::socket_t* statebe;
        zmq::socket_t* monitor;
};

Finally, my test code looks like:

bool PushRequest()
{
        Blackboard bb1;
        TEST_EQUALITY(bb1.init_comm_interfaces(BROKER_1_ADDR), true);

        // Make connection
        zmq::context_t context(1);
        zmq::socket_t client(context, ZMQ_XREP);
        char endpoint[256];

        try {
                char self[20] = "client";
                client.setsockopt(ZMQ_IDENTITY, self, strlen(self));
                sprintf(endpoint, "tcp://%s:%d", BROKER_1_ADDR, 
Blackboard::PortNumbers::LOCAL);
                client.connect(endpoint);
        } catch (const zmq::error_t& err)
        {
                printf("Failed to connect to blackboard (%s:%d), zmq error: 
%s\n", endpoint, Blackboard::PortNumbers::LOCAL, err.what());
                return false;
        }


        ...
        // Fails here
        bb1.poll_comm_interfaces();

        ...
}

Basically I don't see where the context could be terminated. The blackboard's 
context and the one created for the test code should be persistent all the way 
through to the end of the function. I also tried using the blackboard's context 
to create the client socket by doing:

// zmq::context_t context(1);
zmq::socket_t client(bb1.context, ZMQ_XREP);

But that throws the same error.

J.D.

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
  • [zeromq-dev] "... YAMOKOSKI, JOHN D. (JSC-ER)[OCEANEERING SPACE SYSTEMS]

Reply via email to