예제 #1
0
static void *server_routine(void *arg)
{
	static int status = 0;
	static int started = 0;
	if (started)
	{
		output_error("server routine is already running");
		return NULL;
	}
	started = 1;
	sockfd = (SOCKET)arg;
	// repeat forever..
	while (!shutdown_server)
	{
		struct sockaddr_in cli_addr;
		SOCKET newsockfd;

		int clilen = sizeof(cli_addr);

		/* accept client request and get client address */
		newsockfd = accept(sockfd,(struct sockaddr *)&cli_addr,&clilen);
		if ((int)newsockfd<0 && errno!=EINTR)
		{
			status = GetLastError();
			output_error("server accept error on fd=%d: code %d", sockfd, status);
			goto Done;
		}
		else if ((int)newsockfd > 0)
		{
#ifdef WIN32
			output_verbose("accepting incoming connection from %d.%d.%d.%d on port %d", cli_addr.sin_addr.S_un.S_un_b.s_b1,cli_addr.sin_addr.S_un.S_un_b.s_b2,cli_addr.sin_addr.S_un.S_un_b.s_b3,cli_addr.sin_addr.S_un.S_un_b.s_b4,cli_addr.sin_port);
#else
			output_verbose("accepting incoming connection from on port %d",cli_addr.sin_port);
#endif

			if ( pthread_create(&thread_id,NULL, http_response,(void*)newsockfd)!=0 )
				output_error("unable to start http response thread");
			if (global_server_quit_on_close)
				shutdown_now();
			else
				gui_wait_status(0);
		}
#ifdef NEVER
		{
			handleRequest(newsockfd);
#ifdef WIN32
			closesocket(newsockfd);
#else
			close(newsockfd);
#endif
		}
#endif
	}
	output_verbose("server shutdown");
Done:
	started = 0;
	return (void*)&status;
}
예제 #2
0
/** Callback function to shut server down
 
    This process halts both the server and the simulator.
	
	@return Nothing
 **/
static void shutdown_now(void)
{
	output_verbose("server shutdown on exit in progress...");
	exec_setexitcode(XC_SVRKLL);
	shutdown_server = 1;
	if (sockfd!=(SOCKET)0)
#ifdef WIN32
		shutdown(sockfd,SD_BOTH);
#else
		shutdown(sockfd,SHUT_RDWR);
#endif
	sockfd = (SOCKET)0;
	gui_wait_status(GUIACT_HALT);
	output_verbose("server shutdown on exit done");
}
예제 #3
0
/** Callback function to shut server down
 
    This process halts both the server and the simulator.
	
	@return Nothing
 **/
static void shutdown_now(void)
{
	extern int stop_now;
	output_verbose("server shutdown on exit in progress...");
	stop_now = 1;
	shutdown_server = 1;
	if (sockfd!=(SOCKET)0)
#ifdef WIN32
		shutdown(sockfd,SD_BOTH);
#else
		shutdown(sockfd,SHUT_RDWR);
#endif
	sockfd = (SOCKET)0;
	gui_wait_status(GUIACT_HALT);
	output_verbose("server shutdown on exit done");
}