示例#1
0
int main(int argc, char *argv[])
{
    FILE *fpin = NULL;
    if( argc == 1 )
    {
        printf( HMSG, argv[0] );
        return 0;
    }
    else
    {
        for(int i = 1; i < argc; ++i)
        {
            if(argc > 2)
            {
                printf("\n---%03d---%s---\n", i, argv[i]);
            }
            if( (fpin = fopen(argv[i], "r")) == NULL )
            {
                perrmsg(argv[i], ERR_OPEN_FILE);
                exit(1);
            }
            realChar(fpin);
            fclose(fpin);
        }
    }

    return 0;
}
示例#2
0
//Correlation for two vector interval [b,e]
float corf_2(float *trace1, float *trace2, int len, int b, int e)
{
    if(b < 0 || e < 0 || b > len || e > len || e < b)
    {
        perrmsg( "corf_2", WARN_OUT_RANGE);
        exit(1);
    }
    int i;
    float ak = 0.0f, ac1 = 0.0f, ac2 = 0.0f ;
    for(i = b; i <= e; ++i)
    {
        ak  += trace1[i] * trace2[i];
        ac1 += trace1[i] * trace1[i];
        ac2 += trace2[i] * trace2[i];
    }
    //Add by Wangsheng 2015/11/08
    if(ac1 > 1.0e-8 && ac2 > 1.0e-8)
        ak *= sqrtf(1.0f/ ac1 / ac2);
    else
        ak = 0.0f;
    return ak;
}
示例#3
0
int main(int argc,char * argv[]){
	if (argc <= 2){
		printf("usage : ip port\n");
	//	return 1;
	}

	const char * ip = argv[1];
	int port = atoi(argv[2]);

	struct sockaddr_in address;
	memset(&address,0,sizeof(address));
	//address.sin_family = AF_INET;
	//inet_pton(AF_INET,ip,&address.sin_addr);
	//address.sin_port = htons(port);

	address.sin_family=AF_INET; 
	address.sin_addr.s_addr=INADDR_ANY;
	address.sin_port=htons(8000); 

	int listenfd = socket(PF_INET,SOCK_STREAM,0);
	assert(listenfd >= 0);
	int ret = bind(listenfd,(struct sockaddr * )&address,sizeof(address));
	if (ret == -1){
		perrmsg(errno);
		return 1;
	}
	ret = listen(listenfd,5);
	assert(ret != -1);

	struct epoll_event events[MAX_EVENT_NUMBER];
	int epollfd = epoll_create(5);
	assert (epollfd != -1);
	addfd(epollfd,listenfd);

	ret = socketpair(PF_UNIX,SOCK_STREAM,0,pipefd);
	assert (ret != -1);
	setnoblocking(pipefd[1]);
	addfd(epollfd,pipefd[0]);

	addsig(SIGHUP);
	addsig(SIGCHLD);
	addsig(SIGTERM);
	addsig(SIGINT);

	int stop_server = 0;

	while(!stop_server){

		int number = epoll_wait(epollfd,events,MAX_EVENT_NUMBER,-1);
		if ((number != 0) && ( errno != EINTR)){
			printf ("epoll failed\n");
			strerror(errno);
		}
		int i=0;
		for ( i; i< number; i++){
			int sockfd = events[i].data.fd;
			if (sockfd = listenfd){
				struct sockaddr_in client_address;
				socklen_t client_lenth = sizeof(client_address);
				int connfd = accept(listenfd,(struct sockaddr *)&client_address,&client_lenth);
				addfd(epollfd,connfd);
			}
			else if ((sockfd == pipefd[0]) && (events[i].events & EPOLLIN)){
				int sig;
				char signals[1024];
				ret = recv(pipefd[0],signals,sizeof(signals),0);
				if (ret == -1){
					continue;
				}
				else if(ret == 0){
					continue;
				}
				else{
					int i;
					for ( i=0;i<ret;++i){
						printf("sig no occured is %d",signals[i]);
						if (signals[i] == SIGINT){
							stop_server = 1;
						}
					}
				}
			}

		}
		}
	printf("close fds\n");
	close(listenfd);
	close(pipefd[0]);
	close(pipefd[1]);
	return 0;
}