--- deliantra/server/socket/init.C 2006/12/11 19:46:47 1.10 +++ deliantra/server/socket/init.C 2006/12/13 02:55:51 1.11 @@ -34,9 +34,7 @@ #include -#ifndef __CEXTRACT__ -# include -#endif +#include #include #include #include @@ -61,7 +59,7 @@ * client. */ void -InitConnection (NewSocket * ns, const char *from_ip) +InitConnection (NewSocket *ns, const char *from_ip) { SockList sl; char buf[256]; @@ -70,22 +68,15 @@ int buflen = sizeof (int); if (fcntl (ns->fd, F_SETFL, O_NONBLOCK) == -1) - { - LOG (llevError, "InitConnection: Error on fcntl.\n"); - } + LOG (llevError, "InitConnection: Error on fcntl.\n"); if (getsockopt (ns->fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen) == -1) oldbufsize = 0; + if (oldbufsize < bufsize) - { -#ifdef ESRV_DEBUG - LOG (llevDebug, "Default buffer size was %d bytes, will reset it to %d\n", oldbufsize, bufsize); -#endif - if (setsockopt (ns->fd, SOL_SOCKET, SO_SNDBUF, (char *) &bufsize, sizeof (&bufsize))) - { - LOG (llevError, "InitConnection: setsockopt unable to set output buf size to %d\n", bufsize); - } - } + if (setsockopt (ns->fd, SOL_SOCKET, SO_SNDBUF, (char *) &bufsize, sizeof (&bufsize))) + LOG (llevError, "InitConnection: setsockopt unable to set output buf size to %d\n", bufsize); + buflen = sizeof (oldbufsize); getsockopt (ns->fd, SOL_SOCKET, SO_SNDBUF, (char *) &oldbufsize, (socklen_t *) & buflen); #ifdef ESRV_DEBUG @@ -172,15 +163,7 @@ struct protoent *protox; struct linger linger_opt; -#ifdef HAVE_SYSCONF socket_info.max_filedescriptor = sysconf (_SC_OPEN_MAX); -#else -# ifdef HAVE_GETDTABLESIZE - socket_info.max_filedescriptor = getdtablesize (); -# else - "Unable to find usable function to get max filedescriptors"; -# endif -#endif socket_info.timeout.tv_sec = 0; socket_info.timeout.tv_usec = 0; @@ -205,12 +188,14 @@ LOG (llevError, "init_ericserver: Error getting protox\n"); return; } + init_sockets[0].fd = socket (PF_INET, SOCK_STREAM, protox->p_proto); if (init_sockets[0].fd == -1) { LOG (llevError, "Cannot create socket: %s\n", strerror (errno)); exit (-1); } + insock.sin_family = AF_INET; insock.sin_port = htons (settings.csport); insock.sin_addr.s_addr = htonl (INADDR_ANY); @@ -218,33 +203,14 @@ linger_opt.l_onoff = 0; linger_opt.l_linger = 0; if (setsockopt (init_sockets[0].fd, SOL_SOCKET, SO_LINGER, (char *) &linger_opt, sizeof (struct linger))) - { - LOG (llevError, "Cannot setsockopt(SO_LINGER): %s\n", strerror (errno)); - } + LOG (llevError, "Cannot setsockopt(SO_LINGER): %s\n", strerror (errno)); -/* Would be nice to have an autoconf check for this. It appears that - * these functions are both using the same calling syntax, just one - * of them needs extra valus passed. - */ -#if defined(__osf__) || defined(hpux) || defined(sgi) || defined(NeXT) || \ - defined(__sun__) || defined(__linux__) || defined(SVR4) || \ - defined(__FreeBSD__) || defined(__OpenBSD__) || \ - defined(WIN32) /* ---win32 add this here */ || \ - defined(__GNU__) /* HURD */ { int tmp = 1; if (setsockopt (init_sockets[0].fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof (tmp))) - { - LOG (llevError, "Cannot setsockopt(SO_REUSEADDR): %s\n", strerror (errno)); - } - } -#else - if (setsockopt (init_sockets[0].fd, SOL_SOCKET, SO_REUSEADDR, (char *) NULL, 0)) - { LOG (llevError, "Cannot setsockopt(SO_REUSEADDR): %s\n", strerror (errno)); - } -#endif + } if (bind (init_sockets[0].fd, (struct sockaddr *) &insock, sizeof (insock)) == (-1)) { @@ -252,12 +218,14 @@ close (init_sockets[0].fd); exit (-1); } + if (listen (init_sockets[0].fd, 5) == (-1)) { LOG (llevError, "Cannot listen on socket: %s\n", strerror (errno)); close (init_sockets[0].fd); exit (-1); } + init_sockets[0].status = Ns_Add; read_client_images (); } @@ -286,15 +254,9 @@ */ void -free_newsocket (NewSocket * ns) +free_newsocket (NewSocket *ns) { - if (close (ns->fd)) - { - -#ifdef ESRV_DEBUG - LOG (llevDebug, "Error closing socket %d\n", ns->fd); -#endif - } + close (ns->fd); if (ns->stats.range) free (ns->stats.range);