From f0f60ae760a0274a50d65666e97a141a29287a8f Mon Sep 17 00:00:00 2001 From: dholland Date: Sun, 30 Mar 2014 05:14:47 +0000 Subject: Naming reform for socket pieces, akin to what I did in huntd earlier. (but not as comprehensive) --- hunt/hunt/connect.c | 16 ++++++------ hunt/hunt/hunt.c | 67 ++++++++++++++++++++++++------------------------ hunt/hunt/hunt_private.h | 6 ++--- hunt/hunt/otto.c | 6 ++--- hunt/hunt/playit.c | 20 +++++++-------- 5 files changed, 58 insertions(+), 57 deletions(-) (limited to 'hunt/hunt') diff --git a/hunt/hunt/connect.c b/hunt/hunt/connect.c index f1d35334..71729c02 100644 --- a/hunt/hunt/connect.c +++ b/hunt/hunt/connect.c @@ -1,4 +1,4 @@ -/* $NetBSD: connect.c,v 1.9 2014/03/29 21:24:26 dholland Exp $ */ +/* $NetBSD: connect.c,v 1.10 2014/03/30 05:14:47 dholland Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. * All rights reserved. @@ -32,7 +32,7 @@ #include #ifndef lint -__RCSID("$NetBSD: connect.c,v 1.9 2014/03/29 21:24:26 dholland Exp $"); +__RCSID("$NetBSD: connect.c,v 1.10 2014/03/30 05:14:47 dholland Exp $"); #endif /* not lint */ #include @@ -50,13 +50,13 @@ do_connect(char *name, char team, long enter_status) if (uid == 0) uid = htonl(getuid()); - (void) write(Socket, &uid, LONGLEN); - (void) write(Socket, name, NAMELEN); - (void) write(Socket, &team, 1); + (void) write(huntsocket, &uid, LONGLEN); + (void) write(huntsocket, name, NAMELEN); + (void) write(huntsocket, &team, 1); enter_status = htonl(enter_status); - (void) write(Socket, &enter_status, LONGLEN); + (void) write(huntsocket, &enter_status, LONGLEN); (void) strcpy(Buf, ttyname(fileno(stderr))); - (void) write(Socket, Buf, NAMELEN); + (void) write(huntsocket, Buf, NAMELEN); #ifdef INTERNET if (Send_message != NULL) mode = C_MESSAGE; @@ -69,5 +69,5 @@ do_connect(char *name, char team, long enter_status) #endif mode = C_PLAYER; mode = htonl(mode); - (void) write(Socket, &mode, sizeof mode); + (void) write(huntsocket, &mode, sizeof mode); } diff --git a/hunt/hunt/hunt.c b/hunt/hunt/hunt.c index 1a116d33..4621543b 100644 --- a/hunt/hunt/hunt.c +++ b/hunt/hunt/hunt.c @@ -1,4 +1,4 @@ -/* $NetBSD: hunt.c,v 1.53 2014/03/30 04:57:37 dholland Exp $ */ +/* $NetBSD: hunt.c,v 1.54 2014/03/30 05:14:47 dholland Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. * All rights reserved. @@ -32,7 +32,7 @@ #include #ifndef lint -__RCSID("$NetBSD: hunt.c,v 1.53 2014/03/30 04:57:37 dholland Exp $"); +__RCSID("$NetBSD: hunt.c,v 1.54 2014/03/30 05:14:47 dholland Exp $"); #endif /* not lint */ #include @@ -64,9 +64,11 @@ static const char Driver[] = PATH_HUNTD; #endif #ifdef INTERNET -static uint16_t Test_port = TEST_PORT; +static const char *contactportstr; +static uint16_t contactport = TEST_PORT; +static const char *contacthost; #else -static const char Sock_name[] = PATH_HUNTSOCKET; +static const char huntsockpath[] = PATH_HUNTSOCKET; #endif @@ -77,10 +79,8 @@ bool Am_monitor = false; char Buf[BUFSIZ]; -/*static*/ int Socket; +/*static*/ int huntsocket; #ifdef INTERNET -static char *Sock_host; -static char *use_port; char *Send_message = NULL; #endif @@ -182,11 +182,11 @@ main(int ac, char **av) Send_message = optarg; break; case 'h': - Sock_host = optarg; + contacthost = optarg; break; case 'p': - use_port = optarg; - Test_port = atoi(use_port); + contactportstr = optarg; + contactport = atoi(contactportstr); break; #else case 'S': @@ -225,14 +225,14 @@ main(int ac, char **av) if (optind + 1 < ac) goto usage; else if (optind + 1 == ac) - Sock_host = av[ac - 1]; + contacthost = av[ac - 1]; #else if (optind < ac) goto usage; #endif #ifdef INTERNET - serverlist_setup(Sock_host, Test_port); + serverlist_setup(contacthost, contactport); if (Show_scores) { const struct sockaddr_storage *host; @@ -300,15 +300,15 @@ main(int ac, char **av) do { int option; - Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0); - if (Socket < 0) + huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0); + if (huntsocket < 0) err(1, "socket"); option = 1; - if (setsockopt(Socket, SOL_SOCKET, SO_USELOOPBACK, + if (setsockopt(huntsocket, SOL_SOCKET, SO_USELOOPBACK, &option, sizeof option) < 0) warn("setsockopt loopback"); errno = 0; - if (connect(Socket, (struct sockaddr *) &Daemon, + if (connect(huntsocket, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) { if (errno != ECONNREFUSED) { leave(1, "connect"); @@ -317,13 +317,13 @@ main(int ac, char **av) else break; sleep(1); - } while (close(Socket) == 0); + } while (close(huntsocket) == 0); #else /* !INTERNET */ /* * set up a socket */ - if ((Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0)) < 0) + if ((huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0)) < 0) err(1, "socket"); /* @@ -333,20 +333,20 @@ main(int ac, char **av) */ Daemon.sun_family = SOCK_FAMILY; - (void) strcpy(Daemon.sun_path, Sock_name); - if (connect(Socket, &Daemon, DAEMON_SIZE) < 0) { + (void) strcpy(Daemon.sun_path, huntsockpath); + if (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0) { if (errno != ENOENT) { leavex(1, "connect2"); } start_driver(); do { - (void) close(Socket); - if ((Socket = socket(SOCK_FAMILY, SOCK_STREAM, + (void) close(huntsocket); + if ((huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0)) < 0) err(1, "socket"); sleep(2); - } while (connect(Socket, &Daemon, DAEMON_SIZE) < 0); + } while (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0); } #endif @@ -474,7 +474,7 @@ start_driver(void) #endif #ifdef INTERNET - if (Sock_host != NULL) { + if (contacthost != NULL) { sleep(3); return; } @@ -490,14 +490,15 @@ start_driver(void) if (procid == 0) { (void) signal(SIGINT, SIG_IGN); #ifndef INTERNET - (void) close(Socket); + (void) close(huntsocket); #else - if (use_port == NULL) + if (contactportstr == NULL) #endif execl(Driver, "HUNT", (char *) NULL); #ifdef INTERNET else - execl(Driver, "HUNT", "-p", use_port, (char *) NULL); + execl(Driver, "HUNT", "-p", contactportstr, + (char *) NULL); #endif /* only get here if exec failed */ (void) kill(getppid(), SIGUSR1); /* tell mom */ @@ -591,9 +592,9 @@ intr(int dummy __unused) if (isupper(ch)) ch = tolower(ch); if (ch == 'y') { - if (Socket != 0) { - (void) write(Socket, "q", 1); - (void) close(Socket); + if (huntsocket != 0) { + (void) write(huntsocket, "q", 1); + (void) close(huntsocket); } leavex(0, NULL); } @@ -698,8 +699,8 @@ env_init(long enter_status) } #ifdef INTERNET else if (strncmp(envp, "port=", s - envp + 1) == 0) { - use_port = s + 1; - Test_port = atoi(use_port); + contactportstr = s + 1; + contactport = atoi(contactportstr); if ((s = strchr(envp, ',')) == NULL) { *envp = '\0'; break; @@ -708,7 +709,7 @@ env_init(long enter_status) envp = s + 1; } else if (strncmp(envp, "host=", s - envp + 1) == 0) { - Sock_host = s + 1; + contacthost = s + 1; if ((s = strchr(envp, ',')) == NULL) { *envp = '\0'; break; diff --git a/hunt/hunt/hunt_private.h b/hunt/hunt/hunt_private.h index 7e5ba3a6..65c15e0e 100644 --- a/hunt/hunt/hunt_private.h +++ b/hunt/hunt/hunt_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: hunt_private.h,v 1.7 2014/03/30 04:31:21 dholland Exp $ */ +/* $NetBSD: hunt_private.h,v 1.8 2014/03/30 05:14:47 dholland Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. @@ -50,7 +50,7 @@ extern bool Last_player; extern char Buf[BUFSIZ]; -extern int Socket; +extern int huntsocket; #ifdef INTERNET extern char *Send_message; @@ -64,7 +64,7 @@ extern char map_key[256]; extern bool no_beep; #ifdef INTERNET -/* XXX this pile had to be made public to split off server.c; fix them up */ +/* XXX this had to be made public to split off server.c; fix it up */ extern SOCKET Daemon; #endif diff --git a/hunt/hunt/otto.c b/hunt/hunt/otto.c index de5ef41b..466d51b4 100644 --- a/hunt/hunt/otto.c +++ b/hunt/hunt/otto.c @@ -1,4 +1,4 @@ -/* $NetBSD: otto.c,v 1.17 2014/03/29 21:24:26 dholland Exp $ */ +/* $NetBSD: otto.c,v 1.18 2014/03/30 05:14:47 dholland Exp $ */ #ifdef OTTO /* * Copyright (c) 1983-2003, Regents of the University of California. @@ -45,7 +45,7 @@ #include #ifndef lint -__RCSID("$NetBSD: otto.c,v 1.17 2014/03/29 21:24:26 dholland Exp $"); +__RCSID("$NetBSD: otto.c,v 1.18 2014/03/30 05:14:47 dholland Exp $"); #endif /* not lint */ #include @@ -217,7 +217,7 @@ otto(int y, int x, char face) wander(); done: - (void) write(Socket, command, comlen); + (void) write(huntsocket, command, comlen); Otto_count += comlen; #ifdef DEBUG (void) fwrite(command, 1, comlen, debug); diff --git a/hunt/hunt/playit.c b/hunt/hunt/playit.c index ec702599..16978bfa 100644 --- a/hunt/hunt/playit.c +++ b/hunt/hunt/playit.c @@ -1,4 +1,4 @@ -/* $NetBSD: playit.c,v 1.19 2014/03/30 02:11:25 dholland Exp $ */ +/* $NetBSD: playit.c,v 1.20 2014/03/30 05:14:47 dholland Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. * All rights reserved. @@ -32,7 +32,7 @@ #include #ifndef lint -__RCSID("$NetBSD: playit.c,v 1.19 2014/03/30 02:11:25 dholland Exp $"); +__RCSID("$NetBSD: playit.c,v 1.20 2014/03/30 05:14:47 dholland Exp $"); #endif /* not lint */ #include @@ -94,7 +94,7 @@ playit(void) int y, x; uint32_t version; - if (read(Socket, &version, LONGLEN) != LONGLEN) { + if (read(huntsocket, &version, LONGLEN) != LONGLEN) { bad_con(); /* NOTREACHED */ } @@ -191,7 +191,7 @@ playit(void) } } out: - (void) close(Socket); + (void) close(huntsocket); } /* @@ -207,7 +207,7 @@ getchr(void) struct pollfd set[2]; int nfds; - set[0].fd = Socket; + set[0].fd = huntsocket; set[0].events = POLLIN; set[1].fd = STDIN; set[1].events = POLLIN; @@ -222,7 +222,7 @@ one_more_time: send_stuff(); if (! (set[0].revents & POLLIN)) goto one_more_time; - icnt = read(Socket, ibuf, sizeof ibuf); + icnt = read(huntsocket, ibuf, sizeof ibuf); if (icnt < 0) { bad_con(); /* NOTREACHED */ @@ -273,7 +273,7 @@ send_stuff(void) nchar_send -= count; if (nchar_send < 0) count += nchar_send; - (void) write(Socket, inp, count); + (void) write(huntsocket, inp, count); } } @@ -436,7 +436,7 @@ do_message(void) { uint32_t version; - if (read(Socket, &version, LONGLEN) != LONGLEN) { + if (read(huntsocket, &version, LONGLEN) != LONGLEN) { bad_con(); /* NOTREACHED */ } @@ -445,10 +445,10 @@ do_message(void) /* NOTREACHED */ } #ifdef INTERNET - if (write(Socket, Send_message, strlen(Send_message)) < 0) { + if (write(huntsocket, Send_message, strlen(Send_message)) < 0) { bad_con(); /* NOTREACHED */ } #endif - (void) close(Socket); + (void) close(huntsocket); } -- cgit v1.2.3-56-ge451