Esempio n. 1
0
int main( int argc, char** argv )
{
    /*
     *	Initialize the memory allocator. Allow use of malloc and start
     *	with a 60K heap.  For each page request approx 8KB is allocated.
     *	60KB allows for several concurrent page requests.  If more space
     *	is required, malloc will be used for the overflow.
     */
    bopen( NULL, ( 60 * 1024 ), B_USE_MALLOC );
    signal( SIGPIPE, SIG_IGN );

    /*
     *	Initialize the web server
     */
    if ( initWebs() < 0 )
    {
        return -1;
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLOpen();
#endif

    /*
     *	Basic event loop. SocketReady returns true when a socket is ready for
     *	service. SocketSelect will block until an event occurs. SocketProcess
     *	will actually do the servicing.
     */
    while ( !finished )
    {
        if ( socketReady( -1 ) || socketSelect( -1, 1000 ) )
        {
            socketProcess( -1 );
        }

        websCgiCleanup();
        emfSchedProcess();
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLClose();
#endif
#ifdef USER_MANAGEMENT_SUPPORT
    umClose();
#endif
    /*
     *	Close the socket module, report memory leaks and close the memory allocator
     */
    websCloseServer();
    socketClose();
#ifdef B_STATS
    memLeaks();
#endif
    bclose();
    return 0;
}
Esempio n. 2
0
int main(int argc, char** argv)
{
/*
 *	Hook the unload routine in
 */
   signal( SIGTERM, SigTermSignalHandler ) ;

/*
 * Initialize the memory allocator. Allow use of malloc and start 
 * with a 60K heap.  For each page request approx 8KB is allocated.
 * 60KB allows for several concurrent page requests.  If more space
 * is required, malloc will be used for the overflow.
 */
   bopen(NULL, (60 * 1024), B_USE_MALLOC);

   P( 1 ) ;

/*
 *	Switch to LONG name-space. If LONG is not loaded, WEBS will default
 *	to 8.3
 */
   SetCurrentNameSpace( 4 ) ;

/*
 * Initialize the web server
 */
   if (initWebs() < 0) {
      return -1;
   }

#ifdef WEBS_SSL_SUPPORT
   websSSLOpen();
#endif

   P( 20 ) ;

/*
 * Basic event loop. SocketReady returns true when a socket is ready for
 * service. SocketSelect will block until an event occurs. SocketProcess
 * will actually do the servicing.
 */
   while (!finished) {
      if (socketReady(-1) || socketSelect(-1, 1000)) {
         socketProcess(-1);
         ThreadSwitch() ;
      }
      websCgiCleanup();
      emfSchedProcess();
   }

   NLMcleanup() ;

   return 0;
}
Esempio n. 3
0
static void
rtems_httpd_daemon(rtems_task_argument args)
{
/*
 *	Initialize the memory allocator. Allow use of malloc and start with a 
 *	10K heap.
 */
	bopen(NULL, (10 * 1024), B_USE_MALLOC);

/*
 *	Initialize the web server
 */
	if (initWebs() < 0) {
	  rtems_panic("Unable to initialize Web server !!\n");
	}

#ifdef WEBS_SSL_SUPPORT
	websSSLOpen();
#endif

/*
 *	Basic event loop. SocketReady returns true when a socket is ready for
 *	service. SocketSelect will block until an event occurs. SocketProcess
 *	will actually do the servicing.
 */
	while (!finished) {
	  if (socketReady(-1) || socketSelect(-1, 2000)) {
			socketProcess(-1);
	  }
	  /*websCgiCleanup();*/
	  emfSchedProcess();
	}

#ifdef WEBS_SSL_SUPPORT
	websSSLClose();
#endif

#ifdef USER_MANAGEMENT_SUPPORT
	umClose();
#endif

/*
 *	Close the socket module, report memory leaks and close the memory allocator
 */
	websCloseServer();
	websDefaultClose();
	socketClose();
	symSubClose();
#if B_STATS
	memLeaks();
#endif
	bclose();
        rtems_task_delete( RTEMS_SELF );
}
Esempio n. 4
0
/*
    Wait until an event occurs on a socket. Return zero on success, -1 on failure.
 */
PUBLIC int socketWaitForEvent(WebsSocket *sp, int handlerMask)
{
    int mask;

    assert(sp);

    mask = sp->handlerMask;
    sp->handlerMask |= handlerMask;
    while (socketSelect(sp->sid, 1000)) {
        if (sp->currentEvents & (handlerMask | SOCKET_EXCEPTION)) {
            break;
        }
    }
    sp->handlerMask = mask;
    if (sp->currentEvents & SOCKET_EXCEPTION) {
        return -1;
    } else if (sp->currentEvents & handlerMask) {
        return 0;
    }
    return 0;
}
Esempio n. 5
0
int socketReady(int sid)
{
	socket_t 	*sp;
	int			all;

	all = 0;
	if (sid < 0) {
		sid = 0;
		all = 1;
	}

	for (; sid < socketMax; sid++) {
		if ((sp = socketList[sid]) == NULL) {
			if (! all) {
				break;
			} else {
				continue;
			}
		} 
		if (sp->flags & SOCKET_CONNRESET) {
			socketCloseConnection(sid);
			return 0;
		}
		if (sp->currentEvents & sp->handlerMask) {
			return 1;
		}
/*
 *		If there is input data, also call select to test for new events
 */
		if (sp->handlerMask & SOCKET_READABLE && socketInputBuffered(sid) > 0) {
			socketSelect(sid, 0);
			return 1;
		}
		if (! all) {
			break;
		}
	}
	return 0;
}
Esempio n. 6
0
int main(int argc, char** argv)
{
/*
 *	Initialize the memory allocator. Allow use of malloc and start 
 *	with a 60K heap.  For each page request approx 8KB is allocated.
 *	60KB allows for several concurrent page requests.  If more space
 *	is required, malloc will be used for the overflow.
 */
	bopen(NULL, (60 * 1024), B_USE_MALLOC);

/*
 *	Initialize the web server
 */
	if (initWebs() < 0) {
		return -1;
	}

/*
 *	Basic event loop. SocketReady returns true when a socket is ready for
 *	service. SocketSelect will block until an event occurs. SocketProcess
 *	will actually do the servicing.
 */
	while (!finished) {
		if (socketReady(-1) || socketSelect(-1, 2000)) {
			socketProcess(-1);
		}
		emfSchedProcess();
	}

/*
 *	Close the socket module, report memory leaks and close the memory allocator
 */
	websCloseServer();
	socketClose();
	bclose();
	return 0;
}
Esempio n. 7
0
int socketWaitForEvent(socket_t *sp, int handlerMask, int *errCode)
{
	int	mask;

	a_assert(sp);

	mask = sp->handlerMask;
	sp->handlerMask |= handlerMask;
	while (socketSelect(sp->sid, 1000)) {
		if (sp->currentEvents & (handlerMask | SOCKET_EXCEPTION)) {
			break;
		}
	}
	sp->handlerMask = mask;
	if (sp->currentEvents & SOCKET_EXCEPTION) {
		return -1;
	} else if (sp->currentEvents & handlerMask) {
		return 1;
	}
	if (errCode) {
		*errCode = errno = EWOULDBLOCK;
	}
	return 0;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
   int opt, cpid;
   struct sigaction sigact;

   while ((opt = getopt(argc, argv, "c:d:ps:nu:v")) != -1)
   {
      switch (opt)
      {
         case 'c':
            strcpy(confFile, optarg);
            break;

         case 'd':
            Debug = atoi(optarg);
            break;

         case 'p':
            Permiscuous = 1;
            break;

         case 'n':
            NoDetach = 1;
            break;

         case 'u':
            strcpy(PrivilegedUser, optarg);
            break;

         case 'v':
            Verbose = 1;
            break;

         case 's':
            strcpy(ControlPort, optarg);
            break;

         break;
      }
   }



   /*
   ** If they didn't ask us not to, detach from the controlling terminal
   ** and chdir to /etc.
   */
   if (NoDetach == 0)
   {
      openlog("termnetd", LOG_PID | LOG_CONS, LOG_DAEMON);
      if ((cpid = fork()) > 0)
         exit(0);
      else if (cpid < 0)
      {
         syslog(LOG_ERR, "Quiting!! Error Detaching from terminal:%m");
         exit(1);
      }
      else
      {
         chdir("/etc");
         close(0);
         close(1);
         close(2);
      }
   }
   else
      openlog("termnetd", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON);

   if (loadConfig(confFile) < 0)
   {
      syslog(LOG_ERR, "Quiting!! Error opening config file %s:%m", confFile);
      exit(1);
   }
   memset(&sigact, 0, sizeof(sigact));
   sigact.sa_flags = SA_RESTART;

   sigact.sa_handler = reloadConfig;
   sigaction(SIGHUP, &sigact, NULL);
   sigact.sa_handler = retryConnections;
   sigaction(SIGALRM, &sigact, NULL);
   sigact.sa_handler = SIG_IGN;
   sigaction(SIGCHLD, &sigact, NULL);
   sigact.sa_handler = ignoreSignal;
   sigaction(SIGHUP, &sigact, NULL);
   for (;;)
   {
      Retry = 0;
      if (dbg) syslog(LOG_DEBUG, "main():Opening Sockets!");
      openSockets(Retry);
      if (dbg) syslog(LOG_DEBUG, "main():Calling Socket Select!");
      socketSelect();
      if (Retry == 0)
      {
         if (dbg) syslog(LOG_DEBUG, "main():Closing Sockets!");
         closeSockets();
      }
      if (dbg) syslog(LOG_DEBUG, "main():Loading Config file!");
      if (loadConfig(confFile) < 0)
      {
         syslog(LOG_ERR, "Quiting!! Error opening config file %s:%m", confFile);
         exit(1);
      }
      if (dbg) syslog(LOG_DEBUG, "main():Grabbing 60 winks!");
   }
#ifndef SCO
   exit(0);
#endif
}
Esempio n. 9
0
/*
 *	Main -- entry point from LINUX
 */
int main(int argc, char** argv)
{
    int i, demo = 0;
    printf("OK open data!!!\n");
    printf("open data OK!\n");
    for (i = 0; i < argc; i++) {
        if (strcmp(argv[i], "-demo") == 0) {
			demo++;
		}
	}
/*	Initialize the memory allocator. Allow use of malloc and start 
 *	with a 60K heap.  For each page request approx 8KB is allocated.
 *	60KB allows for several concurrent page requests.  If more space
 *	is required, malloc will be used for the overflow.
 */
	bopen(NULL, (60 * 1024), B_USE_MALLOC);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGINT, sigintHandler);
    signal(SIGTERM, sigintHandler);
/*
 *	Initialize the web server
 */
	if (initWebs(demo) < 0) 
    {
		return -1;
	}
    printf("Init Web service ok!\n");
#ifdef WEBS_SSL_SUPPORT
	websSSLOpen();
        /*	websRequireSSL("/"); */	/* Require all files be served via https */
#endif

        /*
         *	Basic event loop. SocketReady returns true when a socket is ready for
         *	service. SocketSelect will block until an event occurs. SocketProcess
         *	will actually do the servicing.
         */
	finished = 0;
	while (!finished)
    {
		if (socketReady(-1) || socketSelect(-1, 1000))
        {
			socketProcess(-1);
		}
        websCgiCleanup();
        emfSchedProcess();
    }
#ifdef WEBS_SSL_SUPPORT
	websSSLClose();
#endif
#ifdef USER_MANAGEMENT_SUPPORT
	umClose();
#endif
/*
 *	Close the socket module, report memory leaks and close the memory allocator
 */
	websCloseServer();
	socketClose();
#ifdef B_STATS
	memLeaks();
#endif
	bclose();
	return 0;
}
Esempio n. 10
0
/*********************************************************************************************************
** 函数名称: websStart
** 功能描述: 启动 GoAhead web 服务器
** 输 入  : addr          主机地址
**           path          web 路径
**           port          端口号
** 输 出  : 0
** 全局变量:
** 调用模块:
*********************************************************************************************************/
int websStart(char *addr, char *path, int port)
{
    /*
     *  Initialize the memory allocator. Allow use of malloc and start
     *  with a 60K heap.  For each page request approx 8KB is allocated.
     *  60KB allows for several concurrent page requests.  If more space
     *  is required, malloc will be used for the overflow.
     */
    bopen(NULL, (60 * 1024), B_USE_MALLOC);

    /*
     *  Initialize the web server
     */
    if (websInit(addr, path, port) < 0) {
        return -1;
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLOpen();
#endif

    /*
     *  Basic event loop. SocketReady returns true when a socket is ready for
     *  service. SocketSelect will block for two seconds or until an event
     *  occurs. SocketProcess will actually do the servicing.
     */
    running = TRUE;
    while (!running) {
        if (socketReady(-1) || socketSelect(-1, 2000)) {
            socketProcess(-1);
        }
        websCgiCleanup();
        emfSchedProcess();
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLClose();
#endif

#ifdef USER_MANAGEMENT_SUPPORT
    umClose();
#endif

    /*
     *  Close the socket module, report memory leaks and close the memory allocator
     */
    websCloseServer();
    websDefaultClose();
    socketClose();
    symSubClose();

#ifdef B_STATS
    {
        char *argv[2];
        argv[0] = "goaheadmemleak";
        argv[1] = "\0";
        memLeaks(1, argv);                                              /*  print message on stdout     */
    }
#endif

    bclose();

    if (logFile != NULL) {
        fclose(logFile);
        logFile = NULL;
    }

    return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
    int i, demo = 0;
    /*
    	for (i = 1; i < argc; i++) {
    		if (strcmp(argv[i], "-demo") == 0) {
    			demo++;
    		}
    	}
    */
    /*
     *	Initialize the memory allocator. Allow use of malloc and start
     *	with a 60K heap.  For each page request approx 8KB is allocated.
     *	60KB allows for several concurrent page requests.  If more space
     *	is required, malloc will be used for the overflow.
     */

    bopen(NULL, (60 * 1024), B_USE_MALLOC);


    /*
     *	Store the instance handle (used in socket.c)
     */

    /*
     *	Initialize the web server
     */
    if (initWebs(demo) < 0) {
        return FALSE;
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLOpen();
#endif

    /*
     *	Basic event loop. SocketReady returns true when a socket is ready for
     *	service. SocketSelect will block until an event occurs. SocketProcess
     *	will actually do the servicing.
     */
    wprintf(L"begin loop\n");
    while (!finished) {
        if (socketReady(-1) || socketSelect(-1, sockServiceTime)) {
            wprintf(L"--->socketProcess\n");
            socketProcess(-1);
        }
        emfSchedProcess();
        //wprintf(L"cleanup\n");
        websCgiCleanup();
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLClose();
#endif

    /*
     *	Close the User Management database
     */
#ifdef USER_MANAGEMENT_SUPPORT
    umClose();
#endif

    /*
     *	Close the socket module, report memory leaks and close the memory allocator
     */
    websCloseServer();
    socketClose();
#ifdef B_STATS
    memLeaks();
#endif
    bclose();
    return 0;
}
Esempio n. 12
0
int APIENTRY WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance,
                      char* args, int cmd_show )
{
    WPARAM	rc;
    /*
     *	Initialize the memory allocator. Allow use of malloc and start
     *	with a 60K heap.  For each page request approx 8KB is allocated.
     *	60KB allows for several concurrent page requests.  If more space
     *	is required, malloc will be used for the overflow.
     */
    bopen( NULL, ( 60 * 1024 ), B_USE_MALLOC );

    /*
     *	Store the instance handle (used in socket.c)
     */

    if ( windowsInit( hinstance ) < 0 )
    {
        return FALSE;
    }

    /*
     *	Initialize the web server
     */
    if ( initWebs() < 0 )
    {
        return FALSE;
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLOpen();
#endif

    /*
     *	Basic event loop. SocketReady returns true when a socket is ready for
     *	service. SocketSelect will block until an event occurs. SocketProcess
     *	will actually do the servicing.
     */
    while ( !finished )
    {
        if ( socketReady( -1 ) || socketSelect( -1, sockServiceTime ) )
        {
            socketProcess( -1 );
        }

        emfSchedProcess();
        websCgiCleanup();

        if ( ( rc = checkWindowsMsgLoop() ) != 0 )
        {
            break;
        }
    }

#ifdef WEBS_SSL_SUPPORT
    websSSLClose();
#endif
    /*
     *	Close the User Management database
     */
#ifdef USER_MANAGEMENT_SUPPORT
    umClose();
#endif
    /*
     *	Close the socket module, report memory leaks and close the memory allocator
     */
    websCloseServer();
    socketClose();
    /*
     *	Free up Windows resources
     */
    windowsClose( hinstance );
#ifdef B_STATS
    memLeaks();
#endif
    bclose();
    return rc;
}
Esempio n. 13
0
int main(int argc, char** argv)
{
	int i, demo = 0;

	for (i = 1; i < argc; i++) 
	{
		if (strcmp(argv[i], "-demo") == 0) 
		{
			demo++;
		}
	}

	#ifdef DEBUG
		printf("demo:%d\n",demo);		//Modify by :LuiShiLi 
	#endif								//date		:2011.09.28
	

	
	//首先分配一个大的内存块(60*1024字节),以后只要是以b开头的
	//对内存操作的函数都是在这个已经分好的内存块上的操作,
	//这些操作在Balloc.c中实现。

 
	bopen(NULL, (60 * 1024), B_USE_MALLOC);
	signal(SIGPIPE, SIG_IGN);			//管道破裂,写一个没有读端口的管道
	signal(SIGINT, sigintHandler);		//按键中断
	signal(SIGTERM, sigintHandler);		//终止信号


	/*
	
	Initialize the web server
	
	初始化用户管理部分,打开web服务器,注册URL处理函数。
	
	用户管理部分在um.c中实现,
	
	Web服务器的初始化是在default.c和webs.c中实现
	
	url处理函数在handler.c中实现
	
	 */

	if (initWebs(demo) < 0) 
	{
		return -1;
	}

	
#ifdef WEBS_SSL_SUPPORT
	websSSLOpen();
/*	websRequireSSL("/"); */	/* Require all files be served via https */
#endif

/*
 *	Basic event loop. SocketReady returns true when a socket is ready for
 *	service. SocketSelect will block until an event occurs. SocketProcess
 *	will actually do the servicing.
 */

//主循环
	finished = 0;
	while (!finished) 
	{
	
		/*
		
		1,socketReady()函数检查是否有准备好的sock事件
		
		2,socketSelect()函数首先把各个sock感兴趣的事件 (sp->handlerMask)
		注册给三个集合(读,写,例外),然后调用select系统调用,然后更新各个sock
		的 sp->currentEvents,表示各个sock的当前状态。
		
		这两个函数在sockGen.c中实现,他们主要操作的数据是socket_t变量 socketList中
		的handlerMask和currentEvents,socketList在sock.c中定义并主要由该文件中的 
		socketAlloc,socketFree和socketPtr三个函数维护。
		
		*/
		if (socketReady(-1) || socketSelect(-1, 1000)) 
		{
			
			/*
			
			该函数处理具体的sock事件
			
			1,调用socketReady(sid)对socketList[sid]进行检查,看是否有sock事件
			
			2,如果有sock事件,则调用socketDoEvent()函数,对事件进行处理
			
			*/
			socketProcess(-1);
		}

		
		/*
		
		该函数在cgi.c中实现,检查cgiRec变量cgilist,首先把cgi的结果输出,如果有的话,然后看cgi进程是否已对号束,如果结束,就清理该cgi进程。
		
		Cgilist在函数websCgiHandler和websCgiCleanup中维护。




		
		*/
		websCgiCleanup();
		
		/*
		
		该函数在websuemf.c中实现,功能是检查sched_t变量sched,断开超时的连接,sched变量在emfSchedCallback和emfUnschedCallback中维护
		
		*/
		emfSchedProcess();
	}

	
	/*
	
	退出时的清理工作,永远不会执行到这里
	
	*/

#ifdef WEBS_SSL_SUPPORT
	websSSLClose();
#endif

#ifdef USER_MANAGEMENT_SUPPORT
	umClose();
#endif

/*
 *	Close the socket module, report memory leaks and close the memory allocator
 */
	websCloseServer();
	socketClose();
#ifdef B_STATS
	memLeaks();
#endif
	bclose();
	return 0;
}
Esempio n. 14
0
bool mainLoop(int argc, char **argv)
{
  const char *port = PORT;
  int backlog = BACKLOG;
  int bufferSize = BUFFER_SIZE;
  bool interactive = INTERACTIVE;
  args_param_t args_param_list[] =
  {
    {"-p",            &port,        argsString },
    {"--port",        &port,        argsString },
    {"-b",            &backlog,     argsInteger },
    {"--backlog",     &backlog,     argsInteger },
    {"-B",            &bufferSize,  argsInteger },
    {"--buffer",      &bufferSize,  argsInteger },
    {"-i",            &interactive, argsBoolTrue },
    {"--interactive", &interactive, argsBoolTrue },
    {"-d",            &interactive, argsBoolFalse },
    {"--daemon",      &interactive, argsBoolFalse },
    ARGS_DONE
  };
  argsProcess(argc, argv, args_param_list);

  int socket = -1;
  fd_set socketSet;

  bool success = true;
  success = success && socketOpen(port, backlog, &socket);
  success = success && socketSetInitialize(socket, &socketSet, interactive);
  if (success) {
    infof("Message buffer size set to %d.", bufferSize);
  }

  // main loop
  int maxSocket = socket;
  success = success && protocolInit(socket, &socketSet, maxSocket, bufferSize);
  bool done = !success; // skip loop on error
  while (!done) {
    fd_set readSocketSet;
    FD_COPY(&socketSet, &readSocketSet);
    success = success && socketSelect(maxSocket, &readSocketSet);
    for (int s = 0; !done && s <= maxSocket; s++) {
      if (FD_ISSET(s, &readSocketSet)) {
        if (s == socket) {
          socketConnectionNew(s, &maxSocket, &socketSet, bufferSize); // failure is not terminal
        }
        else if (STDIN_FILENO == s) {
          // system control
          done = localControl(s, &socketSet, maxSocket, bufferSize);
        }
        else {
          // existing connection
          protocolUpdate(s, &socketSet, maxSocket, bufferSize); // failure is not terminal
        }
      }
    }
    done = done || !success;
  }
  protocolCleanup(socket, &socketSet, maxSocket, bufferSize); // always

  close(socket);

  return done;
}