END_TEST START_TEST (set_opt_invalid_option) { uint32_t initFlags = 0; uint32_t capabilities = 0; uint32_t status = 0; cci_device_t const ** const devices = NULL; /* available device structure */ cci_endpoint_t* endpointP = NULL; /* pointer to endpoint structure */ int32_t deviceFlags = 0; /* not yet implemented */ cci_os_handle_t fd; /* endpoint handle */ cci_opt_handle_t *optHandle; int32_t* option; /* 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)); /* create an endpoint. For now, simply use the first device - remember that fd can be used in select() */ status = cci_create_endpoint((cci_device_t*) *devices, deviceFlags, &endpointP, &fd); fail_unless(status == CCI_SUCCESS, "cci_create_endpoint() failed with status %s", cci_strerror(NULL, status)); /* get an endpoint option */ optHandle = endpointP; status = cci_set_opt(optHandle, 100, (void*) &option, sizeof(option)); fail_unless(status == CCI_EINVAL, "cci_set_opt failed with status %s\n", cci_strerror(NULL, status)); }
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; }
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; }
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); } }