CVS update: php3/functions
| From: | tommay | Date: | Tue, 03 Nov 1998 01:42:31 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-2137@lists.php.net to get a copy of this message | ||
Date: Monday November 2, 1998 @ 20:42
Author: tommay
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv23276/functions
Modified Files:
sybase-ct.c
Log Message:
sybase_pconnect() now detects and attempts to reopen dead connections.
sybase_pconnect() and sybase_connect() no longer leak CS_CONNECTIONs when
reusing existing connections.
Added error messages for the various failure points while connecting.
Index: php3/functions/sybase-ct.c
diff -c php3/functions/sybase-ct.c:1.45 php3/functions/sybase-ct.c:1.46
*** php3/functions/sybase-ct.c:1.45 Mon Nov 2 20:03:28 1998
--- php3/functions/sybase-ct.c Mon Nov 2 20:42:30 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: sybase-ct.c,v 1.45 1998/11/03 01:03:28 tommay Exp $ */
#ifndef MSVC5
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: sybase-ct.c,v 1.46 1998/11/03 01:42:30 tommay Exp $ */
#ifndef MSVC5
***************
*** 243,248 ****
--- 243,284 ----
return SUCCESS;
}
+
+ static int _php3_sybct_really_connect(sybct_link *sybct, char *host, char *user, char *passwd)
+ {
+ /* set a CS_CONNECTION record */
+ if (ct_con_alloc(context, &sybct->connection)!=CS_SUCCEED) {
+ php3_error(E_WARNING,"Sybase: Unable to allocate connection record");
+ return 0;
+ }
+
+ if (user) {
+ ct_con_props(sybct->connection, CS_SET, CS_USERNAME, user, CS_NULLTERM, NULL);
+ }
+ if (passwd) {
+ ct_con_props(sybct->connection, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL);
+ }
+ ct_con_props(sybct->connection, CS_SET, CS_APPNAME, php3_sybct_module.appname, CS_NULLTERM,
NULL);
+ sybct->valid = 1;
+
+ /* create the link */
+ if (ct_connect(sybct->connection, host, CS_NULLTERM)!=CS_SUCCEED) {
+ php3_error(E_WARNING,"Sybase: Unable to connect");
+ ct_con_drop(sybct->connection);
+ return 0;
+ }
+
+ if (ct_cmd_alloc(sybct->connection,&sybct->cmd)!=CS_SUCCEED) {
+ php3_error(E_WARNING,"Sybase: Unable to allocate command record");
+ ct_close(sybct->connection,CS_UNUSED);
+ ct_con_drop(sybct->connection);
+ return 0;
+ }
+
+ return 1;
+ }
+
+
static void php3_sybct_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
{
char *user,*passwd,*host;
***************
*** 313,333 ****
}
- /* set a CS_CONNECTION record */
- if (ct_con_alloc(context, &sybct.connection)!=CS_SUCCEED) {
- php3_error(E_WARNING,"Sybase: Unable to allocate connection record");
- RETURN_FALSE;
- }
-
- if (user) {
- ct_con_props(sybct.connection, CS_SET, CS_USERNAME, user, CS_NULLTERM, NULL);
- }
- if (passwd) {
- ct_con_props(sybct.connection, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL);
- }
- ct_con_props(sybct.connection, CS_SET, CS_APPNAME, php3_sybct_module.appname, CS_NULLTERM, NULL);
- sybct.valid = 1;
-
if (!php3_sybct_module.allow_persistent) {
persistent=0;
}
--- 349,354 ----
***************
*** 341,366 ****
if (php3_sybct_module.max_links!=-1 &&
php3_sybct_module.num_links>=php3_sybct_module.max_links) {
php3_error(E_WARNING,"Sybase: Too many open links
(%d)",php3_sybct_module.num_links);
efree(hashed_details);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
if (php3_sybct_module.max_persistent!=-1 &&
php3_sybct_module.num_persistent>=php3_sybct_module.max_persistent) {
php3_error(E_WARNING,"Sybase: Too many open persistent links
(%d)",php3_sybct_module.num_persistent);
efree(hashed_details);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
- /* create the link */
- if (ct_connect(sybct.connection, host, CS_NULLTERM)!=CS_SUCCEED) {
- efree(hashed_details);
- ct_con_drop(sybct.connection);
- RETURN_FALSE;
- }
! if (ct_cmd_alloc(sybct.connection,&sybct.cmd)!=CS_SUCCEED) {
efree(hashed_details);
- ct_close(sybct.connection,CS_UNUSED);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
--- 362,377 ----
if (php3_sybct_module.max_links!=-1 &&
php3_sybct_module.num_links>=php3_sybct_module.max_links) {
php3_error(E_WARNING,"Sybase: Too many open links
(%d)",php3_sybct_module.num_links);
efree(hashed_details);
RETURN_FALSE;
}
if (php3_sybct_module.max_persistent!=-1 &&
php3_sybct_module.num_persistent>=php3_sybct_module.max_persistent) {
php3_error(E_WARNING,"Sybase: Too many open persistent links
(%d)",php3_sybct_module.num_persistent);
efree(hashed_details);
RETURN_FALSE;
}
! if (!_php3_sybct_really_connect(&sybct, host, user, passwd)) {
efree(hashed_details);
RETURN_FALSE;
}
***************
*** 370,404 ****
new_le.type = php3_sybct_module.le_plink;
new_le.ptr = sybct_ptr;
if (_php3_hash_update(plist, hashed_details, hashed_details_length+1, (void *) &new_le,
sizeof(list_entry),NULL)==FAILURE) {
free(sybct_ptr);
efree(hashed_details);
- ct_close(sybct.connection, CS_UNUSED);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
php3_sybct_module.num_persistent++;
php3_sybct_module.num_links++;
} else { /* we do */
if (le->type != php3_sybct_module.le_plink) {
RETURN_FALSE;
}
sybct_ptr = (sybct_link *) le->ptr;
! /* test that the link hasn't died */
! /* No clue how to do it with CT-lib...
! if (DBDEAD(sybct_ptr->link)==TRUE) {
! if (dbopen(sybct_ptr->login,host)==FAIL) {
! _php3_hash_del(plist, hashed_details, hashed_details_length+1);
! efree(hashed_details);
! RETURN_FALSE;
}
! if (dbsetopt(sybct_ptr->link,DBBUFFER,"2",-1)==FAIL) {
! _php3_hash_del(plist, hashed_details, hashed_details_length+1);
efree(hashed_details);
RETURN_FALSE;
}
}
- */
}
return_value->value.lval = php3_list_insert(sybct_ptr,php3_sybct_module.le_plink);
return_value->type = IS_LONG;
--- 381,430 ----
new_le.type = php3_sybct_module.le_plink;
new_le.ptr = sybct_ptr;
if (_php3_hash_update(plist, hashed_details, hashed_details_length+1, (void *) &new_le,
sizeof(list_entry),NULL)==FAILURE) {
+ ct_close(sybct_ptr->connection, CS_UNUSED);
+ ct_con_drop(sybct_ptr->connection);
free(sybct_ptr);
efree(hashed_details);
RETURN_FALSE;
}
php3_sybct_module.num_persistent++;
php3_sybct_module.num_links++;
} else { /* we do */
+ CS_INT con_status;
+
if (le->type != php3_sybct_module.le_plink) {
+ efree(hashed_details);
RETURN_FALSE;
}
sybct_ptr = (sybct_link *) le->ptr;
!
! /* If the link has died, close it and overwrite it with a new one. */
!
! if (ct_con_props(sybct_ptr->connection, CS_GET, CS_CON_STATUS,
! &con_status, CS_UNUSED, NULL)!=CS_SUCCEED) {
! php3_error(E_WARNING,"Sybase: Unable to get connection status");
! efree(hashed_details);
! RETURN_FALSE;
! }
! if (!(con_status & CS_CONSTAT_CONNECTED) || (con_status & CS_CONSTAT_DEAD)) {
! if (con_status & CS_CONSTAT_CONNECTED) {
! ct_close(sybct_ptr->connection, CS_UNUSED);
}
! /* Create a new connection, then replace the old
! * connection. If we fail to create a new connection,
! * leave the old one so there will be a connection,
! * even if it is a non-functional one. This is because
! * code may still be holding an id for this connection
! * so we can't free the CS_CONNECTION.
! */
! if (!_php3_sybct_really_connect(&sybct, host, user, passwd)) {
efree(hashed_details);
RETURN_FALSE;
}
+ ct_con_drop(sybct_ptr->connection);
+ memcpy(sybct_ptr,&sybct,sizeof(sybct_link));
}
}
return_value->value.lval = php3_list_insert(sybct_ptr,php3_sybct_module.le_plink);
return_value->type = IS_LONG;
***************
*** 415,420 ****
--- 441,447 ----
void *ptr;
if (index_ptr->type != le_index_ptr) {
+ efree(hashed_details);
RETURN_FALSE;
}
link = (int) index_ptr->ptr;
***************
*** 431,454 ****
if (php3_sybct_module.max_links!=-1 &&
php3_sybct_module.num_links>=php3_sybct_module.max_links) {
php3_error(E_WARNING,"Sybase: Too many open links
(%d)",php3_sybct_module.num_links);
efree(hashed_details);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
-
- if (ct_connect(sybct.connection,host,CS_NULLTERM)!=CS_SUCCEED) {
- efree(hashed_details);
- ct_con_drop(sybct.connection);
- RETURN_FALSE;
- }
! if (ct_cmd_alloc(sybct.connection,&sybct.cmd)!=CS_SUCCEED) {
efree(hashed_details);
- ct_close(sybct.connection,CS_UNUSED);
- ct_con_drop(sybct.connection);
RETURN_FALSE;
}
-
/* add it to the list */
sybct_ptr = (sybct_link *) emalloc(sizeof(sybct_link));
memcpy(sybct_ptr,&sybct,sizeof(sybct_link));
--- 458,471 ----
if (php3_sybct_module.max_links!=-1 &&
php3_sybct_module.num_links>=php3_sybct_module.max_links) {
php3_error(E_WARNING,"Sybase: Too many open links
(%d)",php3_sybct_module.num_links);
efree(hashed_details);
RETURN_FALSE;
}
! if (!_php3_sybct_really_connect(&sybct, host, user, passwd)) {
efree(hashed_details);
RETURN_FALSE;
}
/* add it to the list */
sybct_ptr = (sybct_link *) emalloc(sizeof(sybct_link));
memcpy(sybct_ptr,&sybct,sizeof(sybct_link));
***************
*** 459,464 ****
--- 476,484 ----
new_index_ptr.ptr = (void *) return_value->value.lval;
new_index_ptr.type = le_index_ptr;
if (_php3_hash_update(list,hashed_details,hashed_details_length+1,(void *) &new_index_ptr,
sizeof(list_entry),NULL)==FAILURE) {
+ ct_close(sybct_ptr->connection, CS_UNUSED);
+ ct_con_drop(sybct_ptr->connection);
+ free(sybct_ptr);
efree(hashed_details);
RETURN_FALSE;
}
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net