From 1a592767c6e34bdeb7f30fa063b5e24c57d45894 Mon Sep 17 00:00:00 2001 From: oroborus Date: Sat, 2 Aug 2008 14:12:48 +0000 Subject: - gameserver podporuje clientov z IPv4-UDP IPv4-TCP IPv6-UDP IPv6-TCP - client sa moze pripojit na gameserver, ktory podporuje IPv4-UDP IPv4-TCP IPv6-UDP IPv6-TCP ( nie, nie je to samozrejmost :) ) - client ma parametre --tcp , --udp ( ak sa neuvedie, implicitne sa berie --udp ) - btw. ladit, ladit, ladit git-svn-id: http://opensvn.csie.org/tuxanci_ng@187 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/base/serverSelect.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/base/serverSelect.c (limited to 'src/base/serverSelect.c') diff --git a/src/base/serverSelect.c b/src/base/serverSelect.c new file mode 100644 index 0000000..99505d5 --- /dev/null +++ b/src/base/serverSelect.c @@ -0,0 +1,90 @@ + +#include +#include +#include + +#include + +#include +#include +#include + +#ifndef __WIN32__ +#include +#include +#include +#else +#include +#include +#endif + +#include "server.h" + +static struct timeval tv; +static fd_set readfds; +static int max_fd; + +void restartSelect() +{ +#ifndef PUBLIC_SERVER + tv.tv_sec = 0; + tv.tv_usec = 0; +#endif + +#ifdef PUBLIC_SERVER + tv.tv_sec = 0; + tv.tv_usec = 1000; +#endif + + FD_ZERO(&readfds); + max_fd = 0; +} + +void addSockToSelect(int sock) +{ + //printf("addSockToSelect %d\n", sock); + + FD_SET(sock, &readfds); + + if(sock > max_fd ) + { + max_fd = sock; + } +} + +int actionSelect() +{ + int ret; + +#ifdef PUBLIC_SERVER + list_t *listClient; + listClient = getListServerClient(); + + if( listClient->count == 0 ) + { + ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, NULL); + setServerTimer(); + } + else + { + ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv); + } +#endif + +#ifndef PUBLIC_SERVER + ret = select(max_fd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, &tv); +#endif + + return ret; +} + +int isChangeSockInSelect(int sock) +{ + int ret; + + ret = FD_ISSET(sock, &readfds); + + //printf("isChangeSockInSelect %d -> %d\n", sock, ret); + + return ret; +} -- cgit v1.2.3