Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert get-sender test
[simgrid.git] / teshsuite / s4u / comm-get-sender / comm-get-sender.cpp
1 /* Copyright (c) 2009-2020. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/s4u.hpp"
8 #include <float.h>
9 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
10
11 static void sender_fun()
12 {
13   XBT_INFO("Sending");
14   std::string* payload = new std::string("Blah");
15   simgrid::s4u::Mailbox::by_name("Tremblay")->put(payload, 0);
16   simgrid::s4u::this_actor::sleep_for(1.0);
17   XBT_INFO("Exiting");
18 }
19
20 static void receiver_fun()
21 {
22   XBT_INFO("Receiving");
23   void* payload              = nullptr;
24   simgrid::s4u::CommPtr comm = simgrid::s4u::Mailbox::by_name("Tremblay")->get_async(&payload);
25   comm->wait();
26   xbt_assert(comm->get_sender(), "No sender received");
27   XBT_INFO("Got a message sent by '%s'", comm->get_sender()->get_cname());
28   simgrid::s4u::this_actor::sleep_for(2.0);
29   XBT_INFO("Did I tell you that I got a message sent by '%s'?", comm->get_sender()->get_cname());
30   delete static_cast<std::string*>(payload);
31 }
32
33 int main(int argc, char* argv[])
34 {
35   simgrid::s4u::Engine e(&argc, argv);
36
37   e.load_platform(argv[1]);
38
39   simgrid::s4u::Actor::create("send", simgrid::s4u::Host::by_name("Tremblay"), sender_fun);
40   simgrid::s4u::Actor::create("receive", simgrid::s4u::Host::by_name("Tremblay"), receiver_fun);
41
42   e.run();
43   return 0;
44 }