Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try again to be 32/64 bit agnostic
[simgrid.git] / teshsuite / msg / get_sender.c
1 /* Copyright (c) 2009, 2010. 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 <stdio.h>
8 #include "msg/msg.h"
9 #include <float.h>
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
12
13
14 static int send(int argc, char *argv[])
15 {
16   XBT_INFO("Sending");
17   MSG_task_send(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_get_name(MSG_host_self()));
18   MSG_process_sleep(1.);        /* FIXME: if the sender exits before the receiver calls get_sender(), bad thing happens */
19   XBT_INFO("Exiting");
20   return 0;
21 }
22
23 static int receive(int argc, char *argv[])
24 {
25   XBT_INFO("Receiving");
26   msg_task_t task = NULL;
27   MSG_task_receive_with_timeout(&task, MSG_host_get_name(MSG_host_self()), DBL_MAX);
28   xbt_assert(MSG_task_get_sender(task), "No sender received");
29   XBT_INFO("Got a message sent by '%s'",
30         MSG_process_get_name(MSG_task_get_sender(task)));
31   MSG_task_destroy(task);
32   return 0;
33 }
34
35 /** Main function */
36 int main(int argc, char *argv[])
37 {
38   msg_error_t res = MSG_OK;
39
40   MSG_init(&argc, argv);
41
42   /*   Application deployment */
43   MSG_function_register("send", &send);
44   MSG_function_register("receive", &receive);
45
46   MSG_create_environment(argv[1]);
47   MSG_launch_application(argv[2]);
48   res = MSG_main();
49
50   if (res == MSG_OK)
51     return 0;
52   else
53     return 1;
54 }