diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-08-04 18:09:31 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-08-04 18:11:14 +0200 |
commit | bad5ce8ac7eaeaf1161d2577d8a7b92d166e6764 (patch) | |
tree | 84d291a3dd0a5be1da133a9c04e1c5ce6b6f5b39 /ping.c | |
parent | 2da4adea98b371233e313b66e388331e83e0ff64 (diff) |
Diffstat (limited to 'ping.c')
-rw-r--r-- | ping.c | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -0,0 +1,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); + } +} |