diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/Makefile.am freeciv/common/Makefile.am --- FreecivCVS/common/Makefile.am Wed May 24 15:13:00 2000 +++ freeciv/common/Makefile.am Fri Jun 23 16:08:11 2000 @@ -39,6 +39,8 @@ map.h \ nation.c \ nation.h \ + netintf.c \ + netintf.h \ packets.c \ packets.h \ player.c \ diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/netintf.c freeciv/common/netintf.c --- FreecivCVS/common/netintf.c Wed Dec 31 19:00:00 1969 +++ freeciv/common/netintf.c Fri Jun 23 16:22:28 2000 @@ -0,0 +1,66 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + 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. +***********************************************************************/ + +/********************************************************************** + Common network interface. +**********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + +#include "log.h" +#include "support.h" + +#include "netintf.h" + +/*************************************************************** +... +***************************************************************/ +void my_nonblock(int sockfd) +{ +#ifdef NONBLOCKING_SOCKETS +#ifdef HAVE_FCNTL + int f_set; + + if ((f_set=fcntl(sockfd, F_GETFL)) == -1) { + freelog(LOG_NORMAL, "fcntl F_GETFL failed: %s", mystrerror(errno)); + } + + f_set |= O_NONBLOCK; + + if (fcntl(sockfd, F_SETFL, f_set) == -1) { + freelog(LOG_NORMAL, "fcntl F_SETFL failed: %s", mystrerror(errno)); + } +#else +#ifdef HAVE_IOCTL + long value=1; + + if (ioctl(sockfd, FIONBIO, (char*)&value) == -1) { + freelog(LOG_NORMAL, "ioctl failed: %s", mystrerror(errno)); + } +#endif +#endif +#else + freelog(LOG_DEBUG, "NONBLOCKING_SOCKETS not available"); +#endif +} diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/netintf.h freeciv/common/netintf.h --- FreecivCVS/common/netintf.h Wed Dec 31 19:00:00 1969 +++ freeciv/common/netintf.h Fri Jun 23 16:08:11 2000 @@ -0,0 +1,46 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + 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. +***********************************************************************/ + +#ifndef FC__NETINTF_H +#define FC__NETINTF_H + +/********************************************************************** + Common network interface. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif + +#ifdef FD_ZERO +#define MY_FD_ZERO FD_ZERO +#else +#define MY_FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p))) +#endif + +void my_nonblock(int sockfd); + +#endif /* FC__NETINTF_H */ diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/packets.c freeciv/common/packets.c --- FreecivCVS/common/packets.c Sat Jun 17 10:21:04 2000 +++ freeciv/common/packets.c Fri Jun 23 16:08:11 2000 @@ -44,6 +44,7 @@ #include "capability.h" #include "log.h" #include "mem.h" +#include "netintf.h" #include "support.h" #include "packets.h" @@ -3531,8 +3532,8 @@ fd_set writefs, exceptfs; struct timeval tv; - FD_ZERO(&writefs); - FD_ZERO(&exceptfs); + MY_FD_ZERO(&writefs); + MY_FD_ZERO(&exceptfs); FD_SET(pc->sock, &writefs); FD_SET(pc->sock, &exceptfs); diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/support.c freeciv/common/support.c --- FreecivCVS/common/support.c Wed Jun 21 18:48:39 2000 +++ freeciv/common/support.c Fri Jun 23 16:08:11 2000 @@ -421,34 +421,3 @@ va_end(ap); return ret; } - - -/*************************************************************** -... -***************************************************************/ -void my_nonblock(int sockfd) -{ -#ifdef NONBLOCKING_SOCKETS -#ifdef HAVE_FCNTL - int f_set; - - if ((f_set=fcntl(sockfd, F_GETFL)) == -1) { - fprintf(stderr, "fcntl F_GETFL failed: %s", mystrerror(errno)); - } - - f_set |= O_NONBLOCK; - - if (fcntl(sockfd, F_SETFL, f_set) == -1) { - fprintf(stderr, "fcntl F_SETFL failed: %s", mystrerror(errno)); - } -#else -#ifdef HAVE_IOCTL - long value=1; - - if (ioctl(sockfd, FIONBIO, (char*)&value) == -1) { - freelog(stderr, "ioctl failed: %s", mystrerror(errno)); - } -#endif -#endif -#endif -} diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/common/support.h freeciv/common/support.h --- FreecivCVS/common/support.h Wed Jun 21 18:48:40 2000 +++ freeciv/common/support.h Fri Jun 23 16:08:11 2000 @@ -17,7 +17,7 @@ /********************************************************************** Replacements for functions which are not available on all platforms. Where the functions are available natively, these are just wrappers. - See also mem.h, rand.h, and see support.c for more comments. + See also mem.h, netintf.h, rand.h, and see support.c for more comments. ***********************************************************************/ #include /* size_t */ @@ -46,11 +46,5 @@ fc__attribute((format (printf, 3, 4))); int my_vsnprintf(char *str, size_t n, const char *format, va_list ap ); - -#ifndef FD_ZERO -#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p))) -#endif - -void my_nonblock(int sockfd); #endif /* FC__SUPPORT_H */ diff -ruN -X /home/jjm/cvs/no.freeciv FreecivCVS/server/sernet.c freeciv/server/sernet.c --- FreecivCVS/server/sernet.c Wed Jun 21 18:48:39 2000 +++ freeciv/server/sernet.c Fri Jun 23 16:08:11 2000 @@ -58,6 +58,7 @@ #endif #include "log.h" +#include "netintf.h" #include "packets.h" #include "shared.h" #include "support.h" @@ -149,8 +150,8 @@ tv.tv_sec=1; tv.tv_usec=0; - FD_ZERO(&readfs); - FD_ZERO(&exceptfs); + MY_FD_ZERO(&readfs); + MY_FD_ZERO(&exceptfs); #ifndef SOCKET_ZERO_ISNT_STDIN FD_SET(0, &readfs); #endif