Пример #1
0
END_TEST

START_TEST (create_endpoint_loop) {
  uint32_t initFlags = 0;
  uint32_t capabilities = 0;
  uint32_t status = 0;
  cci_device_t const ** const devices = NULL;   		/* available device structure */
  cci_device_t const ** d = NULL;
	cci_endpoint_t* endpointP = NULL;											/* pointer to endpoint structure */
	int32_t deviceFlags = 0;																				/* not yet implemented */
	cci_os_handle_t fd;																								/* endpoint handle */
	uint32_t i;
	
  /* Initialize cci library */
  status = cci_init(CCI_ABI_VERSION, initFlags, &capabilities);
  fail_unless(status == CCI_SUCCESS, "cci_init() failed with status %s", cci_strerror(NULL, status));

  /* get a list of the available devices */
  status = cci_get_devices((cci_device_t * const **) &devices);
  fail_unless(status == CCI_SUCCESS, "cci_get_devices() failed with status %s", cci_strerror(NULL, status));
	
	for(i=0; i<10; ++i) {
		for(d = devices; *d != NULL; ++d) {
			status = cci_create_endpoint((cci_device_t*) *d, deviceFlags, &endpointP, &fd);
			fail_unless(status == CCI_SUCCESS, "cci_create_endpoint() failed with status %s", cci_strerror(NULL, status));

			status = cci_destroy_endpoint(endpointP);
			fail_unless(status == CCI_SUCCESS, "cci_destroy_endpoint() failed with status %s", cci_strerror(NULL, status));
		}
	}
}
Пример #2
0
Файл: register.c Проект: CCI/cci
int main(int argc, char *argv[])
{
	int c, ret;
	int dereg = 0, prefault = 0;
	uint32_t pagesize = 0, offset = 0;
	uint64_t regsize = REGSIZE, totalsize = TOTALSIZE, count, i;
	uint32_t caps;
	cci_device_t * const *devices;
	cci_endpoint_t *endpoint;
	void *base, *ptr;
	uint64_t length;
	cci_rma_handle_t **handles = NULL;
	struct timeval start, end;
	uint64_t usecs = 0;

	pagesize = sysconf(_SC_PAGESIZE);

	while ((c = getopt(argc, argv, "dfo:s:t:")) != -1) {
		switch (c) {
		case 'd':
			dereg = 1;
			break;
		case 'f':
			prefault = 1;
			break;
		case 'o':
			offset = strtoul(optarg, NULL, 0);
			if (offset >= pagesize) {
				fprintf(stderr,
					"offset larger than pagesize (%u)\n",
					pagesize);
				usage(argv[0]);
			}
			break;
		case 's':
			regsize = strtoull(optarg, NULL, 0);
			if (regsize < pagesize) {
				printf("regsize (%" PRIu64
				       ") < pagesize (%u) - increasing to pagesize\n",
				       regsize, pagesize);
				regsize = pagesize;
			}
			break;
		case 't':
			totalsize = strtoull(optarg, NULL, 0);
			break;
		default:
			usage(argv[0]);
			break;
		}
	}

	count = totalsize / regsize;

	ret = posix_memalign(&base, pagesize, totalsize + offset);
	check_return(NULL, "posix_memalign", ret);

	ptr = (void*)((uintptr_t)base + (uintptr_t) offset);
	length = regsize;

	handles = calloc(count, sizeof(*handles));
	check_return(NULL, "calloc", handles ? 0 : CCI_ENOMEM);

	if (prefault) {
		for (i = 0; i < totalsize; i += pagesize) {
			char *c = (char *)ptr + (uintptr_t) i;
			*c = '1';
		}
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	check_return(NULL, "cci_init", ret);

	ret = cci_get_devices(&devices);
	check_return(NULL, "cci_get_devices", ret);

	ret = cci_create_endpoint(NULL, 0, &endpoint, NULL);
	check_return(NULL, "cci_create_endpoint", ret);

	/* register */
	if (!dereg)
		gettimeofday(&start, NULL);

	for (i = 0; i < count; i++) {
		void *p = (void*)((uintptr_t)ptr + ((uintptr_t) i * (uintptr_t)length));

		ret = cci_rma_register(endpoint, p, length, CCI_FLAG_READ|CCI_FLAG_WRITE, &handles[i]);
		check_return(endpoint, "cci_rma_register", ret);
	}

	if (!dereg)
		gettimeofday(&end, NULL);

	/* deregister */
	if (dereg)
		gettimeofday(&start, NULL);

	for (i = 0; i < count; i++) {
		ret = cci_rma_deregister(endpoint, handles[i]);
		check_return(endpoint, "cci_rma_register", ret);
	}

	if (dereg)
		gettimeofday(&end, NULL);

	usecs = (end.tv_sec - start.tv_sec) * 1000000 +
	    end.tv_usec - start.tv_usec;
	printf("%10s%10s%10s%10s\n", "RegSize", "Count", "usecs", "us/page");
	printf("%10" PRIu64 "%10" PRIu64 "%10" PRIu64 "%10.2f\n",
	       regsize, count, usecs,
	       ((double)usecs / (double) count) / ((double)regsize / (double)pagesize));

	ret = cci_destroy_endpoint(endpoint);
	check_return(endpoint, "cci_destroy_endpoint", ret);

        ret = cci_finalize();
	check_return(NULL, "cci_finalize", ret);

	return 0;
}
Пример #3
0
Файл: rpc.c Проект: CCI/cci
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	char *transport = NULL;
	cci_device_t * const *devices = NULL, *device = NULL;

	name = argv[0];

	opts.iters = ITERS;
	opts.warmup = WARMUP;
	opts.req_size = REQ_SIZE;
	opts.transfer_size = TRANSFER_SIZE;
	opts.ack_size = ACK_SIZE;

	while ((c = getopt(argc, argv, "h:st:i:W:c:wrR:T:A:S")) != -1) {
		switch (c) {
		case 'h':
			strncpy(server_uri, optarg, sizeof(server_uri));
			break;
		case 's':
			is_server = 1;
			break;
		case 't':
			transport = strdup(optarg);
			break;
		case 'i':
			opts.iters = strtoul(optarg, NULL, 0);
			break;
		case 'W':
			opts.warmup = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			concurrent = strtoul(optarg, NULL, 0);
			if (concurrent > 64)
				concurrent = 64;
			break;
		case 'w':
			/* The client wants to write. The server will RMA Read. */
			opts.rma_flags = CCI_FLAG_READ;
			break;
		case 'r':
			/* The client wants to read. The server will RMA Write. */
			opts.rma_flags = CCI_FLAG_WRITE;
			break;
		case 'R':
			opts.req_size = strtoul(optarg, NULL, 0);
			if (opts.req_size > REQ_SIZE)
				opts.req_size = REQ_SIZE;
			break;
		case 'T':
			opts.transfer_size = strtoul(optarg, NULL, 0);
			break;
		case 'A':
			opts.ack_size = strtoul(optarg, NULL, 0);
			if (opts.ack_size > ACK_SIZE)
				opts.ack_size = ACK_SIZE;
			break;
		case 'S':
			suppress = 1;
			break;
		default:
			print_usage();
		}
	}

	if (!opts.rma_flags)
		opts.rma_flags = CCI_FLAG_READ;

	if (!opts.transfer_size)
		opts.transfer_size = TRANSFER_SIZE;

#ifndef USE_MPI
	if (!is_server && server_uri[0] == '\0') {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}
#else
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	if (rank == 0)
		is_server = 1;
#endif

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	check_return(NULL, "cci_init", ret, 1);

	if (transport) {
		int i = 0;
		ret = cci_get_devices(&devices);
		check_return(NULL, "cci_get_devices", ret, 1);

		/* Select first device that matches transport. */
		for (i = 0; ; i++) {
			device = devices[i];

			if (!device)
				break;

			if (strncmp(device->transport, transport, strlen(device->transport)) == 0)
				break;
		}
	}

	/* create an endpoint */
	ret = cci_create_endpoint(device, 0, &endpoint, NULL);
	check_return(NULL, "cci_create_endpoint", ret, 1);

	ret = cci_get_opt(endpoint, CCI_OPT_ENDPT_URI, &uri);
	check_return(endpoint, "cci_get_opt", ret, 1);

	if (!suppress)
		printf("Opened %s\n", uri);

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	check_return(endpoint, "cci_destroy_endpoint", ret, 1);

	if (buffer)
		free(buffer);

	free(transport);
	free(uri);

	ret = cci_finalize();
	check_return(NULL, "cci_finalize", ret, 1);

#ifdef USE_MPI
	MPI_Barrier();
	MPI_Finalize();
#endif
	return 0;
}
Пример #4
0
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	cci_os_handle_t *os_handle = NULL;
	char *uri = NULL;
	pid_t pid = 0;

	pid = getpid();
	srandom(pid);

	memset(&msg, 0, sizeof(msg));

	name = argv[0];

	while ((c = getopt(argc, argv, "h:si:c:wrl:o:O:R:BI")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			is_client = 1;
			break;
		case 's':
			is_server = 1;
			break;
		case 'i':
			iters = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			if (strncasecmp("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else
				print_usage();
			printf("Using %s connection\n",
			       attr == CCI_CONN_ATTR_RU ? "RU" : "RO");
			break;
		case 'w':
			opts.method = RMA_WRITE;
			break;
		case 'r':
			opts.method = RMA_READ;
			break;
		case 'l':
			length = strtoul(optarg, NULL, 0);
			break;
		case 'R':
			opts.reg_len = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			local_offset = strtoul(optarg, NULL, 0);
			break;
		case 'O':
			remote_offset = strtoul(optarg, NULL, 0);
			break;
		case 'B':
			blocking = 1;
			os_handle = &fd;
			break;
		case 'I':
			ignore_os_handle = 1;
			os_handle = &fd;
			break;
		default:
			print_usage();
		}
	}

	if (!is_server && !server_uri) {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}

	if (is_server && is_client) {
		fprintf(stderr, "Must select -h or -s, not both\n");
		print_usage();
	}

	if (blocking && ignore_os_handle) {
		fprintf(stderr, "-B and -I are not compatible.\n");
		fprintf(stderr, "-B will block using select() using the OS handle.\n");
		fprintf(stderr, "-I will obtain the OS handle, but not use it to wait.\n");
		print_usage();
	}

	if (!opts.method)
		opts.method = RMA_WRITE;

	if (!opts.reg_len) {
		if (!length) {
			opts.reg_len = RMA_REG_LEN;
		} else {
			opts.reg_len = length;
		}
	}

	if (!length) {
		if (!opts.reg_len)
			length = RMA_REG_LEN;
		else
			length = opts.reg_len;
	}

	if (opts.reg_len == length) {
		if (local_offset || remote_offset) {
			fprintf(stderr, "*** RMA registration length == RMA length "
					"and an offset was requested. ***\n"
					"*** This should cause an error. ***\n");
		}
	}

	if (is_client)
		fprintf(stderr, "Testing with local_offset %"PRIu64" "
				"remote_offset %"PRIu64" "
				"reg_len %"PRIu64" length %"PRIu64"\n",
				local_offset, remote_offset, opts.reg_len, length);

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, os_handle);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	if (blocking) {
		nfds = fd + 1;
		FD_ZERO(&rfds);
		FD_SET(fd, &rfds);
	}

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	free(buffer);
	free(uri);
	free(server_uri);

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}
Пример #5
0
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	cci_os_handle_t *os_handle = NULL;
	char *uri = NULL;

	name = argv[0];

	while ((c = getopt(argc, argv, "h:sRc:nwrm:Ci:W:bo")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			break;
		case 's':
			is_server = 1;
			break;
		case 'R':
			accept = 0;
			break;
		case 'i':
			iters = strtoul(optarg, NULL, 0);
			break;
		case 'W':
			warmup = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			if (strncasecmp("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else if (strncasecmp("uu", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_UU;
			else
				print_usage();
			printf("Using %s connection\n",
			       attr == CCI_CONN_ATTR_UU ? "UU" : attr ==
			       CCI_CONN_ATTR_RU ? "RU" : "RO");
			break;
		case 'n':
			opts.flags = CCI_FLAG_NO_COPY;
			break;
		case 'w':
			opts.method = RMA_WRITE;
			break;
		case 'r':
			opts.method = RMA_READ;
			break;
		case 'm':
			opts.max_rma_size = strtoul(optarg, NULL, 0);
			break;
		case 'C':
			remote_completion = 1;
			break;
		case 'b':
			blocking = 1;
			os_handle = &fd;
			break;
		case 'o':
			ignore_os_handle = 1;
			os_handle = &fd;
			break;
		default:
			print_usage();
		}
	}

	if (!is_server && !server_uri) {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}

	if (blocking && ignore_os_handle) {
		fprintf(stderr, "-b and -o are not compatible.\n");
		fprintf(stderr, "-b will block using select() using the OS handle.\n");
		fprintf(stderr, "-o will obtain the OS handle, but not use it to wait.\n");
		print_usage();
	}

	if (attr == CCI_CONN_ATTR_UU) {
		if (opts.method != MSGS) {
			fprintf(stderr,
				"RMA %s not allowed with UU connections\n",
				opts.method == RMA_WRITE ? "WRITE" : "READ");
			print_usage();
		}
		if (opts.max_rma_size) {
			printf("ignoring max_rma_size (-m) with MSGs\n");
			opts.max_rma_size = 0;
		}
	} else {
		/* RO or RU */
		if (opts.flags == CCI_FLAG_NO_COPY) {
			printf("Ignoring CCI_FLAG_NO_COPY (-n) with RMA %s\n",
			       opts.method == RMA_WRITE ? "WRITE" : "READ");
			opts.flags &= ~(CCI_FLAG_NO_COPY);
		}
		if (!opts.max_rma_size)
			opts.max_rma_size = MAX_RMA_SIZE;
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, os_handle);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	if (blocking) {
		nfds = fd + 1;
		FD_ZERO(&rfds);
		FD_SET(fd, &rfds);
	}

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	if (buffer)
		free(buffer);

	free(uri);
	free(server_uri);

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}
Пример #6
0
int main(int argc, char *argv[])
{

	cci_os_handle_t *fd = NULL; //endpoint 생성시, process를 block하는데 사용
	cci_endpoint_t *endpoint = NULL;
	cci_connection_t *connection = NULL;
	int ret, c, ft_start = 0 , done = 0, i = 0, connect = 0;
    pthread_t send;	
	uint32_t caps = 0;//??
	char *server_uri = NULL;
	char id[16]="";
	t_data thread_data;

	while ((c = getopt(argc, argv, "h:c:b")) != -1) { //client 실행시 option check
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);//-h에 대한 인자를 가리키는  optarg 포인터가 생김 http://weed2758.tistory.com/entry/Linux-C-getopt-%ED%95%A8%EC%88%98
			break;
		case 'c':
			if (strncasecmp ("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp ("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else if (strncasecmp ("uu", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_UU;
			break;
		case 'b':
			flags |= CCI_FLAG_BLOCKING;
			break;
		default:
			fprintf(stderr, "usage: %s -h <server_uri> [-c <type>]\n",
			        argv[0]);
			fprintf(stderr, "\t-c\tConnection type (UU, RU, or RO) "
			                "set by client; RO by default\n");
			exit(EXIT_FAILURE);
		}
	}

	if (!server_uri) {
		fprintf(stderr, "usage: %s -h <server_uri> [-c <type>]\n", argv[0]);
		fprintf(stderr, "\t-c\tConnection type (UU, RU, or RO) "
                                        "set by client; RO by default\n");
		exit(EXIT_FAILURE);
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}


	if (ret) {
		fprintf(stderr, "cci_set_opt() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	/* initiate connect */
	ret = cci_connect(endpoint, server_uri, "Connect request", 15, attr, CONNECT_CONTEXT, 0, NULL);
	if (ret) {
		fprintf(stderr, "cci_connect() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}
	
    while (!done)
       poll_events(endpoint, &connection, &done, id);

    
	if (!connection)
		exit(0);

    done = 0;
    thread_data.connection=connection;
    thread_data.flag=flags;
    thread_data.id=id;
    pthread_create(&send,NULL,send_msg,&thread_data);

    while(!done)
       poll_events(endpoint, &connection, &done, id);

	pthread_join(send,NULL);

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}
Пример #7
0
int main (int argc, char *argv[])
{
	int ret, c;
	uint32_t caps	= 0;
	char *ctl_uri	= NULL;

	name = argv[0];

	while ((c = getopt (argc, argv, "h:s")) != -1) {
		switch (c) {
			case 'h':
				server_uri = strdup (optarg);
				break;
			case 's':
				is_server = 1;
				break;
			default:
				print_usage ();
		}
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
        if (ret) {
                fprintf(stderr, "cci_init() failed with %s\n",
                        cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);
        }

	/* Create the endpoint for the control connection */
	ret = cci_create_endpoint(NULL, 0, &ctl_ep, NULL);
	if (ret) {                                                              
                fprintf(stderr, "cci_create_endpoint() failed with %s\n",       
                        cci_strerror(NULL, ret));                               
                exit(EXIT_FAILURE);                                             
        }

	ret = cci_get_opt(ctl_ep,                                             
                          CCI_OPT_ENDPT_URI, &ctl_uri);                             
        if (ret) {                                                              
                fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);                                             
        }                                                                       
        printf("Opened control connection %s\n", ctl_uri);

	if (is_server)
		do_server ();
	else
		do_client ();

	ret = cci_destroy_endpoint (ctl_ep);
	if (ret) {
		fprintf (stderr, "cci_destroy_endpoint() failed with %s\n",
		         cci_strerror (NULL, ret));
		exit (EXIT_FAILURE);
	}

	free (server_uri);

	ret = cci_finalize ();
	if (ret) {
		fprintf (stderr, "cci_finalize() failed with %s\n",
		         cci_strerror (NULL, ret));
		exit (EXIT_FAILURE);
	}

	return 0;
}
Пример #8
0
Файл: server.c Проект: CCI/cci
int main(int argc, char *argv[])
{
	int ret, done = 0;
	uint32_t caps = 0;
	char *uri = NULL;
	cci_endpoint_t *endpoint = NULL;
	cci_os_handle_t *ep_fd = NULL;
	cci_connection_t *connection = NULL;

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, ep_fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	while (!done) {
		int accept = 1;
		cci_event_t *event;

		ret = cci_get_event(endpoint, &event);
		if (ret != 0) {
			if (ret != CCI_EAGAIN)
				fprintf(stderr, "cci_get_event() returned %s\n",
					cci_strerror(endpoint, ret));
			continue;
		}
		switch (event->type) {
		case CCI_EVENT_RECV:{
				char buf[8192];
				char *data = "data:";
				int offset = 0;
				int len = event->recv.len;

				assert(event->recv.connection == connection);
				assert(event->recv.connection->context == ACCEPT_CONTEXT);

				if (len == 3) {
					done = 1;
					continue;
				}

				memset(buf, 0, 8192);
				offset = strlen(data);
				memcpy(buf, data, offset);
				memcpy(buf + offset, event->recv.ptr, len);
				offset += len;
				fprintf(stderr, "recv'd \"%s\"\n", buf);
				ret =
				    cci_send(connection, buf, offset, SEND_CONTEXT, 0);
				if (ret)
					fprintf(stderr, "send returned %s\n",
						cci_strerror(endpoint, ret));
				break;
			}
		case CCI_EVENT_SEND:
			fprintf(stderr, "completed send\n");

			assert(event->send.context == SEND_CONTEXT);
			assert(event->send.connection == connection);
			assert(event->send.connection->context == ACCEPT_CONTEXT);

			break;
		case CCI_EVENT_CONNECT_REQUEST:
			/* inspect conn_req_t and decide to accept or reject */
			if (accept) {
				/* associate this connect request with this endpoint */
				cci_accept(event, ACCEPT_CONTEXT);
			} else {
				cci_reject(event);
			}
			break;
		case CCI_EVENT_ACCEPT:
			fprintf(stderr, "completed accept\n");

			assert(event->accept.connection != NULL);
			assert(event->accept.connection->context == ACCEPT_CONTEXT);

			connection = event->accept.connection;
			break;
		default:
			printf("event type %d\n", event->type);
			break;
		}
		cci_return_event(event);
	}

	/* clean up */
	cci_destroy_endpoint(endpoint);
	cci_finalize();
	free(uri);

	return 0;
}
Пример #9
0
int main(int argc, char *argv[])
{
	int ret, number_of_connections=0;
	int client_end[MAX_CONNECTION_SIZE]={0,};
	uint32_t caps = 0;
	char *uri = NULL;	
	long file_size[MAX_CONNECTION_SIZE]={0,};
	cci_endpoint_t *endpoint = NULL;
	cci_os_handle_t *ep_fd = NULL;
	cci_connection_t *connection[MAX_CONNECTION_SIZE] = {NULL,};   

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, ep_fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	while (1) { 
		int accept = 1;
		cci_event_t *event;		
		ret = cci_get_event(endpoint, &event);
		if (ret != 0) {
			if (ret != CCI_EAGAIN)
				fprintf(stderr, "cci_get_event() returned %s\n",
			cci_strerror(endpoint, ret));
			continue;
		}
		switch (event->type) {
			
		case CCI_EVENT_RECV:{
				char buf[MAX_BUFFER_SIZE];
				char *number, *data;
				char exit_msg[32];
				long read_size=0;
				int len = event->recv.len;				
				int i=0, j=0;
				int id;
				
				memset(buf, 0, MAX_BUFFER_SIZE);
				memcpy(buf, event->recv.ptr, len);	
				if(strncasecmp((char*)event->recv.ptr,"client", 6)==0){ /* 문자인 경우 */ 	
					fprintf(stderr, "%s", buf); 

					strtok(buf," :");	 /* 필요한 정보 파싱 (누구한테, 첫번째 문자)*/
					number=strtok(NULL," :");	
					data=strtok(NULL," :");	
					id=atoi(number); //누구한테서 왔는지

					memcpy(buf, event->recv.ptr, len);						
					if(event->recv.connection==connection[id-1]){
						if(strncasecmp(data,"bye\n", 4)==0){  //종료를 원할 경우 
		            		fprintf(stderr, "Client%d want to termainate this program.\n", id);
		            		client_end[id-1]=1;                      		       
			            }else if(strncasecmp(data,"file\n", 5)==0) //file 전송을 원할 경우			
							fprintf(stderr, "Client %d send a file...\n", id);		       
													
						for(j=0; j<number_of_connections; j++){
							if(j !=id-1 && !client_end[j]) //받는놈은 종료되지 않은놈이고 보내는놈이 아님
								ret = cci_send(connection[j], buf, len, SEND_CONTEXT, 0); //보냄	
							if(client_end[id-1]){  //보내는놈이 종료를 원한 경우
								sprintf(exit_msg,"client%d exits..\n", id);
								ret = cci_send(connection[j], exit_msg, strlen(exit_msg), SEND_CONTEXT, 0); //종료메세지 보냄	
							}
						} //end for j
					}
	            }else{   /* 파일인 경우 */	                 		
					for(i=0; i<number_of_connections; i++){ //어떤 connection에서 왔는지 check
						if(event->recv.connection == connection[i]){
							if(strncasecmp((char*)event->recv.ptr,"file send completed\0", 20)==0){ //file 전송종료신호면 그만				
								fprintf(stderr,"%s. file size is %ldbytes.\n",(char*)event->recv.ptr, file_size[i]);						
								memcpy(buf,event->recv.ptr, len); //종료신호 고대로 클라에게
								read_size=len;
								file_size[i]=0;
							}else{
								read_size=event->recv.len;	//읽은 크기 
								file_size[i]+=read_size; //file size check		
								fprintf(stderr, "%ld\n", file_size[i]);		
								memcpy(buf, event->recv.ptr, read_size); //읽은거 buf에 써주기			            			
							}//end file trasport
							for(j=0; j<number_of_connections; j++){ /* broadcast */
									if(j !=i && !client_end[j]){ 
										ret = cci_send(connection[j], buf, read_size, SEND_CONTEXT, 0); 
										if(ret)
											fprintf(stderr, "file send failed!\n");
									}
							}//end for j
							break;
	            		}//end if	            					
					}//end for i
	            }													
				break;
			}//end recv case

		case CCI_EVENT_SEND:

			assert(event->send.context == SEND_CONTEXT);
			assert(event->send.connection->context == ACCEPT_CONTEXT);
			fprintf(stderr, "completed send\n");
			break;

		case CCI_EVENT_CONNECT_REQUEST:
			if (accept) {
				cci_accept(event, ACCEPT_CONTEXT);
			}else {
				cci_reject(event);
			}
			break;

		case CCI_EVENT_ACCEPT:{
		    char number[MAX_CONNECTION_SIZE];

			assert(event->accept.connection != NULL);
			assert(event->accept.connection->context == ACCEPT_CONTEXT);
			
			connection[number_of_connections] = event->accept.connection;			
			fprintf(stderr, "completed accept\n");
		
            sprintf(number,"%d",number_of_connections+1);
            ret = cci_send(connection[number_of_connections], number, strlen(number), SEND_CONTEXT, 0); //몇번째 클라이언트 인지 알려줌
            number_of_connections++;
			break;
		}
		default:
			printf("event type %d\n", event->type);
			break;
		} //end switch

		cci_return_event(event);
	}

	/* clean up */
	cci_destroy_endpoint(endpoint);
	cci_finalize();
	free(uri);

	return 0;
}
Пример #10
0
int main(int argc, char *argv[])
{
	int done = 0, ret, i = 0, c;
	uint32_t caps = 0;
	char *server_uri = NULL;	/* ip://1.2.3.4 */
	char *uri = NULL;
	cci_os_handle_t fd;
	cci_endpoint_t *endpoint = NULL;
	cci_connection_t *connection = NULL;
	uint32_t timeout_us = 30 * 1000000;	/* microseconds */

	proc_name = argv[0];

	while ((c = getopt(argc, argv, "h:")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			break;
		default:
			usage();
		}
	}

	/* init */
	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() returned %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, &fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() returned %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	/* set endpoint tx timeout */
	cci_set_opt(endpoint, CCI_OPT_ENDPT_SEND_TIMEOUT,
		    &timeout_us);
	if (ret) {
		fprintf(stderr, "cci_set_opt() returned %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	/* initiate connect */
	ret = cci_connect(endpoint, server_uri, "Hello World!", 12,
			  CCI_CONN_ATTR_UU, NULL, 0, NULL);
	if (ret) {
		fprintf(stderr, "cci_connect() returned %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	/* poll for connect completion */
	while (!done)
		poll_events(endpoint, &connection, &done);

	if (!connection) {
		fprintf(stderr, "no connection\n");
		exit(EXIT_FAILURE);
	}

	/* begin communication with server */
	char *data;
	int max  = connection->max_send_size;
	data = (char*)malloc(max);
	memset(data, 1, sizeof(data));
	int len = 128;
	int repeat = 1000;
	while (len <= max) {
	  s = cci_get_time();
	  for (i = 0; i < repeat; i++) {
/* 		ret = cci_send(connection, data, (uint32_t) strlen(data), */
/* 			       (void *)(uintptr_t) i, 0); */

		ret = cci_send(connection, data, len,
			       (void *)(uintptr_t) i, 0);
		
 		if (ret > 0) {
		  fprintf(stderr, "send %d returned %s\n", i, 
			  cci_strerror(endpoint, ret)); 
		  exit(1);
		}

		done = 0;
		while (!done)
			poll_events(endpoint, &connection, &done);
	  }
	  e = cci_get_time();
	  fprintf(stderr, "%d %f %f\n", len, (e - s) / repeat, (len / (e - s)) * repeat);
	  len = len << 1;
	  sleep(1);
	}

	/* clean up */
	ret = cci_disconnect(connection);
	if (ret) {
		fprintf(stderr, "cci_disconnect() returned %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() returned %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	/* add cci_finalize() here */

	return 0;
}
Пример #11
0
int main(int argc, char *argv[])
{
	int ret;
	uint32_t caps = 0;
	char *uri = NULL;
	cci_endpoint_t *endpoint = NULL;
	cci_os_handle_t ep_fd;
	cci_connection_t *connection = NULL;

	/* init */
	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, &ep_fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	while (1) {

		cci_event_t *event;

		ret = cci_get_event(endpoint, &event);
		if (ret != CCI_SUCCESS) {
			if (ret != CCI_EAGAIN) {
				fprintf(stderr, "cci_get_event() returned %s",
					cci_strerror(endpoint, ret));
			}
			continue;
		}
/* 		fprintf(stderr, "ret: %d, event: %d (RECV:%d, SEND:%d, CONNECT_REQ:%d, ACCEPT:%d)\n", */
/*                         ret, event->type, CCI_EVENT_RECV, CCI_EVENT_SEND, CCI_EVENT_CONNECT_REQUEST, */
/*                         CCI_EVENT_ACCEPT); */
		fprintf(stderr, "Event: %s, ret:%d len: %lu\n", cci_event_type_str(event->type), ret, event->recv.len);
		switch (event->type) {
		case CCI_EVENT_RECV:
			{
			  //			  fprintf(stderr, "=====: %p %p %d\n", buffer, event->recv.ptr, event->recv.len);
			  //			  memcpy(buffer,
			  //				 event->recv.ptr, event->recv.len);
			  //			  fprintf(stderr, "=====\n");
			  //			  buffer[event->recv.len] = 0;
			  //			  printf("recv'd \n");
			  
			  /* echo the message to the client */
			  ret = cci_send(connection,
					 event->recv.ptr,
					 event->recv.len, NULL, 0);
			  if (ret != CCI_SUCCESS)
			    fprintf(stderr,
				    "send returned %s\n",
				    cci_strerror(endpoint, ret));
			  break;
			}
		case CCI_EVENT_SEND:
		  //			printf("completed send\n");
			break;
		case CCI_EVENT_CONNECT_REQUEST:
			{
				int accept = 1;

				if (accept) {
					ret = cci_accept(event, NULL);
					if (ret != CCI_SUCCESS) {
						fprintf(stderr,
							"cci_accept() returned %s",
							cci_strerror(endpoint, ret));
					}

				} else {
					cci_reject(event);
				}
			}
			break;
		case CCI_EVENT_ACCEPT:
			connection = event->accept.connection;
			if (!buffer) {
				buffer = calloc(1, connection->max_send_size + 1);
				fprintf(stderr, "allocated buffer: %p , size %d", buffer, connection->max_send_size + 1);
				/* check for buffer ... */
			} else {
			  fprintf(stderr, "Not allocated\n");
			}
			break;
		default:
			fprintf(stderr, "unexpected event %d", event->type);
			break;
		}
		cci_return_event(event);
	}

	/* clean up */
	cci_destroy_endpoint(endpoint);
	/* add cci_finalize() here */

	return 0;
}
Пример #12
0
Файл: client.c Проект: CCI/cci
int main(int argc, char *argv[])
{
	int done = 0, ret, i = 0, c;
	uint32_t caps = 0;
	char *server_uri = NULL;
	cci_os_handle_t *fd = NULL;
	cci_endpoint_t *endpoint = NULL;
	cci_connection_t *connection = NULL;
	uint32_t timeout = 30 * 1000000;

	while ((c = getopt(argc, argv, "h:c:b")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			break;
		case 'c':
			if (strncasecmp ("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp ("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else if (strncasecmp ("uu", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_UU;
			break;
		case 'b':
			flags |= CCI_FLAG_BLOCKING;
			break;
		default:
			fprintf(stderr, "usage: %s -h <server_uri> [-c <type>]\n",
			        argv[0]);
			fprintf(stderr, "\t-c\tConnection type (UU, RU, or RO) "
			                "set by client; RO by default\n");
			exit(EXIT_FAILURE);
		}
	}

	if (!server_uri) {
		fprintf(stderr, "usage: %s -h <server_uri> [-c <type>]\n", argv[0]);
		fprintf(stderr, "\t-c\tConnection type (UU, RU, or RO) "
                                        "set by client; RO by default\n");
		exit(EXIT_FAILURE);
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* set conn tx timeout */
	cci_set_opt(endpoint, CCI_OPT_ENDPT_SEND_TIMEOUT,
		    &timeout);
	if (ret) {
		fprintf(stderr, "cci_set_opt() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	/* initiate connect */
	ret =
	    cci_connect(endpoint, server_uri, "Hello World!", 12,
			attr, CONNECT_CONTEXT, 0, NULL);
	if (ret) {
		fprintf(stderr, "cci_connect() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	/* poll for connect completion */
	while (!done)
		poll_events(endpoint, &connection, &done);

	if (!connection)
		exit(0);

	done = 0;

	/* begin communication with server */
	for (i = 0; i < iters; i++) {
		char data[128];

		memset(data, 0, sizeof(data));
		sprintf(data, "%4d", i);
		sprintf(data + 4, "Hello World!");
		ret = cci_send(connection, data, (uint32_t) strlen(data) + 4,
			       (void *)(uintptr_t) i, flags);
		if (ret)
			fprintf(stderr, "send %d failed with %s\n", i,
				cci_strerror(endpoint, ret));
		if (flags & CCI_FLAG_BLOCKING)
			fprintf(stderr, "send %d completed with %d\n", i, ret);

	}
	if (flags == CCI_FLAG_BLOCKING)
		send_done = iters;

	while (!done)
		poll_events(endpoint, &connection, &done);

	ret = cci_send(connection, "bye", 3, (void *)(uintptr_t) iters, flags);
	if (ret)
		fprintf(stderr, "sending \"bye\" failed with %s\n",
			cci_strerror(endpoint, ret));

	if (flags & CCI_FLAG_BLOCKING)
		done = 2;

	while (done != 2)
		poll_events(endpoint, &connection, &done);

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(endpoint, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}
Пример #13
0
void server()
{
	int ret, context, num_request = 0, num_accept = 0;
	uint32_t caps = 0;
	char *uri = NULL;
	cci_endpoint_t *endpoint = NULL;
	cci_os_handle_t *ep_fd = NULL;
	cci_connection_t *connection = NULL;

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, ep_fd);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	printf("Opened %s\n", uri);
	fflush(stdout);

	while (num_request < 3 || num_accept < 1) {
		cci_event_t *event;

		ret = cci_get_event(endpoint, &event);
		if (ret != 0) {
			if (ret != CCI_EAGAIN)
				fprintf(stderr, "cci_get_event() returned %s\n",
					cci_strerror(endpoint, ret));
			continue;
		}
		switch (event->type) {
		case CCI_EVENT_CONNECT_REQUEST:
			fprintf(stderr, "connect request\n");
			num_request++;
			/* accept the first, reject the second, let the third timeout */
			if (num_request == 1) {
				context = 123;
				cci_accept(event, (int *) &context);
			} else if (num_request == 2 && 0) { /* XXX: cci_reject segfaults */
				cci_reject(event);
			} 
			break;
		case CCI_EVENT_ACCEPT:
			fprintf(stderr, "completed accept\n");
			connection = event->accept.connection;
			context = *(int *) event->accept.context;
			printf("CCI_EVENT_ACCEPT: %d\n", context);
			num_accept++;
			break;
		default:
			fprintf(stderr, "ignoring event type %d\n", event->type);
		}
		cci_return_event(event);
	}

	printf("Pausing while client times out...\n");
        sleep(5);

	printf("test passed\n");
	fflush(stdout);

server_cleanup:
        ret = cci_destroy_endpoint(endpoint);
        if (ret) {
                fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
                        cci_strerror(endpoint, ret));
                exit(EXIT_FAILURE);
        }

        ret = cci_finalize();
        if (ret) {
                fprintf(stderr, "cci_finalize() failed with %s\n",
                        cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);
        }
	free(uri);
}
Пример #14
0
void client(char *server_uri)
{
	int num_connect = 0, ret, i = 0, c;
        uint32_t caps = 0;
        cci_os_handle_t *fd = NULL;
        cci_endpoint_t *endpoint = NULL;
        cci_connection_t *connection = NULL;
        uint32_t timeout = 10 * 1000000;
        int context[3] = {0, 1, 2};
        struct timeval wait;

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
        if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
                        cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
        }

        /* create an endpoint */
        ret = cci_create_endpoint(NULL, 0, &endpoint, fd);
        if (ret) {
                fprintf(stderr, "cci_create_endpoint() failed with %s\n",
                        cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);
        }

        /* set conn tx timeout */
        cci_set_opt(endpoint, CCI_OPT_ENDPT_SEND_TIMEOUT,
                    &timeout);
        if (ret) {
                fprintf(stderr, "cci_set_opt() failed with %s\n",
                        cci_strerror(endpoint, ret));
                exit(EXIT_FAILURE);
        }

        ret = cci_connect(endpoint, server_uri, "Happy", 5,
                        CCI_CONN_ATTR_UU, (int *) &context[0], 0, NULL);
	if (ret) {
                fprintf(stderr, "cci_connect(0) failed with %s\n",
                        cci_strerror(endpoint, ret));
        } 

        ret = cci_connect(endpoint, server_uri, "New", 3,
                        CCI_CONN_ATTR_UU, (int *) &context[1], 0, NULL);
	if (ret) {
                fprintf(stderr, "cci_connect(1) failed with %s\n",
                        cci_strerror(endpoint, ret));
        } 

        wait.tv_sec = 2;
        wait.tv_usec = 0;
        ret = cci_connect(endpoint, server_uri, "Year", 4,
                        CCI_CONN_ATTR_UU, (int *) &context[2], 0, &wait);
	if (ret) {
                fprintf(stderr, "cci_connect(2) failed with %s\n",
                        cci_strerror(endpoint, ret));
        } 

        /* poll for connect completion */
        //while (num_connect < 3)
	while (num_connect < 1) /* connect timeouts are not registering */
                poll_events(endpoint, &connection, &num_connect);

	printf("test passed\n");
	fflush(stdout);

	/* server has to close first to avoid hang */
	sleep(5);

client_cleanup:
        ret = cci_destroy_endpoint(endpoint);
        if (ret) {
                fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
                        cci_strerror(endpoint, ret));
                exit(EXIT_FAILURE);
        }

        ret = cci_finalize();
        if (ret) {
                fprintf(stderr, "cci_finalize() failed with %s\n",
                        cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);
        }
}