List:Commits« Previous MessageNext Message »
From:ahristov Date:August 13 2007 7:19pm
Subject:PHP mysqlnd svn commit: r889 - trunk/mysqlnd
View as plain text  
Author: ahristov
Date: 2007-08-13 19:19:31 +0200 (Mon, 13 Aug 2007)
New Revision: 889

Modified:
   trunk/mysqlnd/mysqlnd.c
   trunk/mysqlnd/mysqlnd.h
   trunk/mysqlnd/mysqlnd_debug.c
   trunk/mysqlnd/mysqlnd_priv.h
   trunk/mysqlnd/mysqlnd_wireprotocol.c
Log:
A little bit of fix for mysqlnd_debug - parsing now
should work better.

Setting state to QUIT_SENT if the connection is broken.


Modified: trunk/mysqlnd/mysqlnd.c
===================================================================
--- trunk/mysqlnd/mysqlnd.c	2007-08-13 15:16:17 UTC (rev 888)
+++ trunk/mysqlnd/mysqlnd.c	2007-08-13 17:19:31 UTC (rev 889)
@@ -60,7 +60,7 @@
 
 
 
-static const char * mysqlnd_server_gone = "MySQL server has gone away";
+const char * mysqlnd_server_gone = "MySQL server has gone away";
 const char * mysqlnd_out_of_sync = "Commands out of sync; you can't run this command
now";
 
 MYSQLND_STATS *mysqlnd_global_stats = NULL;
@@ -373,6 +373,7 @@
 			DBG_ERR_FMT("Error while sending %s packet", mysqlnd_command_to_text[command]);
 			php_error(E_WARNING, "Error while sending %s packet. PID=%d",
mysqlnd_command_to_text[command], getpid());
 		}
+		conn->state = CONN_QUIT_SENT;
 		SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE,
mysqlnd_server_gone);
 		DBG_ERR("Server is gone");
 		ret = FAIL;
@@ -599,7 +600,11 @@
 
 	conn->scramble = auth_packet->server_scramble_buf = pemalloc(SCRAMBLE_LENGTH,
conn->persistent);
 	memcpy(auth_packet->server_scramble_buf, greet_packet.scramble_buf, SCRAMBLE_LENGTH);
-	PACKET_WRITE(auth_packet, conn);
+	if (!PACKET_WRITE(auth_packet, conn)) {
+		conn->state = CONN_QUIT_SENT;
+		SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE,
mysqlnd_server_gone);
+		goto err;	
+	}
 
 	if (FAIL == PACKET_READ_ALLOCA(ok_packet, conn) || ok_packet.field_count >= 0xFE) {
 		if (ok_packet.field_count == 0xFE) {
@@ -1071,9 +1076,13 @@
 
 	MYSQLND_INC_CONN_STATISTIC(NULL, stat);
 
-	mysqlnd_send_close(conn TSRMLS_CC);
+	/*
+	  Close now, free_reference will try,
+	  if we are last, but that's not a problem.
+	*/
+	ret = mysqlnd_send_close(conn TSRMLS_CC);
 
-	conn->m->free_reference(conn TSRMLS_CC);
+	ret = conn->m->free_reference(conn TSRMLS_CC);
 
 	DBG_RETURN(ret);
 }
@@ -1091,9 +1100,10 @@
 
 
 /* {{{ mysqlnd_conn::free_reference */
-static void
+static enum_func_status
 MYSQLND_METHOD_PRIVATE(mysqlnd_conn, free_reference)(MYSQLND * const conn TSRMLS_DC)
 {
+	enum_func_status ret = PASS;
 	DBG_ENTER("mysqlnd_conn::free_reference");
 	DBG_INF_FMT("conn->refcount=%u", conn->refcount);
 	if (!(--conn->refcount)) {
@@ -1102,10 +1112,10 @@
 		  This will free the object too, of course because references has
 		  reached zero.
 		*/
-		mysqlnd_send_close(conn TSRMLS_CC);
+		ret = mysqlnd_send_close(conn TSRMLS_CC);
 		conn->m->dtor(conn TSRMLS_CC);
 	}
-	DBG_VOID_RETURN;
+	DBG_RETURN(ret);
 }
 /* }}} */
 
@@ -1793,13 +1803,16 @@
  */
 static PHP_RINIT_FUNCTION(mysqlnd)
 {
-	if (MYSQLND_G(dbg)) {
+#ifdef PHP_DEBUG
+	if (MYSQLND_G(debug)) {
 		MYSQLND_DEBUG *dbg = mysqlnd_debug_init(TSRMLS_C);
 		if (!dbg) {
 			return FAILURE;
 		}
+		dbg->m->set_mode(dbg, MYSQLND_G(debug));
 		MYSQLND_G(dbg) = dbg;	
 	}
+#endif
 	return SUCCESS;
 }
 /* }}} */
@@ -1809,11 +1822,13 @@
  */
 static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
 {
+#ifdef PHP_DEBUG
 	MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
 	if (dbg) {
 		dbg->m->close(dbg);
 		dbg->m->free(dbg);
 	}
+#endif
 	return SUCCESS;
 }
 /* }}} */

Modified: trunk/mysqlnd/mysqlnd.h
===================================================================
--- trunk/mysqlnd/mysqlnd.h	2007-08-13 15:16:17 UTC (rev 888)
+++ trunk/mysqlnd/mysqlnd.h	2007-08-13 17:19:31 UTC (rev 889)
@@ -382,7 +382,7 @@
 	void				(*dtor)(MYSQLND *conn TSRMLS_DC);	/* private */
 
 	MYSQLND *			(*get_reference)(MYSQLND * const conn);
-	void				(*free_reference)(MYSQLND * const conn TSRMLS_DC);
+	enum_func_status	(*free_reference)(MYSQLND * const conn TSRMLS_DC);
 };
 
 

Modified: trunk/mysqlnd/mysqlnd_debug.c
===================================================================
--- trunk/mysqlnd/mysqlnd_debug.c	2007-08-13 15:16:17 UTC (rev 888)
+++ trunk/mysqlnd/mysqlnd_debug.c	2007-08-13 17:19:31 UTC (rev 889)
@@ -292,16 +292,17 @@
 			case 'o':
 			case 'O':
 				if (mode[i+1] == ',') {
-					unsigned int j = i + 2, endpos = i + 1;
+					unsigned int j = i + 2;
 					while (j < mode_len) {
-						if (j == ':') {
-							endpos = j - 1;
+						if (mode[j] == ':') {
 							break;
 						}
+						j++;
 					}
-					if (endpos > i + 1) {
-						self->file_name = estrndup(mode + i + 2, endpos - i - 1);
+					if (j > i + 2) {
+						self->file_name = estrndup(mode + i + 2, j - i - 2);
 					}
+					i = j;
 				} else {
 					self->file_name = (char *) mysqlnd_debug_default_trace_file;
 				}
@@ -347,18 +348,19 @@
 				break;
 			case 't':
 				if (mode[i+1] == ',') {
-					unsigned int j = i + 2, endpos = i + 1;
+					unsigned int j = i + 2;
 					while (j < mode_len) {
-						if (j == ':') {
-							endpos = j - 1;
+						if (mode[j] == ':') {
 							break;
 						}
+						j++;
 					}
-					if (endpos > i + 1) {
-						char *value_str = estrndup(mode + i + 2, endpos - i - 1);
+					if (j > i + 2) {
+						char *value_str = estrndup(mode + i + 2, j - i - 2);
 						self->nest_level_limit = atoi(value_str);
 						efree(value_str);
 					}
+					i = j;
 				} else {
 					self->flags |= MYSQLND_DEBUG_DUMP_TRACE;
 				}
@@ -414,14 +416,21 @@
 
 void _mysqlnd_debug(const char *mode TSRMLS_DC)
 {
+#ifdef PHP_DEBUG
 	MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
-	if (dbg) {
-		dbg->m->close(dbg);
-		dbg->m->set_mode(dbg, mode);
-		while (zend_stack_count(&dbg->call_stack)) {
-			zend_stack_del_top(&dbg->call_stack);
+	if (!dbg) {
+		MYSQLND_G(dbg) = dbg = mysqlnd_debug_init(TSRMLS_C);
+		if (!dbg) {
+			return;
 		}
 	}
+	
+	dbg->m->close(dbg);
+	dbg->m->set_mode(dbg, mode);
+	while (zend_stack_count(&dbg->call_stack)) {
+		zend_stack_del_top(&dbg->call_stack);
+	}
+#endif
 }
 
 /*

Modified: trunk/mysqlnd/mysqlnd_priv.h
===================================================================
--- trunk/mysqlnd/mysqlnd_priv.h	2007-08-13 15:16:17 UTC (rev 888)
+++ trunk/mysqlnd/mysqlnd_priv.h	2007-08-13 17:19:31 UTC (rev 889)
@@ -164,6 +164,7 @@
 extern struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
 
 extern const char * mysqlnd_out_of_sync;
+extern const char * mysqlnd_server_gone;
 
 
 enum_func_status mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename,
zend_bool *is_warning TSRMLS_DC);

Modified: trunk/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- trunk/mysqlnd/mysqlnd_wireprotocol.c	2007-08-13 15:16:17 UTC (rev 888)
+++ trunk/mysqlnd/mysqlnd_wireprotocol.c	2007-08-13 17:19:31 UTC (rev 889)
@@ -43,6 +43,8 @@
 #define	PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_size, packet_type) \
 	{ \
 		if (FAIL == mysqlnd_read_header((conn), &((packet)->header) TSRMLS_CC)) {\
+			conn->state = CONN_QUIT_SENT; \
+			SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE,
mysqlnd_server_gone);\
 			DBG_ERR_FMT("Can't read %s's header", (packet_type)); \
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't read %s's header. PID=%d", \
 							 (packet_type), getpid());\
@@ -57,6 +59,8 @@
 		}\
 		if (!mysqlnd_read_body((conn), (buf), \
 							   MIN((buf_size), (packet)->header.size) TSRMLS_CC)) { \
+			conn->state = CONN_QUIT_SENT; \
+			SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE,
mysqlnd_server_gone);\
 			DBG_ERR_FMT("Empty %s packet body", (packet_type)); \
 			php_error(E_WARNING, "Empty %s packet body. PID=%d", (packet_type), getpid());\
 			return FAIL; \

Thread
PHP mysqlnd svn commit: r889 - trunk/mysqlndahristov13 Aug