Archived

This forum has been archived. Please start a new discussion on GitHub.

setCloseCallback and setACM cannot be used correctly and safely

// default example used setCloseCallback
connection = proxy->ice_getConnection();
connection->setACM(..);
connection->setCloseCallback({
// async handler
});
// between call ice_getConnection(or ice_getCachedConnection) and request remote func -
// asynchronous event close connection - any moment !!
...
proxy->Func(); //** auto reconnect, and ACM and CloseCallback set default !!!**

P.S. there may be a safe use case but it will be difficult

Comments

  • reconnect in setCloseCallback not solution. The link may be missing.

    check connection for each call-bad way:
    if(ice_getCachedConnection())
    {
    connection = proxy->ice_getConnection();
    connection->setACM(..);
    connection->setCloseCallback({
    // async handler
    });
    }
    // asynchronous event close connection - any moment !! unlikely but possible.
    proxy->Func();

  • benoit
    benoit Rennes, France

    Hi,

    If the connection is closed, you have the guarantee that the callback will be called. When it's called, your callback can notify your application that it needs to re-establish the connection to the server.

    If you want your proxy to only use the connection where you set the close callback instead of transparently reconnecting you can also create a fixed proxy:

    shared_ptr<Ice::ObjectPrx> prx = ...;
    auto con = prx->ice_getConnection();
    con->setACM(...);
    con->setCloseCallbacak(...);
    prx = prx->ice_fixed(con); // Available since 3.7.1
    prx->Func(); 
    

    With the code above, if the connection is closed, the callback will be called and the call to Func will raise an exception.

    Cheers,
    Benoit.