upnp/src/genlib/miniserver/miniserver.c
static void RunMiniServer(
	/*! [in] Socket Array. */
	MiniServerSockArray *miniSock)
{
	char errorBuffer[ERROR_BUFFER_LEN];
	fd_set expSet;
	fd_set rdSet;
	SOCKET maxMiniSock;
	int ret = 0;
	int stopSock = 0;

	maxMiniSock = 0;
	maxMiniSock = max(maxMiniSock, miniSock->miniServerSock4);
	maxMiniSock = max(maxMiniSock, miniSock->miniServerSock6);
	maxMiniSock = max(maxMiniSock, miniSock->miniServerStopSock);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock4);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock6);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock6UlaGua);
#ifdef INCLUDE_CLIENT_APIS
	maxMiniSock = max(maxMiniSock, miniSock->ssdpReqSock4);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpReqSock6);
#endif /* INCLUDE_CLIENT_APIS */
	++maxMiniSock;

	gMServState = MSERV_RUNNING;
	while (!stopSock) {
		FD_ZERO(&rdSet);
		FD_ZERO(&expSet);
		/* FD_SET()'s */
		FD_SET(miniSock->miniServerStopSock, &expSet);
		FD_SET(miniSock->miniServerStopSock, &rdSet);
		fdset_if_valid(miniSock->miniServerSock4, &rdSet);
		fdset_if_valid(miniSock->miniServerSock6, &rdSet);
		fdset_if_valid(miniSock->ssdpSock4, &rdSet);
		fdset_if_valid(miniSock->ssdpSock6, &rdSet);
		fdset_if_valid(miniSock->ssdpSock6UlaGua, &rdSet);
#ifdef INCLUDE_CLIENT_APIS
		fdset_if_valid(miniSock->ssdpReqSock4, &rdSet);
		fdset_if_valid(miniSock->ssdpReqSock6, &rdSet);
#endif /* INCLUDE_CLIENT_APIS */
		/* select() */
		ret = select((int) maxMiniSock, &rdSet, NULL, &expSet, NULL);
		if (ret == SOCKET_ERROR && errno == EINTR) {
			continue;
		}
		if (ret == SOCKET_ERROR) {
			strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
			UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
				"Error in select(): %s\n", errorBuffer);
			continue;
		} else {
			web_server_accept(miniSock->miniServerSock4, &rdSet);
			web_server_accept(miniSock->miniServerSock6, &rdSet);
#ifdef INCLUDE_CLIENT_APIS
			ssdp_read(miniSock->ssdpReqSock4, &rdSet);
			ssdp_read(miniSock->ssdpReqSock6, &rdSet);
#endif /* INCLUDE_CLIENT_APIS */
			ssdp_read(miniSock->ssdpSock4, &rdSet);
			ssdp_read(miniSock->ssdpSock6, &rdSet);
			ssdp_read(miniSock->ssdpSock6UlaGua, &rdSet);
			stopSock = receive_from_stopSock(
				miniSock->miniServerStopSock, &rdSet);
		}
	}
	/* Close all sockets. */
	sock_close(miniSock->miniServerSock4);
	sock_close(miniSock->miniServerSock6);
	sock_close(miniSock->miniServerStopSock);
	sock_close(miniSock->ssdpSock4);
	sock_close(miniSock->ssdpSock6);
	sock_close(miniSock->ssdpSock6UlaGua);
#ifdef INCLUDE_CLIENT_APIS
	sock_close(miniSock->ssdpReqSock4);
	sock_close(miniSock->ssdpReqSock6);
#endif /* INCLUDE_CLIENT_APIS */
	/* Free minisock. */
	free(miniSock);
	gMServState = MSERV_IDLE;

	return;
}
/*!
 * \brief Run the miniserver.
 *
 * The MiniServer accepts a new request and schedules a thread to handle the
 * new request. Checks for socket state and invokes appropriate read and
 * shutdown actions for the Miniserver and SSDP sockets.
 */
\brief Run the miniserver.
The MiniServer accepts a new request and schedules a thread to handle the
new request. Checks for socket state and invokes appropriate read and
shutdown actions for the Miniserver and SSDP sockets.
\ brief Run the miniserver . The MiniServer accepts a new request and schedules a thread to handle the new request . Checks for socket state and invokes appropriate read and shutdown actions for the Miniserver and SSDP sockets .
static void RunMiniServer(
	MiniServerSockArray *miniSock)
{
	char errorBuffer[ERROR_BUFFER_LEN];
	fd_set expSet;
	fd_set rdSet;
	SOCKET maxMiniSock;
	int ret = 0;
	int stopSock = 0;
	maxMiniSock = 0;
	maxMiniSock = max(maxMiniSock, miniSock->miniServerSock4);
	maxMiniSock = max(maxMiniSock, miniSock->miniServerSock6);
	maxMiniSock = max(maxMiniSock, miniSock->miniServerStopSock);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock4);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock6);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpSock6UlaGua);
#ifdef INCLUDE_CLIENT_APIS
	maxMiniSock = max(maxMiniSock, miniSock->ssdpReqSock4);
	maxMiniSock = max(maxMiniSock, miniSock->ssdpReqSock6);
#endif 
	++maxMiniSock;
	gMServState = MSERV_RUNNING;
	while (!stopSock) {
		FD_ZERO(&rdSet);
		FD_ZERO(&expSet);
		FD_SET(miniSock->miniServerStopSock, &expSet);
		FD_SET(miniSock->miniServerStopSock, &rdSet);
		fdset_if_valid(miniSock->miniServerSock4, &rdSet);
		fdset_if_valid(miniSock->miniServerSock6, &rdSet);
		fdset_if_valid(miniSock->ssdpSock4, &rdSet);
		fdset_if_valid(miniSock->ssdpSock6, &rdSet);
		fdset_if_valid(miniSock->ssdpSock6UlaGua, &rdSet);
#ifdef INCLUDE_CLIENT_APIS
		fdset_if_valid(miniSock->ssdpReqSock4, &rdSet);
		fdset_if_valid(miniSock->ssdpReqSock6, &rdSet);
#endif 
		ret = select((int) maxMiniSock, &rdSet, NULL, &expSet, NULL);
		if (ret == SOCKET_ERROR && errno == EINTR) {
			continue;
		}
		if (ret == SOCKET_ERROR) {
			strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
			UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
				"Error in select(): %s\n", errorBuffer);
			continue;
		} else {
			web_server_accept(miniSock->miniServerSock4, &rdSet);
			web_server_accept(miniSock->miniServerSock6, &rdSet);
#ifdef INCLUDE_CLIENT_APIS
			ssdp_read(miniSock->ssdpReqSock4, &rdSet);
			ssdp_read(miniSock->ssdpReqSock6, &rdSet);
#endif 
			ssdp_read(miniSock->ssdpSock4, &rdSet);
			ssdp_read(miniSock->ssdpSock6, &rdSet);
			ssdp_read(miniSock->ssdpSock6UlaGua, &rdSet);
			stopSock = receive_from_stopSock(
				miniSock->miniServerStopSock, &rdSet);
		}
	}
	sock_close(miniSock->miniServerSock4);
	sock_close(miniSock->miniServerSock6);
	sock_close(miniSock->miniServerStopSock);
	sock_close(miniSock->ssdpSock4);
	sock_close(miniSock->ssdpSock6);
	sock_close(miniSock->ssdpSock6UlaGua);
#ifdef INCLUDE_CLIENT_APIS
	sock_close(miniSock->ssdpReqSock4);
	sock_close(miniSock->ssdpReqSock6);
#endif 
	free(miniSock);
	gMServState = MSERV_IDLE;
	return;
}
static void RunMiniServer ( MiniServerSockArray * miniSock ) { char errorBuffer [ ERROR_BUFFER_LEN ] ; fd_set expSet ; fd_set rdSet ; SOCKET maxMiniSock ; int ret = 0 ; int stopSock = 0 ; maxMiniSock = 0 ; maxMiniSock = max ( maxMiniSock , miniSock -> miniServerSock4 ) ; maxMiniSock = max ( maxMiniSock , miniSock -> miniServerSock6 ) ; maxMiniSock = max ( maxMiniSock , miniSock -> miniServerStopSock ) ; maxMiniSock = max ( maxMiniSock , miniSock -> ssdpSock4 ) ; maxMiniSock = max ( maxMiniSock , miniSock -> ssdpSock6 ) ; maxMiniSock = max ( maxMiniSock , miniSock -> ssdpSock6UlaGua ) ; #ifdef INCLUDE_CLIENT_APIS maxMiniSock = max ( maxMiniSock , miniSock -> ssdpReqSock4 ) ; maxMiniSock = max ( maxMiniSock , miniSock -> ssdpReqSock6 ) ; #endif ++ maxMiniSock ; gMServState = MSERV_RUNNING ; while ( ! stopSock ) { FD_ZERO ( & rdSet ) ; FD_ZERO ( & expSet ) ; FD_SET ( miniSock -> miniServerStopSock , & expSet ) ; FD_SET ( miniSock -> miniServerStopSock , & rdSet ) ; fdset_if_valid ( miniSock -> miniServerSock4 , & rdSet ) ; fdset_if_valid ( miniSock -> miniServerSock6 , & rdSet ) ; fdset_if_valid ( miniSock -> ssdpSock4 , & rdSet ) ; fdset_if_valid ( miniSock -> ssdpSock6 , & rdSet ) ; fdset_if_valid ( miniSock -> ssdpSock6UlaGua , & rdSet ) ; #ifdef INCLUDE_CLIENT_APIS fdset_if_valid ( miniSock -> ssdpReqSock4 , & rdSet ) ; fdset_if_valid ( miniSock -> ssdpReqSock6 , & rdSet ) ; #endif ret = select ( ( int ) maxMiniSock , & rdSet , NULL , & expSet , NULL ) ; if ( ret == SOCKET_ERROR && errno == EINTR ) { continue ; } if ( ret == SOCKET_ERROR ) { strerror_r ( errno , errorBuffer , ERROR_BUFFER_LEN ) ; UpnpPrintf ( UPNP_CRITICAL , SSDP , __FILE__ , __LINE__ , " \n " , errorBuffer ) ; continue ; } else { web_server_accept ( miniSock -> miniServerSock4 , & rdSet ) ; web_server_accept ( miniSock -> miniServerSock6 , & rdSet ) ; #ifdef INCLUDE_CLIENT_APIS ssdp_read ( miniSock -> ssdpReqSock4 , & rdSet ) ; ssdp_read ( miniSock -> ssdpReqSock6 , & rdSet ) ; #endif ssdp_read ( miniSock -> ssdpSock4 , & rdSet ) ; ssdp_read ( miniSock -> ssdpSock6 , & rdSet ) ; ssdp_read ( miniSock -> ssdpSock6UlaGua , & rdSet ) ; stopSock = receive_from_stopSock ( miniSock -> miniServerStopSock , & rdSet ) ; } } sock_close ( miniSock -> miniServerSock4 ) ; sock_close ( miniSock -> miniServerSock6 ) ; sock_close ( miniSock -> miniServerStopSock ) ; sock_close ( miniSock -> ssdpSock4 ) ; sock_close ( miniSock -> ssdpSock6 ) ; sock_close ( miniSock -> ssdpSock6UlaGua ) ; #ifdef INCLUDE_CLIENT_APIS sock_close ( miniSock -> ssdpReqSock4 ) ; sock_close ( miniSock -> ssdpReqSock6 ) ; #endif free ( miniSock ) ; gMServState = MSERV_IDLE ; return ; }
\brief Run the miniserver.
\ brief Run the miniserver .
/*! [in] Socket Array. */ /* INCLUDE_CLIENT_APIS */ /* FD_SET()'s */ /* INCLUDE_CLIENT_APIS */ /* select() */ /* INCLUDE_CLIENT_APIS */ /* Close all sockets. */ /* INCLUDE_CLIENT_APIS */ /* Free minisock. */