summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-02 14:12:48 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-02 14:12:48 +0000
commit1a592767c6e34bdeb7f30fa063b5e24c57d45894 (patch)
treee21ebcc5bc79cc5b6a6dfb4b9635ff95c52842c4 /src/base
parent6b805af42cba72e190d94ffa6d1dd7e44d9dfb61 (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')
-rw-r--r--src/base/main.c4
-rw-r--r--src/base/net_multiplayer.c38
-rw-r--r--src/base/net_multiplayer.h2
-rw-r--r--src/base/server.c113
-rw-r--r--src/base/server.h2
-rw-r--r--src/base/serverSelect.c90
-rw-r--r--src/base/serverSelect.h11
-rw-r--r--src/base/tcp_server.c165
-rw-r--r--src/base/tcp_server.h5
-rw-r--r--src/base/udp_server.c166
-rw-r--r--src/base/udp_server.h5
11 files changed, 320 insertions, 281 deletions
diff --git a/src/base/main.c b/src/base/main.c
index 46f68ad..6221dd8 100644
--- a/src/base/main.c
+++ b/src/base/main.c
@@ -123,6 +123,10 @@ int WINAPI WinMain(
int main(int argc, char *argv[])
#endif
{
+#ifndef __WIN32__
+ signal(SIGPIPE, SIG_IGN);
+#endif
+
srand( (unsigned) time(NULL) );
#ifndef __WIN32__
diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c
index f85d287..d0732d7 100644
--- a/src/base/net_multiplayer.c
+++ b/src/base/net_multiplayer.c
@@ -31,14 +31,19 @@ int getNetTypeGame()
return netGameType;
}
-#ifdef OLD_PUBLIC_SERVER
-
-int initNetMulitplayerPublicServer(char *ip4, int port4, char *ip6, int port6)
+int initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6)
{
- netGameType = NET_GAME_TYPE_SERVER;
- return initUdpPublicServer(ip4, port4, ip6, port6);
+ int ret;
+
+ ret = initServer(ip4, port4, ip6, port6);
+
+ if( ret > 0 )
+ {
+ netGameType = NET_GAME_TYPE_SERVER;
+ }
+
+ return ret;
}
-#endif
int initNetMuliplayer(int type, char *ip, int port, int proto)
{
@@ -50,11 +55,24 @@ int initNetMuliplayer(int type, char *ip, int port, int proto)
break;
case NET_GAME_TYPE_SERVER :
- if( initServer(ip, port, proto) != 0 )
+ switch( proto )
{
- fprintf(stderr, "Unable to inicialize network game as server!\n");
- netGameType = NET_GAME_TYPE_NONE;
- return -1;
+ case PROTO_UDPv4 :
+ if( initServer(ip, port, NULL, 0) != 1 )
+ {
+ fprintf(stderr, "Unable to inicialize network game as server!\n");
+ netGameType = NET_GAME_TYPE_NONE;
+ return -1;
+ }
+ break;
+ case PROTO_UDPv6 :
+ if( initServer(NULL, 0, ip, port) != 1 )
+ {
+ fprintf(stderr, "Unable to inicialize network game as server!\n");
+ netGameType = NET_GAME_TYPE_NONE;
+ return -1;
+ }
+ break;
}
break;
diff --git a/src/base/net_multiplayer.h b/src/base/net_multiplayer.h
index 3137385..b7676c5 100644
--- a/src/base/net_multiplayer.h
+++ b/src/base/net_multiplayer.h
@@ -28,7 +28,7 @@
#define NET_MASTER_PORT 2200
#ifdef PUBLIC_SERVER
-extern int initNetMulitplayerPublicServer(char *ip4, int port4, char *ip6, int port6);
+extern int initNetMuliplayerForGameServer(char *ip4, int port4, char *ip6, int port6);
#endif
extern int initNetMuliplayer(int type, char *ip, int port, int proto);
diff --git a/src/base/server.c b/src/base/server.c
index b598810..fe01b5f 100644
--- a/src/base/server.c
+++ b/src/base/server.c
@@ -30,6 +30,7 @@
#include "checkFront.h"
#include "protect.h"
#include "index.h"
+#include "serverSelect.h"
#ifndef PUBLIC_SERVER
#include "screen_world.h"
@@ -40,14 +41,26 @@
#include "heightScore.h"
#endif
-#define SUPPORT_UDP
-
static list_t *listClient;
static list_t *listServerTimer;
static time_t timeUpdate;
static int maxClients;
+/*
+ TRAFFIC
+
+ za 5 sekund :
+
+ up : COUNT_PLAYERS * ( COUNT_PLAYERS - 1 ) * 1KB
+ down : COUNT_PLAYERS * 0.2KB
+
+ za 1 sekund :
+
+ up : COUNT_PLAYERS * ( COUNT_PLAYERS - 1 ) * 1/5 KB
+ down : COUNT_PLAYERS * 1/25 KB
+*/
+
typedef struct proto_cmd_server_struct
{
char *name;
@@ -147,21 +160,15 @@ void destroyAnyClient(client_t *p)
free(p);
}
-static void eventDelClient(client_t *client)
+static void destroyUdpOrTcpClient(client_t *client)
{
- int offset;
-
- offset = searchListItem(listClient, client);
-
- assert( offset != -1 );
-
switch( client->type )
{
case CLIENT_TYPE_UDP :
- delListItem(listClient, offset, destroyUdpClient);
+ destroyUdpClient(client);
break;
case CLIENT_TYPE_TCP :
- delListItem(listClient, offset, destroyTcpClient);
+ destroyTcpClient(client);
break;
default :
assert( ! "zly typ !");
@@ -169,6 +176,17 @@ static void eventDelClient(client_t *client)
}
}
+static void eventDelClientFromListClient(client_t *client)
+{
+ int offset;
+
+ offset = searchListItem(listClient, client);
+
+ assert( offset != -1 );
+
+ delListItem(listClient, offset, destroyUdpOrTcpClient);
+}
+
static void delZombieCLient(void *p_nothink)
{
client_t *thisClient;
@@ -195,7 +213,7 @@ static void delZombieCLient(void *p_nothink)
proto_send_del_server(PROTO_SEND_ALL, NULL, thisClient->tux->id);
}
- eventDelClient(thisClient);
+ eventDelClientFromListClient(thisClient);
i--;
}
}
@@ -208,7 +226,7 @@ static void eventPeriodicSyncClient(void *p_nothink)
int i;
#ifndef PUBLIC_SERVER
- proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT));
+ proto_send_newtux_server(PROTO_SEND_ALL_SEES_TUX, NULL, getControlTux(TUX_CONTROL_KEYBOARD_RIGHT));
#endif
for( i = 0 ; i < listClient->count; i++ )
@@ -246,7 +264,7 @@ void setServerTimer()
addTaskToTimer(listServerTimer, TIMER_PERIODIC, eventSendPingClients, NULL, SERVER_TIME_PING);
}
-int initServer(char *ip, int port, int proto)
+int initServer(char *ip4, int port4, char *ip6, int port6)
{
int ret;
@@ -258,13 +276,20 @@ int initServer(char *ip, int port, int proto)
setServerMaxClients(SERVER_MAX_CLIENTS);
setServerTimer();
-#ifdef SUPPORT_UDP
- ret = initUdpServer(ip, port, proto);
-#endif
+ ret = initUdpServer(ip4, port4, ip6, port6);
+
+ if( ret == 0 )
+ {
+ return -1;
+ }
+
+ ret = initTcpServer(ip4, port4, ip6, port6);
+
+ if( ret == 0 )
+ {
+ return -1;
+ }
-#ifdef SUPPORT_TCP
- ret = initTcpServer(ip, port, proto);
-#endif
return ret;
}
@@ -532,12 +557,39 @@ static void eventClientListBuffer()
void eventServer()
{
-#ifdef SUPPORT_UDP
- eventUdpServer();
+#ifndef PUBLIC_SERVER
+ int count;
+
+ do{
+ restartSelect();
+ setServerTcpSelect();
+ actionSelect();
+ count = selectServerTcpSocket();
+ }while( count > 0 );
+
+ do{
+ restartSelect();
+ setServerUdpSelect();
+ actionSelect();
+ count = selectServerUdpSocket();
+ }while( count > 0 );
#endif
-#ifdef SUPPORT_TCP
- eventTcpServer();
+#ifdef PUBLIC_SERVER
+ int ret;
+
+ restartSelect();
+
+ setServerTcpSelect();
+ setServerUdpSelect();
+
+ ret = actionSelect();
+
+ if( ret > 0 )
+ {
+ selectServerTcpSocket();
+ selectServerUdpSocket();
+ }
#endif
eventClientListBuffer();
@@ -550,21 +602,10 @@ void quitServer()
assert( listClient != NULL );
-#ifdef SUPPORT_UDP
- destroyListItem(listClient, destroyUdpClient);
-#endif
-
-#ifdef SUPPORT_TCP
- destroyListItem(listClient, destroyTcpClient);
-#endif
+ destroyListItem(listClient, destroyUdpOrTcpClient);
destroyTimer(listServerTimer);
-#ifdef SUPPORT_UDP
quitUdpServer();
-#endif
-
-#ifdef SUPPORT_TCP
quitTcpServer();
-#endif
}
diff --git a/src/base/server.h b/src/base/server.h
index 61d9333..0e5ed6b 100644
--- a/src/base/server.h
+++ b/src/base/server.h
@@ -47,7 +47,7 @@ typedef struct client_struct
list_t *listSeesShot;
} client_t;
-extern int initServer(char *ip, int port, int proto);
+extern int initServer(char *ip4, int port4, char *ip6, int port6);
extern time_t getUpdateServer();
extern client_t* newAnyClient();
extern void destroyAnyClient(client_t *p);
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;
+}
diff --git a/src/base/serverSelect.h b/src/base/serverSelect.h
new file mode 100644
index 0000000..332a4da
--- /dev/null
+++ b/src/base/serverSelect.h
@@ -0,0 +1,11 @@
+
+#ifndef SERVER_SELECT
+
+#define SERVER_SELECT
+
+extern void restartSelect();
+extern void addSockToSelect(int sock);
+extern int actionSelect();
+extern int isChangeSockInSelect(int sock);
+
+#endif
diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c
index 77d8592..b201235 100644
--- a/src/base/tcp_server.c
+++ b/src/base/tcp_server.c
@@ -40,6 +40,7 @@
#include "tcp.h"
#include "tcp_server.h"
+#include "serverSelect.h"
static sock_tcp_t *sock_server_tcp;
static sock_tcp_t *sock_server_tcp_second;
@@ -69,7 +70,7 @@ void destroyTcpClient(client_t *p)
eventMsgInCheckFront(p);
getSockTcpIp(p->socket_tcp, str_ip, STR_IP_SIZE);
- printf("closeTCP connect %s %d\n", str_ip, getSockTcpPort(p->socket_tcp) );
+ printf("close TCP connect %s %d\n", str_ip, getSockTcpPort(p->socket_tcp) );
closeTcpSocket(p->socket_tcp);
destroyBuffer(p->buffer);
@@ -77,20 +78,45 @@ void destroyTcpClient(client_t *p)
destroyAnyClient(p);
}
-int initTcpServer(char *ip, int port, int proto)
+int initTcpServer(char *ip4, int port4, char *ip6, int port6)
{
- sock_server_tcp = bindTcpSocket(ip, port, proto);
- sock_server_tcp_second = NULL;
+ int ret;
+
+ ret = 0;
- if( sock_server_tcp == NULL )
+ if( ip4 != NULL )
{
- return -1;
+ sock_server_tcp = bindTcpSocket(ip4, port4, PROTO_UDPv4);
+
+ if( sock_server_tcp != NULL )
+ {
+ ret++;
+ disableNagle(sock_server_tcp);
+ printf("server listen TCP port %s %d\n", ip4, port4);
+ }
+ else
+ {
+ printf("server listen TCP port %s %d -- failed !!!\n", ip4, port4);
+ }
}
- disableNagle(sock_server_tcp);
- printf("server listen TCP port %s %d\n", ip, port);
+ if( ip6 != NULL )
+ {
+ sock_server_tcp_second = bindTcpSocket(ip6, port6, PROTO_UDPv6);
- return 0;
+ if( sock_server_tcp_second != NULL )
+ {
+ ret++;
+ disableNagle(sock_server_tcp_second);
+ printf("server listen TCP port %s %d\n", ip6, port6);
+ }
+ else
+ {
+ printf("server listen TCP port %s %d -- failed !!!\n", ip6, port6);
+ }
+ }
+
+ return ret;
}
static void eventNewClient(sock_tcp_t *server_sock)
@@ -129,44 +155,21 @@ static void eventTcpClient(client_t *client)
}
}
-static int selectServerTcpSocket()
+void setServerTcpSelect()
{
list_t *listClient;
- struct timeval tv;
- fd_set readfds;
- fd_set errorfds;
- int max_fd;
- int ret;
- int count;
int i;
listClient = getListServerClient();
-#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);
- FD_ZERO(&errorfds);
-
- max_fd = 0;
- count = 0;
-
if( sock_server_tcp != NULL )
{
- FD_SET(sock_server_tcp->sock, &errorfds);
- FD_SET(sock_server_tcp->sock, &readfds);
+ addSockToSelect(sock_server_tcp->sock);
+ }
- if( sock_server_tcp->sock > max_fd )
- {
- max_fd = sock_server_tcp->sock;
- }
+ if( sock_server_tcp_second != NULL )
+ {
+ addSockToSelect(sock_server_tcp_second->sock);
}
for( i = 0 ; i < listClient->count ; i++ )
@@ -175,99 +178,65 @@ static int selectServerTcpSocket()
client = (client_t *)listClient->list[i];
- if( client->status != NET_STATUS_OK )
+ if( client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP )
{
continue;
}
- FD_SET(client->socket_tcp->sock, &errorfds);
- FD_SET(client->socket_tcp->sock, &readfds);
-
- if( client->socket_tcp->sock > max_fd )
- {
- max_fd = client->socket_tcp->sock;
- }
+ addSockToSelect(client->socket_tcp->sock);
}
+}
+int selectServerTcpSocket()
+{
+ list_t *listClient;
+ int count;
+ int i;
-#ifdef PUBLIC_SERVER
- if( listClient->count == 0 )
- {
- ret = select(max_fd+1, &readfds, (fd_set *)NULL, &errorfds, NULL);
- setServerTimer();
- }
- else
- {
- ret = select(max_fd+1, &readfds, (fd_set *)NULL,&errorfds, &tv);
- }
-#endif
-
-#ifndef PUBLIC_SERVER
- ret = select(max_fd+1, &readfds, (fd_set *)NULL,&errorfds, &tv);
-#endif
+ count = 0;
- if( ret < 0 )
- {
- //printf("select ret = %d\n", ret);
- return 0;
- }
-
if( sock_server_tcp != NULL )
{
- if( FD_ISSET(sock_server_tcp->sock, &readfds) )
+ if( isChangeSockInSelect(sock_server_tcp->sock) )
{
eventNewClient(sock_server_tcp);
- count = 1;
+ count++;
}
-
- if( FD_ISSET(sock_server_tcp->sock, &errorfds) )
+ }
+
+ if( sock_server_tcp_second != NULL )
+ {
+ if( isChangeSockInSelect(sock_server_tcp_second->sock) )
{
- printf("error\n");
+ eventNewClient(sock_server_tcp_second);
+ count++;
}
}
+ listClient = getListServerClient();
+
for( i = 0 ; i < listClient->count ; i++ )
{
client_t *client;
client = (client_t *)listClient->list[i];
- if( FD_ISSET(client->socket_tcp->sock, &readfds) )
+ if( client->status != NET_STATUS_OK || client->type != CLIENT_TYPE_TCP )
{
- //printf("eventTcpClient(client);\n");
- eventTcpClient(client);
- count = 1;
+ continue;
}
- if( FD_ISSET(client->socket_tcp->sock, &errorfds) )
+ if( isChangeSockInSelect(client->socket_tcp->sock) )
{
- //printf("error client\n");
- count = 1;
+ //printf("eventTcpClient(client);\n");
+ eventTcpClient(client);
+ count++;
}
}
return count;
}
-void eventTcpServer()
-{
-#ifndef PUBLIC_SERVER
-
- int count;
-
-#ifdef SUPPORT_NET_UNIX_UDP
- do{
- count = selectServerTcpSocket();
- }while( count > 0 );
-#endif
-
-#endif
-
-#ifdef PUBLIC_SERVER
- selectServerTcpSocket();
-#endif
-}
-
void quitTcpServer()
{
if( sock_server_tcp != NULL )
diff --git a/src/base/tcp_server.h b/src/base/tcp_server.h
index d4dee0a..6cae061 100644
--- a/src/base/tcp_server.h
+++ b/src/base/tcp_server.h
@@ -8,8 +8,9 @@
extern client_t* newTcpClient(sock_tcp_t *sock_tcp);
extern void destroyTcpClient(client_t *p);
-extern int initTcpServer(char *ip, int port, int proto);
-extern void eventTcpServer();
+extern int initTcpServer(char *ip4, int port4, char *ip6, int port6);
+extern void setServerTcpSelect();
+extern int selectServerTcpSocket();
extern void quitTcpServer();
#endif
diff --git a/src/base/udp_server.c b/src/base/udp_server.c
index cb0aaba..63a24ea 100644
--- a/src/base/udp_server.c
+++ b/src/base/udp_server.c
@@ -40,6 +40,7 @@
#include "udp.h"
#include "udp_server.h"
+#include "serverSelect.h"
static sock_udp_t *sock_server_udp;
static sock_udp_t *sock_server_udp_second;
@@ -75,59 +76,45 @@ void destroyUdpClient(client_t *p)
destroyAnyClient(p);
}
-int initUdpServer(char *ip, int port, int proto)
+int initUdpServer(char *ip4, int port4, char *ip6, int port6)
{
- sock_server_udp = bindUdpSocket(ip, port, proto);
- sock_server_udp_second = NULL;
-
- if( sock_server_udp == NULL )
- {
- return -1;
- }
-
- printf("server listen UDP port %s %d\n", ip, port);
-
- return 0;
-}
+ int ret;
-#ifdef OLD_PUBLIC_SERVER
-
-int initUdpPublicServer(char *ip4, int port4, char *ip6, int port6)
-{
- sock_server_udp = NULL;
- sock_server_udp_second = NULL;
+ ret = 0;
if( ip4 != NULL )
{
sock_server_udp = bindUdpSocket(ip4, port4, PROTO_UDPv4);
-
- if( sock_server_udp == NULL )
+
+ if( sock_server_udp != NULL )
{
- return -1;
+ ret++;
+ printf("server listen UDP port %s %d\n", ip4, port4);
+ }
+ else
+ {
+ printf("server listen UDP port %s %d -- failed !!!\n", ip4, port4);
}
-
- printf("server listen UDP port %s %d\n", ip4, port4);
}
if( ip6 != NULL )
{
sock_server_udp_second = bindUdpSocket(ip6, port6, PROTO_UDPv6);
-
- if( sock_server_udp_second == NULL )
+
+ if( sock_server_udp_second != NULL )
{
- return -1;
+ ret++;
+ printf("server listen UDP port %s %d\n", ip6, port6);
+ }
+ else
+ {
+ printf("server listen UDP port %s %d -- failed !!!\n", ip6, port6);
}
-
- printf("server listen UDP port %s %d\n", ip6, port6);
}
- initServer();
-
- return 0;
+ return ret;
}
-#endif
-
static void eventCreateNewUdpClient(sock_udp_t *socket_udp)
{
list_t *listClient;
@@ -156,7 +143,8 @@ static client_t* findUdpClient(sock_udp_t *sock_udp)
client = (client_t *)listClient->list[i];
- if( getSockUdpPort(client->socket_udp) == port )
+ if( client->type == CLIENT_TYPE_UDP &&
+ getSockUdpPort(client->socket_udp) == port )
{
return client;
}
@@ -218,130 +206,46 @@ static void eventClientUdpSelect(sock_udp_t *sock_server)
addList(client->listRecvMsg, strdup(listRecvMsg) );
}
-static int selectServerUdpSocket()
+void setServerUdpSelect()
{
- struct timeval tv;
- fd_set readfds;
- fd_set errorfds;
- int max_fd;
- int ret;
- int count;
-
-#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);
- FD_ZERO(&errorfds);
-
- max_fd = 0;
- count = 0;
-
if( sock_server_udp != NULL )
{
- FD_SET(sock_server_udp->sock, &errorfds);
- FD_SET(sock_server_udp->sock, &readfds);
-
- if( sock_server_udp->sock > max_fd )
- {
- max_fd = sock_server_udp->sock;
- }
+ addSockToSelect(sock_server_udp->sock);
}
if( sock_server_udp_second != NULL )
{
- FD_SET(sock_server_udp_second->sock, &readfds);
- FD_SET(sock_server_udp_second->sock, &errorfds);
-
- if( sock_server_udp_second->sock > max_fd )
- {
- max_fd = sock_server_udp_second->sock;
- }
+ addSockToSelect(sock_server_udp_second->sock);
}
+}
- //printf("select..\n");
-
-#ifdef PUBLIC_SERVER
- list_t *listClient;
- listClient = getListServerClient();
-
- if( listClient->count == 0 )
- {
- ret = select(max_fd+1, &readfds, (fd_set *)NULL, &errorfds, NULL);
- setServerTimer();
- }
- else
- {
- ret = select(max_fd+1, &readfds, (fd_set *)NULL,&errorfds, &tv);
- }
-#endif
+int selectServerUdpSocket()
+{
+ int count;
-#ifndef PUBLIC_SERVER
- ret = select(max_fd+1, &readfds, (fd_set *)NULL,&errorfds, &tv);
-#endif
+ count = 0;
- if( ret < 0 )
- {
- //printf("select ret = %d\n", ret);
- return 0;
- }
-
if( sock_server_udp != NULL )
{
- if( FD_ISSET(sock_server_udp->sock, &readfds) )
+ if( isChangeSockInSelect(sock_server_udp->sock) )
{
eventClientUdpSelect(sock_server_udp);
- count = 1;
- }
-
- if( FD_ISSET(sock_server_udp->sock, &errorfds) )
- {
- printf("error\n");
+ count++;
}
}
if( sock_server_udp_second != NULL )
{
- if( FD_ISSET(sock_server_udp_second->sock, &readfds) )
+ if( isChangeSockInSelect(sock_server_udp_second->sock) )
{
eventClientUdpSelect(sock_server_udp_second);
- count = 1;
- }
-
- if( FD_ISSET(sock_server_udp_second->sock, &errorfds) )
- {
- printf("error\n");
+ count++;
}
}
return count;
}
-void eventUdpServer()
-{
-#ifndef PUBLIC_SERVER
-
- int count;
-
-#ifdef SUPPORT_NET_UNIX_UDP
- do{
- count = selectServerUdpSocket();
- }while( count > 0 );
-#endif
-
-#endif
-
-#ifdef PUBLIC_SERVER
- selectServerUdpSocket();
-#endif
-}
-
void quitUdpServer()
{
if( sock_server_udp != NULL )
diff --git a/src/base/udp_server.h b/src/base/udp_server.h
index 58bb018..576e63d 100644
--- a/src/base/udp_server.h
+++ b/src/base/udp_server.h
@@ -8,8 +8,9 @@
extern client_t* newUdpClient(sock_udp_t *sock_udp);
extern void destroyUdpClient(client_t *p);
-extern int initUdpServer(char *ip, int port, int proto);
-extern void eventUdpServer();
+extern int initUdpServer(char *ip4, int port4, char *ip6, int port6);
+extern void setServerUdpSelect();
+extern int selectServerUdpSocket();
extern void quitUdpServer();
#endif