static void cubrid_conn_free(void *p) { Connection *c = (Connection *)p; T_CCI_ERROR error; if (c->handle) { cci_disconnect(c->handle, &error); c->handle = 0; } free(p); }
/* call-seq: * close() -> nil * * 데이터베이스와의 연결을 헤제합니다. 이 연결로부터 생성된 Statement도 모두 close됩니다. */ VALUE cubrid_conn_close(VALUE self) { Connection *c; T_CCI_ERROR error; GET_CONN_STRUCT(self, c); if (c->handle) { cci_disconnect(c->handle, &error); c->handle = 0; } return Qnil; }
int CubTest(){ int nColCount = 0, nLen = 0; int i = 0, nDB = 0, nRet = 0, nReq = 0; char *pszBuff = NULL; T_CCI_COL_INFO *pcciCol; T_CCI_SQLX_CMD cciCmdType; assert((nDB = cci_connect(DB_SERVER, DB_PORT, DB_NAME, DB_USER_ID, DB_USER_PW)) >= 0); assert((nReq = cci_prepare(nDB, "SELECT * FROM athlete", 0, &cciErr)) >= 0); assert((pcciCol = cci_get_result_info(nReq, &cciCmdType, &nColCount)) != NULL); for (i = 1; i <= nColCount; i++) { printf("%s\t", CCI_GET_RESULT_INFO_NAME(pcciCol, i)); } printf("\n"); assert(cci_execute(nReq, 0, 0, &cciErr) >= 0); while (1) { if ( cci_cursor(nReq, 1, CCI_CURSOR_CURRENT, &cciErr) == CCI_ER_NO_MORE_DATA ) break; assert(cci_fetch(nReq, &cciErr) >= 0); for (i = 1; i<= nColCount; i++) { assert(cci_get_data(nReq, i, CCI_A_TYPE_STR, &pszBuff, &nLen) >= 0); printf("%s\t", pszBuff); } printf("\n"); } assert(cci_close_req_handle(nReq) >= 0); assert(cci_disconnect(nDB, &cciErr) >= 0); return 0; }
void DbDisconnect(int nDB){ cci_disconnect(nDB, NULL); }
static void poll_events(void) { int ret; cci_event_t *event; if (blocking) { FD_ZERO(&rfds); FD_SET(fd, &rfds); ret = select(nfds, &rfds, NULL, NULL, NULL); if (!ret) return; } ret = cci_get_event(endpoint, &event); if (ret == CCI_SUCCESS) { assert(event); switch (event->type) { case CCI_EVENT_SEND: if (event->send.status != CCI_SUCCESS) { fprintf(stderr, "RMA failed with %s.\n", cci_strerror(endpoint, event->send.status)); cci_disconnect(test); test = NULL; done = 1; } if (is_server) break; /* Client */ if (event->send.context == (void *)0xdeadbeef) { done = 1; break; } break; case CCI_EVENT_RECV: if (is_client) { hdr_t *h = (void*)event->recv.ptr; if (!ready) { ready = 1; memcpy((void*)&remote_rma_handle, &h->reply.handle, sizeof(remote_rma_handle)); } else { /* RMA status msg */ if (opts.method == RMA_WRITE) { if (h->status.crc != msg.check.crc) { fprintf(stderr, "Server reported " "CRC failed.\n" "Local CRC 0x%x != " "remote CRC 0x%x.\n" "count=%d current_size=%u\n", msg.check.crc, h->status.crc, count, current_size); } } else { uint32_t crc = 0; void *ptr = (void*)((uintptr_t)buffer + local_offset); /* Compute the CRC only on a valid buffer */ if (current_size + local_offset <= opts.reg_len) crc = crc32(0, ptr, current_size); else crc = 0; if (crc != h->status.crc) { fprintf(stderr, "Server reported " "CRC failed.\n" "Local CRC 0x%x != " "remote CRC 0x%x.\n" "count=%d current_size=%u\n", crc, h->status.crc, count, current_size); } } /* RMA completed */ count++; if (count < iters) { ret = cci_rma(test, &msg, msg_len, local_rma_handle, local_offset, &remote_rma_handle, remote_offset, current_size, NULL, opts.flags); check_return(endpoint, "cci_rma", ret, 1); } } } else { hdr_t *h = (void*)event->recv.ptr; /* is_server */ if (event->recv.len == 3) { done = 1; } else { uint32_t crc = 0; void *ptr = (void*)((uintptr_t)buffer + h->check.offset); /* RMA check request */ if ((h->check.len + h->check.offset) <= opts.reg_len) crc = crc32(0, ptr, h->check.len); else crc = 0; msg.status.type = MSG_RMA_STATUS; msg.status.crc = crc; if (opts.method == RMA_WRITE) { fprintf(stderr, "server: client crc=0x%x " "server crc=0x%x\n", h->check.crc, crc); } print_buffer(ptr, h->check.len); ret = cci_send(test, &msg, sizeof(msg.status), NULL, CCI_FLAG_SILENT); check_return(endpoint, "cci_send", ret, 1); } } break; case CCI_EVENT_CONNECT: if (event->connect.status != CCI_SUCCESS) { fprintf(stderr, "Connection rejected.\n"); exit(0); } if ((uintptr_t)event->connect.context == (uintptr_t)CONTROL) { control = event->connect.connection; } else { test = event->connect.connection; } if (control && test) connect_done = 1; break; case CCI_EVENT_CONNECT_REQUEST: fprintf(stderr, "Peer is reconnecting? Rejecting.\n"); cci_reject(event); break; default: fprintf(stderr, "ignoring event type %s\n", cci_event_type_str(event->type)); } cci_return_event(event); } return; }
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; }