From 05357f9deaa29cf97dda2569e77868df73dfdfc1 Mon Sep 17 00:00:00 2001 From: TimeServ Date: Tue, 14 Mar 2006 02:50:56 +0000 Subject: [PATCH] fix to sv_http logic git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2116 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/http/httpserver.c | 19 +++++++++++++------ engine/http/iwebiface.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/engine/http/httpserver.c b/engine/http/httpserver.c index 1a0ad0672..70faa2db3 100644 --- a/engine/http/httpserver.c +++ b/engine/http/httpserver.c @@ -9,13 +9,14 @@ //FIXME: Before any admins use this for any serious usage, make the server send bits of file slowly. static qboolean httpserverinitied = false; +qboolean httpserverfailed = false; static int httpserversocket; typedef enum {HTTP_WAITINGFORREQUEST,HTTP_SENDING} http_mode_t; -void HTTP_ServerInit(void) +qboolean HTTP_ServerInit(void) { struct sockaddr_in address; unsigned long _true = true; @@ -24,12 +25,16 @@ void HTTP_ServerInit(void) if ((httpserversocket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { - Sys_Error ("HTTP_UDP_OpenSocket: socket:", strerror(qerrno)); + Con_Printf ("HTTP_ServerInit: socket: %s\n", strerror(qerrno)); + httpserverfailed = true; + return false; } if (ioctlsocket (httpserversocket, FIONBIO, &_true) == -1) { - Sys_Error ("HTTP_UDP_OpenSocket: ioctl FIONBIO:", strerror(qerrno)); + Con_Printf ("HTTP_ServerInit: ioctl FIONBIO: %s\n", strerror(qerrno)); + httpserverfailed = true; + return false; } address.sin_family = AF_INET; @@ -51,7 +56,9 @@ void HTTP_ServerInit(void) if( bind (httpserversocket, (void *)&address, sizeof(address)) == -1) { closesocket(httpserversocket); - return; + Con_Printf("HTTP_ServerInit: failed to bind to socket\n"); + httpserverfailed = true; + return false; } listen(httpserversocket, 3); @@ -60,7 +67,7 @@ void HTTP_ServerInit(void) IWebPrintf("HTTP server is running\n"); - return; + return true; } void HTTP_ServerShutdown(void) @@ -481,7 +488,7 @@ qboolean HTTP_ServerPoll(qboolean httpserverwanted) //loop while true if (!httpserverinitied) { if (httpserverwanted) - HTTP_ServerInit(); + return HTTP_ServerInit(); return false; } else if (!httpserverwanted) diff --git a/engine/http/iwebiface.c b/engine/http/iwebiface.c index 7d9fbc804..0fe3bb59e 100644 --- a/engine/http/iwebiface.c +++ b/engine/http/iwebiface.c @@ -68,6 +68,8 @@ int main(int argc, char **argv) { FTP_ServerRun(1); HTTP_ServerPoll(1); + if (httpserverfailed) + Sys_Error("HTTP server failed"); Sleep(1); } } @@ -368,8 +370,16 @@ void IWebInit(void) void IWebRun(void) { #ifdef WEBSERVER + extern qboolean httpserverfailed; + FTP_ServerRun(ftpserver.value!= 0); HTTP_ServerPoll(httpserver.value!=0); + if (httpserverfailed) + { + Con_Printf("HTTP Server failed to load, setting %s to 0\n", httpserver.name); + Cvar_SetValue(&httpserver, 0); + httpserverfailed = false; + } #endif } void IWebShutdown(void)