summaryrefslogtreecommitdiff
path: root/ping.c
blob: 32a2fb875f4c49b46fd702e98f51607119aa9fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* A pong client.

   Copyright (C) 2013 Free Software Foundation, Inc.

   Written by Justus Winter <4winter@informatik.uni-hamburg.de>

   This file might one day be a part of the GNU Hurd.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <error.h>
#include <hurd.h>
#include <stdio.h>
#include <unistd.h>

#include "reincarnation.h"

#include "pong_U.h"
#include "reincarnation_U.h"

int
main (int argc, char **argv)
{
  error_t err;

  if (argc != 2)
    error (1, 0, "Usage: %s PONG-SERVER", argv[0]);

  /* Get reincarnation port.  */
  mach_port_t reincarnation;
  err = reincarnation_get_port (mach_task_self (),
				&reincarnation);
  if (err)
    error (1, err, "reincarnation_get_port");

  if (reincarnation != MACH_PORT_NULL)
    {
      /* Get reincarnation image.  */
      char *image = NULL;
      size_t image_len = 0;
      err = reincarnation_reincarnate (reincarnation, &image, &image_len);
      if (err)
	error (1, err, "reincarnation_reincarnate");
    }

  mach_port_t pong = file_name_lookup (argv[1], 0, 0);
  if (pong == MACH_PORT_NULL)
    error (1, errno, "file_name_lookup");

  while (1)
    {
      int local;
      int global;
      err = ping (pong, &local, &global);
      if (err)
	error (1, err, "ping");

      printf ("local: % 4i\tglobal: % 4i\n", local, global);

      sleep (1);
    }
}