SObjectizer-5.7.1 and so5extra-1.4.1 released!

8 views
Skip to first unread message

Yauheni Akhotnikau

unread,
Jun 22, 2020, 5:08:26 AM6/22/20
to SObjectizer
SObjectizer-5.7.1 introduces a couple of new features and also contains a few fixes.

One of the new features is default (or generic) message limits:

class demo final : public so_5::agent_t
{
public:
   demo
(context_t ctx)
     
: so_5::agent_t{ctx
         
+ limit_then_drop<msg_A>(100u)
         
+ limit_then_abort<msg_B>(10u)
         
// That limit will be used for all other messages.
         
+ limit_then_drop<any_unspecified_message>(50u)
         
}
   
{}


   
void so_define_agent() override
   
{
     
// Explicitly defined limit will be used.
      so_subscribe_self
().event([](mhood_t<msg_A> cmd) {...});


     
// A new limit object will be created for msg_C here.
      so_subscribe_self
().event([](mhood_t<msg_C> cmd) {...});
   
}
};

Another new feature is template function `make_agent_ref` that can be useful if a pointer to an agent has to be passed to some callback:

class io_performer final : public so_5::agent_t
{
   asio
::io::tcp::socket connection_;
   std
::array<std::byte, 4096> input_buffer_;


   
void handle_incoming_data(std::size_t bytes_transferred) {...}


   
void on_some_event(mhood_t<some_msg> cmd)
   
{
     
// It's time to read some data.
      connection_
.async_read_some(asio::buffer(input_buffer_),
         
[self=so_5::make_agent_ref(this)]
         
(const asio::error_code & ec, std::size_t bytes_transferred)
         
{
           
if(!ec)
               
self->handle_incoming_data(bytes_transferred);
         
});
   
}
   
...
};

That way of passing a pointer to agent to a callback guarantees that the pointer remains valid even if the agent is deregistered before the invocation of the callback.

More information about new v.5.7.1 changes can be found here.

The new version of so5extra introduces another type of dispatcher: asio_one_thread that uses Asio's io_context object for serving I/O operations and message dispatching on just one worker thread.
Reply all
Reply to author
Forward
0 new messages