Example #1
0
void stop_all_threads()
{
	gblSetQuit();

	int i;
	for (i = 0; i < NUM_OF_THREADS; i++)
	{
		if (i == ALARM_INPUT_THR)
			OSA_thrDelete(&g_threadMgr.hThread[i]);
		else
			OSA_thrJoin(&g_threadMgr.hThread[i]);
		printf("[main] join threads: %d\n", i);
	}
}
Example #2
0
/*WEB server Thead Function*/
Void *weblistenThrFxn(Void *arg)
{
	PRINTF("get pid= %d\n", getpid());
	Void                   *status              = THREAD_SUCCESS;
	int 					listenSocket  		= 0 , flags = 0;
	struct sockaddr_in 		addr;
	//struct in_addr          addr_ip;
	int len, client_sock, opt = 1;
	struct sockaddr_in client_addr;
	webMsgInfo_1260		webinfo_1260;
	ssize_t			recvlen;
	//int count = 0;
	char  data_1260[2048] = {0};
	// signal_set();


	//	for(count = TS_STREAM; count < MAX_PROTOCOL; count++) {
	//		WebInitMultAddr(&s_MultAddr[count]);
	//	}

	len = sizeof(struct sockaddr_in);
	memset(&client_addr, 0, len);
	listenSocket =	socket(PF_INET, SOCK_STREAM, 0);

	if(listenSocket < 1)	{
		status  = THREAD_FAILURE;
		return status;
	}

	memset(&addr, 0, sizeof(struct sockaddr_in));
	addr.sin_family =       AF_INET;
	addr.sin_addr.s_addr = inet_addr("127.0.0.1");
	addr.sin_port = htons(ENCODESERVER_PORT);

	setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

	if(bind(listenSocket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)  	{
		DEBUG(DL_ERROR, "[weblistenThrFxn] bind failed,errno = %d,error message:%s \n", errno, strerror(errno));
		status  = THREAD_FAILURE;
		return status;
	}


	if(-1 == listen(listenSocket, MAX_LISTEN))     {
		DEBUG(DL_ERROR, "listen failed,errno = %d,error message:%s \n", errno, strerror(errno));
		status  = THREAD_FAILURE;
		return status;
	}

	if((flags = fcntl(listenSocket, F_GETFL, 0)) == -1)	{
		DEBUG(DL_ERROR, "fcntl F_GETFL error:%d,error msg: = %s\n", errno, strerror(errno));
		gblSetQuit();
		status  = THREAD_FAILURE;
		return status ;
	}

	if(fcntl(listenSocket, F_SETFL, flags | O_NONBLOCK) == -1) {
		DEBUG(DL_ERROR, "fcntl F_SETFL error:%d,error msg: = %s\n", errno, strerror(errno));
		gblSetQuit();
		status  = THREAD_FAILURE;
		return status ;
	}

	//ProtocolInit();
	//InitProtocalStatus();





	while(!gblGetQuit()) {
		fd_set rfds;
		FD_ZERO(&rfds);
		FD_SET(listenSocket, &rfds);
		//接收recv_buf 复位为空!
		select(FD_SETSIZE, &rfds , NULL , NULL , NULL);
		//PRINTF("\n");
		client_sock = accept(listenSocket, (struct sockaddr *)&client_addr, (socklen_t *)&len);

		if(0 > client_sock)     {
			PRINTF("\n");

			if(errno == ECONNABORTED || errno == EAGAIN) 	{
				//usleep(20000);
				continue;
			}

			DEBUG(DL_DEBUG, "weblisten thread Function errno  = %d\n", errno);
			status  = THREAD_FAILURE;
			return status;
		}

		memset(&webinfo_1260, 0, sizeof(webinfo_1260));
		recvlen = recv(client_sock, &webinfo_1260, sizeof(webinfo_1260), 0);
		//PRINTF("recvlen = %d webinfo.len =%d webinfo.type = %d,id=%x\n",
		//       recvlen, webinfo_1260.len, webinfo_1260.type, webinfo_1260.identifier);

		if(recvlen < 1)	{
			PRINTF("recv failed,errno = %d,error message:%s,client_sock = %d\n", errno, strerror(errno), client_sock);
			status  = THREAD_FAILURE;
			return status;
		}

		if(webinfo_1260.identifier != WEB_IDENTIFIER) {
			PRINTF("id  error,client_sock = %d\n", client_sock);
			status  = THREAD_FAILURE;
			return status;
		}

		len = webinfo_1260.len - sizeof(webinfo_1260);

		PRINTF("web deal begin =%d\n", webinfo_1260.type);

		switch(webinfo_1260.type) {
			case INT_TYPE:
				//PRINTF("web deal begin =%d\n", webinfo_1260.type);
				midParseInt(webinfo_1260.identifier,client_sock, data_1260, len);
				//PRINTF("web deal end =%d\n", webinfo_1260.type);
				break;

			case STRING_TYPE:
				//	PRINTF("web deal begin =%d\n", webinfo_1260.type);
				midParseString(webinfo_1260.identifier,client_sock, data_1260, len);
				//	PRINTF("web deal end =%d\n", webinfo_1260.type);
				break;

			case STRUCT_TYPE:
				//	PRINTF("web deal begin =%d\n", webinfo_1260.type);
				midParseStruct(webinfo_1260.identifier,client_sock, data_1260, len);
				//	PRINTF("web deal end =%d\n", webinfo_1260.type);
				break;

			default:
				break;
		}

		PRINTF("web deal end =%d\n", webinfo_1260.type);
		close(client_sock);
	}

	//ProtocolExit();

	close(listenSocket);
	DEBUG(DL_DEBUG, "Web listen Thread Function Exit!!\n");
	return status;
}
Example #3
0
File: main.c Project: aCayF/encode
/******************************************************************************
 * Signal handler
 ******************************************************************************/
Void signalHandler(int sig)
{
    signal(SIGINT, SIG_DFL);
    gblSetQuit();
}
Example #4
0
static void signal_handle(int signo)
{
	DEBUG(DL_DEBUG, "System signal(%d) received,exit \n", signo);
	gblSetQuit();
}