New version for gw_mysql_close()

This commit is contained in:
Massimiliano Pinto
2013-06-10 15:11:03 +02:00
parent 3413f29e5a
commit ac08cb4368

View File

@ -34,7 +34,7 @@ Massimiliano Pinto
#include "session.h" #include "session.h"
#define MYSQL_CONN_DEBUG #define MYSQL_CONN_DEBUG
#undef MYSQL_CONN_DEBUG //#undef MYSQL_CONN_DEBUG
int mysql_send_ok(int fd, int packet_number, int in_affected_rows, const char* mysql_message) { int mysql_send_ok(int fd, int packet_number, int in_affected_rows, const char* mysql_message) {
int n = 0; int n = 0;
@ -737,33 +737,32 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, char *passw
// free data scructure // free data scructure
////////////////////////////////////// //////////////////////////////////////
void gw_mysql_close(MySQLProtocol **ptr) { void gw_mysql_close(MySQLProtocol **ptr) {
int rv; MySQLProtocol *conn = *ptr;
uint8_t packet_buffer[5];
MySQLProtocol *conn = *ptr;
if (conn == NULL) if (*ptr == NULL)
return; return;
if (conn->fd > 0) { fprintf(stderr, "Closing MySQL connection %i, [%s]\n", conn->fd, conn->scramble);
if (conn->fd > 0) {
//write COM_QUIT //write COM_QUIT
//write //write
#ifdef MYSQL_CONN_DEBUG #ifdef MYSQL_CONN_DEBUG
fprintf(stderr, "mysqlgw_mysql_close() called for %i\n", conn->fd); fprintf(stderr, "mysqlgw_mysql_close() called for %i\n", conn->fd);
#endif #endif
close(conn->fd); close(conn->fd);
} else { } else {
#ifdef MYSQL_CONN_DEBUG #ifdef MYSQL_CONN_DEBUG
fprintf(stderr, "mysqlgw_mysql_close() called, no socket\n"); fprintf(stderr, "mysqlgw_mysql_close() called, no socket %i\n", conn->fd);
#endif #endif
} }
if (conn != NULL) { free(*ptr);
free(conn);
#ifdef MYSQL_CONN_DEBUG
fprintf(stderr, "mysqlgw_mysql_close() free(conn)\n");
#endif
}
*ptr = NULL;
#ifdef MYSQL_CONN_DEBUG
fprintf(stderr, "mysqlgw_mysql_close() free(conn)\n");
#endif
} }