diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-08-02 14:12:48 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-08-02 14:12:48 +0000 |
| commit | 1a592767c6e34bdeb7f30fa063b5e24c57d45894 (patch) | |
| tree | e21ebcc5bc79cc5b6a6dfb4b9635ff95c52842c4 /src/base/serverSelect.c | |
| parent | 6b805af42cba72e190d94ffa6d1dd7e44d9dfb61 (diff) | |
- 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
Diffstat (limited to 'src/base/serverSelect.c')
| -rw-r--r-- | src/base/serverSelect.c | 90 |
1 files changed, 90 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sys/types.h> + +#include <unistd.h> +#include <fcntl.h> +#include <sys/time.h> + +#ifndef __WIN32__ +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/select.h> +#else +#include <io.h> +#include <winsock2.h> +#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; +} |