예제 #1
0
int main(int argc, char** argv)
{
    mpi::environment env(argc, argv);
    mpi::communicator world;

    // half of the processes generate, the others accumulate
    // the sample size is just the number of accumulation ranks
    if (world.rank() < world.size()/2)
        calculate_samples(world.size()-world.size()/2);
    else
        accumulate_samples();

    return 0;
}
예제 #2
0
파일: sock_serv.c 프로젝트: ilart/Yarrow
int main (int argc, char **argv) 
{
	int server_fd, fifo_fd, res, i, nelems;
	char buf[LINE_MAX], packet[PACKET_SIZE];
	
	entropy_src[0].id = 0;
	entropy_src[0].path = "/dev/random";
	entropy_src[0].estimate = 0.4;
	entropy_src[0].len = 100;

	entropy_src[0].id = 1;
	entropy_src[0].path = "/dev/urandom";
	entropy_src[0].estimate = 0.5;
	entropy_src[0].len = 120;

	entropy_src[0].id = 2;
	entropy_src[0].path = NULL;
	entropy_src[0].estimate = 0.8;
	entropy_src[0].len = 120;

	mkfifo(FIFO_PATH, 0777);
	fifo_fd = open(FIFO_PATH, O_NONBLOCK);
	if (fifo_fd == -1)
		printf("open returned %d: %s\n",
			fifo_fd, strerror(fifo_fd));

	nsources = 2; // this value will be taken from entropy_pool.nsources

	// create children for accumulate entropy from i source
	// All information about source will be obtained from config file.
	for (i = 0; i < nsources; i++) {
		if ((pid = fork()) < 0) {
			printf("Fork returned %d: %s\n",
			       pid, strerror(pid));
			exit(1);
		} else if (pid == 0) {
			accumulate_samples(i); 
	}
		
	server_fd = sock_unix_listen("/var/run/yarrow.socket");
	if (server_fd <= 0) {
		perror("Sock unix listen");
		exit(1);
	}

	printf("server_fd %d\n", server_fd);
	sock_nonblock(server_fd);

	poll_fd = calloc(2, sizeof(struct pollfd));
	if (poll_fd == NULL) {
		perror("Calloc returned NULL.");
		exit(1);
	}

	poll_fd[0].fd = server_fd;
	poll_fd[0].events = POLLIN;
	poll_fd[1].fd = fifo_fd;
	poll_fd[1].events = (POLLIN|POLLPRI);

	peer_ctx = calloc(2, sizeof(struct peer));
	if (peer_ctx == NULL) {
		perror("Calloc returned NULL");
		exit(1);
	}
	
	peer_ctx[0].sfd = server_fd;
	peer_ctx[0].bufused = 0;
	peer_ctx[1].sfd = fifo_fd;
	peer_ctx[1].bufused = 0;

	nelems = 2;
	i = 0;
	
	while (1) {
		res = poll(poll_fd, nelems, -1);
		if (res > 0) {
			if (poll_fd[0].revents & POLLIN) {
				accept_connect(&nelems);
			} else if (poll_fd[1].revents & POLLIN) {
				accumulate_entropy(packet);	
			}
 		
			process_events(nelems); 
		} else if (res < 0 && errno != EINTR) {
			printf("poll returned %d: %s\n",
			      res, strerror(errno));
			break;
		} 
	}	
	
	close(server_fd);
	unlink("/var/run/yarrow.socket");
return 0;
}