Naming reform for socket pieces, akin to what I did in huntd earlier.

(but not as comprehensive)
This commit is contained in:
dholland 2014-03-30 05:14:47 +00:00
parent 5c657efd0e
commit b57df0f022
5 changed files with 58 additions and 57 deletions

View File

@ -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. * Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -32,7 +32,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #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 */ #endif /* not lint */
#include <string.h> #include <string.h>
@ -50,13 +50,13 @@ do_connect(char *name, char team, long enter_status)
if (uid == 0) if (uid == 0)
uid = htonl(getuid()); uid = htonl(getuid());
(void) write(Socket, &uid, LONGLEN); (void) write(huntsocket, &uid, LONGLEN);
(void) write(Socket, name, NAMELEN); (void) write(huntsocket, name, NAMELEN);
(void) write(Socket, &team, 1); (void) write(huntsocket, &team, 1);
enter_status = htonl(enter_status); enter_status = htonl(enter_status);
(void) write(Socket, &enter_status, LONGLEN); (void) write(huntsocket, &enter_status, LONGLEN);
(void) strcpy(Buf, ttyname(fileno(stderr))); (void) strcpy(Buf, ttyname(fileno(stderr)));
(void) write(Socket, Buf, NAMELEN); (void) write(huntsocket, Buf, NAMELEN);
#ifdef INTERNET #ifdef INTERNET
if (Send_message != NULL) if (Send_message != NULL)
mode = C_MESSAGE; mode = C_MESSAGE;
@ -69,5 +69,5 @@ do_connect(char *name, char team, long enter_status)
#endif #endif
mode = C_PLAYER; mode = C_PLAYER;
mode = htonl(mode); mode = htonl(mode);
(void) write(Socket, &mode, sizeof mode); (void) write(huntsocket, &mode, sizeof mode);
} }

View File

@ -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. * Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -32,7 +32,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #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 */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -64,9 +64,11 @@ static const char Driver[] = PATH_HUNTD;
#endif #endif
#ifdef INTERNET #ifdef INTERNET
static uint16_t Test_port = TEST_PORT; static const char *contactportstr;
static uint16_t contactport = TEST_PORT;
static const char *contacthost;
#else #else
static const char Sock_name[] = PATH_HUNTSOCKET; static const char huntsockpath[] = PATH_HUNTSOCKET;
#endif #endif
@ -77,10 +79,8 @@ bool Am_monitor = false;
char Buf[BUFSIZ]; char Buf[BUFSIZ];
/*static*/ int Socket; /*static*/ int huntsocket;
#ifdef INTERNET #ifdef INTERNET
static char *Sock_host;
static char *use_port;
char *Send_message = NULL; char *Send_message = NULL;
#endif #endif
@ -182,11 +182,11 @@ main(int ac, char **av)
Send_message = optarg; Send_message = optarg;
break; break;
case 'h': case 'h':
Sock_host = optarg; contacthost = optarg;
break; break;
case 'p': case 'p':
use_port = optarg; contactportstr = optarg;
Test_port = atoi(use_port); contactport = atoi(contactportstr);
break; break;
#else #else
case 'S': case 'S':
@ -225,14 +225,14 @@ main(int ac, char **av)
if (optind + 1 < ac) if (optind + 1 < ac)
goto usage; goto usage;
else if (optind + 1 == ac) else if (optind + 1 == ac)
Sock_host = av[ac - 1]; contacthost = av[ac - 1];
#else #else
if (optind < ac) if (optind < ac)
goto usage; goto usage;
#endif #endif
#ifdef INTERNET #ifdef INTERNET
serverlist_setup(Sock_host, Test_port); serverlist_setup(contacthost, contactport);
if (Show_scores) { if (Show_scores) {
const struct sockaddr_storage *host; const struct sockaddr_storage *host;
@ -300,15 +300,15 @@ main(int ac, char **av)
do { do {
int option; int option;
Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0); huntsocket = socket(SOCK_FAMILY, SOCK_STREAM, 0);
if (Socket < 0) if (huntsocket < 0)
err(1, "socket"); err(1, "socket");
option = 1; option = 1;
if (setsockopt(Socket, SOL_SOCKET, SO_USELOOPBACK, if (setsockopt(huntsocket, SOL_SOCKET, SO_USELOOPBACK,
&option, sizeof option) < 0) &option, sizeof option) < 0)
warn("setsockopt loopback"); warn("setsockopt loopback");
errno = 0; errno = 0;
if (connect(Socket, (struct sockaddr *) &Daemon, if (connect(huntsocket, (struct sockaddr *) &Daemon,
DAEMON_SIZE) < 0) { DAEMON_SIZE) < 0) {
if (errno != ECONNREFUSED) { if (errno != ECONNREFUSED) {
leave(1, "connect"); leave(1, "connect");
@ -317,13 +317,13 @@ main(int ac, char **av)
else else
break; break;
sleep(1); sleep(1);
} while (close(Socket) == 0); } while (close(huntsocket) == 0);
#else /* !INTERNET */ #else /* !INTERNET */
/* /*
* set up a socket * 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"); err(1, "socket");
/* /*
@ -333,20 +333,20 @@ main(int ac, char **av)
*/ */
Daemon.sun_family = SOCK_FAMILY; Daemon.sun_family = SOCK_FAMILY;
(void) strcpy(Daemon.sun_path, Sock_name); (void) strcpy(Daemon.sun_path, huntsockpath);
if (connect(Socket, &Daemon, DAEMON_SIZE) < 0) { if (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0) {
if (errno != ENOENT) { if (errno != ENOENT) {
leavex(1, "connect2"); leavex(1, "connect2");
} }
start_driver(); start_driver();
do { do {
(void) close(Socket); (void) close(huntsocket);
if ((Socket = socket(SOCK_FAMILY, SOCK_STREAM, if ((huntsocket = socket(SOCK_FAMILY, SOCK_STREAM,
0)) < 0) 0)) < 0)
err(1, "socket"); err(1, "socket");
sleep(2); sleep(2);
} while (connect(Socket, &Daemon, DAEMON_SIZE) < 0); } while (connect(huntsocket, &Daemon, DAEMON_SIZE) < 0);
} }
#endif #endif
@ -474,7 +474,7 @@ start_driver(void)
#endif #endif
#ifdef INTERNET #ifdef INTERNET
if (Sock_host != NULL) { if (contacthost != NULL) {
sleep(3); sleep(3);
return; return;
} }
@ -490,14 +490,15 @@ start_driver(void)
if (procid == 0) { if (procid == 0) {
(void) signal(SIGINT, SIG_IGN); (void) signal(SIGINT, SIG_IGN);
#ifndef INTERNET #ifndef INTERNET
(void) close(Socket); (void) close(huntsocket);
#else #else
if (use_port == NULL) if (contactportstr == NULL)
#endif #endif
execl(Driver, "HUNT", (char *) NULL); execl(Driver, "HUNT", (char *) NULL);
#ifdef INTERNET #ifdef INTERNET
else else
execl(Driver, "HUNT", "-p", use_port, (char *) NULL); execl(Driver, "HUNT", "-p", contactportstr,
(char *) NULL);
#endif #endif
/* only get here if exec failed */ /* only get here if exec failed */
(void) kill(getppid(), SIGUSR1); /* tell mom */ (void) kill(getppid(), SIGUSR1); /* tell mom */
@ -591,9 +592,9 @@ intr(int dummy __unused)
if (isupper(ch)) if (isupper(ch))
ch = tolower(ch); ch = tolower(ch);
if (ch == 'y') { if (ch == 'y') {
if (Socket != 0) { if (huntsocket != 0) {
(void) write(Socket, "q", 1); (void) write(huntsocket, "q", 1);
(void) close(Socket); (void) close(huntsocket);
} }
leavex(0, NULL); leavex(0, NULL);
} }
@ -698,8 +699,8 @@ env_init(long enter_status)
} }
#ifdef INTERNET #ifdef INTERNET
else if (strncmp(envp, "port=", s - envp + 1) == 0) { else if (strncmp(envp, "port=", s - envp + 1) == 0) {
use_port = s + 1; contactportstr = s + 1;
Test_port = atoi(use_port); contactport = atoi(contactportstr);
if ((s = strchr(envp, ',')) == NULL) { if ((s = strchr(envp, ',')) == NULL) {
*envp = '\0'; *envp = '\0';
break; break;
@ -708,7 +709,7 @@ env_init(long enter_status)
envp = s + 1; envp = s + 1;
} }
else if (strncmp(envp, "host=", s - envp + 1) == 0) { else if (strncmp(envp, "host=", s - envp + 1) == 0) {
Sock_host = s + 1; contacthost = s + 1;
if ((s = strchr(envp, ',')) == NULL) { if ((s = strchr(envp, ',')) == NULL) {
*envp = '\0'; *envp = '\0';
break; break;

View File

@ -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. * Copyright (c) 1983-2003, Regents of the University of California.
@ -50,7 +50,7 @@
extern bool Last_player; extern bool Last_player;
extern char Buf[BUFSIZ]; extern char Buf[BUFSIZ];
extern int Socket; extern int huntsocket;
#ifdef INTERNET #ifdef INTERNET
extern char *Send_message; extern char *Send_message;
@ -64,7 +64,7 @@ extern char map_key[256];
extern bool no_beep; extern bool no_beep;
#ifdef INTERNET #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; extern SOCKET Daemon;
#endif #endif

View File

@ -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 #ifdef OTTO
/* /*
* Copyright (c) 1983-2003, Regents of the University of California. * Copyright (c) 1983-2003, Regents of the University of California.
@ -45,7 +45,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #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 */ #endif /* not lint */
#include <sys/time.h> #include <sys/time.h>
@ -217,7 +217,7 @@ otto(int y, int x, char face)
wander(); wander();
done: done:
(void) write(Socket, command, comlen); (void) write(huntsocket, command, comlen);
Otto_count += comlen; Otto_count += comlen;
#ifdef DEBUG #ifdef DEBUG
(void) fwrite(command, 1, comlen, debug); (void) fwrite(command, 1, comlen, debug);

View File

@ -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. * Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -32,7 +32,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #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 */ #endif /* not lint */
#include <sys/file.h> #include <sys/file.h>
@ -94,7 +94,7 @@ playit(void)
int y, x; int y, x;
uint32_t version; uint32_t version;
if (read(Socket, &version, LONGLEN) != LONGLEN) { if (read(huntsocket, &version, LONGLEN) != LONGLEN) {
bad_con(); bad_con();
/* NOTREACHED */ /* NOTREACHED */
} }
@ -191,7 +191,7 @@ playit(void)
} }
} }
out: out:
(void) close(Socket); (void) close(huntsocket);
} }
/* /*
@ -207,7 +207,7 @@ getchr(void)
struct pollfd set[2]; struct pollfd set[2];
int nfds; int nfds;
set[0].fd = Socket; set[0].fd = huntsocket;
set[0].events = POLLIN; set[0].events = POLLIN;
set[1].fd = STDIN; set[1].fd = STDIN;
set[1].events = POLLIN; set[1].events = POLLIN;
@ -222,7 +222,7 @@ one_more_time:
send_stuff(); send_stuff();
if (! (set[0].revents & POLLIN)) if (! (set[0].revents & POLLIN))
goto one_more_time; goto one_more_time;
icnt = read(Socket, ibuf, sizeof ibuf); icnt = read(huntsocket, ibuf, sizeof ibuf);
if (icnt < 0) { if (icnt < 0) {
bad_con(); bad_con();
/* NOTREACHED */ /* NOTREACHED */
@ -273,7 +273,7 @@ send_stuff(void)
nchar_send -= count; nchar_send -= count;
if (nchar_send < 0) if (nchar_send < 0)
count += nchar_send; count += nchar_send;
(void) write(Socket, inp, count); (void) write(huntsocket, inp, count);
} }
} }
@ -436,7 +436,7 @@ do_message(void)
{ {
uint32_t version; uint32_t version;
if (read(Socket, &version, LONGLEN) != LONGLEN) { if (read(huntsocket, &version, LONGLEN) != LONGLEN) {
bad_con(); bad_con();
/* NOTREACHED */ /* NOTREACHED */
} }
@ -445,10 +445,10 @@ do_message(void)
/* NOTREACHED */ /* NOTREACHED */
} }
#ifdef INTERNET #ifdef INTERNET
if (write(Socket, Send_message, strlen(Send_message)) < 0) { if (write(huntsocket, Send_message, strlen(Send_message)) < 0) {
bad_con(); bad_con();
/* NOTREACHED */ /* NOTREACHED */
} }
#endif #endif
(void) close(Socket); (void) close(huntsocket);
} }