From 7d3df37b572192b6915f5fc3ea9803b195e3a5b3 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 14 Jul 2014 17:51:16 -0400 Subject: Minor fixes --- server.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 568c5e6..629d976 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -x/* +/* * WarGames - a WOPR emulator written in C * Copyright (C) 2014 Franklin Wei * @@ -18,17 +18,18 @@ x/* * Contact the author at contact@fwei.tk */ -#include -#include -#include +#include "joshua.h" #include -#include #include -#include -#include -#include +#include #include -#include "joshua.h" +#include +#include +#include +#include +#include +#include + int server_socket; uint16_t port; int pipes[FD_SETSIZE][2]; @@ -58,9 +59,15 @@ int process_data(int fd) char buf[1024]; memset(buf, 0, sizeof(buf)); int ret=read(fd, buf, sizeof(buf)); + char ctrl_c[]={0xff, 0xf4, 0xff, 0xfd, 0x06, 0x00}; + if(strcmp(ctrl_c, buf)==0) + { + printf("Got CTRL-C from client.\n"); + return -1; + } if(ret<0) /* error */ { - printf("error in read()\n"); + printf("Error in read()\n"); return -1; } if(ret==0) @@ -80,7 +87,6 @@ void serv_cleanup() printf("preparing to exit...\n"); fflush(stdout); shutdown(server_socket, SHUT_RDWR); - close(server_socket); } int main(int argc, char* argv[]) { @@ -89,8 +95,8 @@ int main(int argc, char* argv[]) printf("Usage: %s PORT\n", argv[0]); return 2; } - printf("starting server...\n"); port=atoi(argv[1]); + printf("Initializing server on port %u...\n", port); signal(SIGINT, &serv_cleanup); int sock=make_server_socket(port); server_socket=sock; @@ -98,19 +104,19 @@ int main(int argc, char* argv[]) struct sockaddr_in client; if(listen(sock, 1)<0) { - printf("error listening.\n"); + printf("Error opening socket.\n"); return 1; } FD_ZERO(&active_fd_set); FD_SET(sock, &active_fd_set); - printf("listening on port %d\n", port); + printf("Server ready, listening on port %d.\n", port); while(1) { read_fd_set=active_fd_set; int ret=select(FD_SETSIZE, &read_fd_set, 0,0,0); if(ret<0) { - printf("select() returned error.\n"); + printf("Error in select().\n"); return 1; } for(int i=0;i