Cocaine 12 streaming

60 views
Skip to first unread message

Александр Могилко

unread,
Jun 28, 2016, 10:16:13 AM6/28/16
to reverbrain
Hello,
We are trying move from cocaine 11 to 12 and I'm investigating details. I didn't find any docs about writing applications with cocaine12 and examples are too simple.
Now I'm interested how properly send big array of bytes in chunks?

App:
worker.on("ping", [](worker::sender tx, worker::receiver rx) {
       std::cout << "After invoke" << std::endl;
       if (boost::optional<std::string> message = rx.recv().get()) { // app read one chunk
            std::cout << "After chunk: '" << *message << "'" << std::endl;
           tx.write(*message).get(); // app write one chunk
            std::cout << "After write" << std::endl;
       }
       std::cout << "After close" << std::endl;
   });

Client:
task<void>::future_type
on_invoke(task<channel<io::app::enqueue>>::future_move_type future) {
   auto channel = future.get();
   auto tx = std::move(channel.tx);
   auto rx = std::move(channel.rx);
   return tx.send<scope::chunk>("le message") // client write one chunk
        .then(trace_t::bind(&on_send, std::placeholders::_1, rx))
       .then(trace_t::bind(&on_chunk, std::placeholders::_1, rx)) // client read one chunk
        .then(trace_t::bind(&on_choke, std::placeholders::_1));
}

In this example I see how to send one chunk from client to app and backward. But what should I do if I want to send 3 chunks from client to app and after that 5 chunks from app to client?

Евгений Сафронов

unread,
Jun 28, 2016, 11:50:13 AM6/28/16
to reverbrain
Sender and receiver channels (aka tx/rx) are independent, so you are free to send as many chunks as you want via tx and on the other side receive as many chunks as you like.

Something like this:
tx.send<scope::chunk>("le message").get();
tx.send<scope::chunk>("another chunk").get();
tx.send<scope::chunk>("and one more").get();
tx.send<scope::close>().get();


вторник, 28 июня 2016 г., 17:16:13 UTC+3 пользователь Александр Могилко написал:

Александр Могилко

unread,
Jun 28, 2016, 1:57:10 PM6/28/16
to reverbrain
Is there way to determine when last chunk was read? Or I need to specify number of chunks in first chunk?

вторник, 28 июня 2016 г., 18:50:13 UTC+3 пользователь Евгений Сафронов написал:
Reply all
Reply to author
Forward
0 new messages