int connect_pool_perisent(cpClient** cli, zval* zres, int port) { zend_rsrc_list_entry sock_le; int ret; (*cli) = (cpClient*) pecalloc(sizeof (cpClient), 1, 1); if (cpClient_create((*cli)) < 0) { zend_error(E_ERROR, "pdo_connect_pool: create sock fail. Error: %s [%d]", strerror(errno), errno); } (*cli)->port = port; ret = cpClient_connect((*cli), "127.0.0.1", (*cli)->port, (float) 100, 0); //所有的操作100s超时 if (ret < 0) { pefree(*cli, 1); return -1; } sock_le.type = le_cli_connect_pool; sock_le.ptr = (*cli); ZEND_REGISTER_RESOURCE(zres, (*cli), le_cli_connect_pool); char str[100] = {0}; CON_FORMART_KEY(str, (*cli)->port); zend_hash_update(&EG(persistent_list), str, strlen(str), (void*) &sock_le, sizeof (zend_rsrc_list_entry), NULL); return 1; }
static void* connect_pool_perisent(zval* zres, zval* data_source) { // cpLog_init("/tmp/pool_client.log"); zend_rsrc_list_entry sock_le; int ret; cpClient* cli = (cpClient*) pecalloc(sizeof (cpClient), 1, 1); if (cpClient_create(cli) < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "pdo_connect_pool: create sock fail. Error: %s [%d]", strerror(errno), errno); } ret = cpClient_connect(cli, "127.0.0.1", 6253, (float) 100, 0); //所有的操作100s超时 if (ret < 0) { pefree(cli, 1); return NULL; } sock_le.type = le_cli_connect_pool; sock_le.ptr = cli; ZEND_REGISTER_RESOURCE(zres, cli, le_cli_connect_pool); zend_hash_update(&EG(persistent_list), Z_STRVAL_P(data_source), Z_STRLEN_P(data_source), (void*) &sock_le, sizeof (zend_rsrc_list_entry), NULL); cli->lock = cpMutexLock; cli->unLock = cpMutexUnLock; cpTcpEvent event = {0}; event.type = CP_TCPEVENT_GETFD; cpClient_send(cli->sock, (char *) &event, sizeof (event), 0); cpMasterInfo info; ret = cpClient_recv(cli->sock, &info, sizeof (cpMasterInfo), 1); if (ret < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "recv from pool server error [%d],%s", errno, strerror(errno)); } cli->server_fd = info.server_fd; cpClient_attach_mem(); CONN(cli)->release = CP_FD_RELEASED; return cli; }
void* connect_pool_perisent(zval* zres, int port) { zend_rsrc_list_entry sock_le; int ret; cpClient* cli = (cpClient*) pecalloc(sizeof (cpClient), 1, 1); if (cpClient_create(cli) < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "pdo_connect_pool: create sock fail. Error: %s [%d]", strerror(errno), errno); } cli->port = port; ret = cpClient_connect(cli, "127.0.0.1", cli->port, (float) 100, 0); //所有的操作100s超时 if (ret < 0) { pefree(cli, 1); return NULL; } sock_le.type = le_cli_connect_pool; sock_le.ptr = cli; ZEND_REGISTER_RESOURCE(zres, cli, le_cli_connect_pool); char str[100] = {0}; CON_FORMART_KEY(str, cli->port); zend_hash_update(&EG(persistent_list), str, strlen(str), (void*) &sock_le, sizeof (zend_rsrc_list_entry), NULL); return cli; }