diff --git a/include/errmsg.h b/include/errmsg.h index 7ca3238a..8a7a718c 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -101,7 +101,11 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_BULK_WITHOUT_PARAMETERS 5006 #define CR_INVALID_STMT 5007 #define CR_VERSION_MISMATCH 5008 +#define CR_ERR_NET_READ 5013 +#define CR_ERR_NET_WRITE 5014 +#define CR_ERR_NET_UNCOMPRESS 5015 + /* Always last, if you add new error codes please update the value for CR_MARIADB_LAST_ERROR */ -#define CR_MARIADB_LAST_ERROR CR_VERSION_MISMATCH +#define CR_MARIADB_LAST_ERROR CR_ERR_NET_UNCOMPRESS #endif diff --git a/libmariadb/ma_errmsg.c b/libmariadb/ma_errmsg.c index 6f11f7cc..fe8eea9e 100644 --- a/libmariadb/ma_errmsg.c +++ b/libmariadb/ma_errmsg.c @@ -159,6 +159,13 @@ const char *mariadb_client_errors[] = /* 5006 */ "Bulk operation without parameters is not supported", /* 5007 */ "Invalid statement handle", /* 5008 */ "Unsupported version %d. Supported versions are in the range %d - %d", + /* 5009 */ "", + /* 5010 */ "", + /* 5011 */ "", + /* 5012 */ "", + /* 5013 */ "Read error: %s (%d)", + /* 5014 */ "Write error: %s (%d)", + /* 5015 */ "Error while uncompressing packet", "" }; diff --git a/libmariadb/ma_net.c b/libmariadb/ma_net.c index 680369b3..3451bf70 100644 --- a/libmariadb/ma_net.c +++ b/libmariadb/ma_net.c @@ -29,7 +29,7 @@ #include #include #include "mysql.h" -#include "ma_server_error.h" +#include "errmsg.h" #include #include #include @@ -125,7 +125,7 @@ static my_bool net_realloc(NET *net, size_t length) if (length >= net->max_packet_size) { net->error=1; - net->last_errno=ER_NET_PACKET_TOO_LARGE; + net->pvio->set_error(net->pvio->mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0); return(1); } pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); @@ -313,7 +313,7 @@ int ma_net_real_write(NET *net, const char *packet, size_t len) uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1))) { - net->last_errno=ER_OUT_OF_RESOURCES; + net->pvio->set_error(net->pvio->mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); net->error=2; net->reading_or_writing=0; return(1); @@ -337,8 +337,13 @@ int ma_net_real_write(NET *net, const char *packet, size_t len) { if ((length=ma_pvio_write(net->pvio,(uchar *)pos,(size_t) (end-pos))) <= 0) { + int save_errno= errno; + char errmsg[100]; + net->error=2; /* Close socket */ - net->last_errno= ER_NET_ERROR_ON_WRITE; + strerror_r(save_errno, errmsg, 100); + net->pvio->set_error(net->pvio->mysql, CR_ERR_NET_WRITE, SQLSTATE_UNKNOWN, 0, + errmsg, save_errno); net->reading_or_writing=0; #ifdef HAVE_COMPRESS if (net->compress) @@ -557,8 +562,7 @@ ulong ma_net_read(NET *net) if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) { net->error=2; /* caller will close socket */ - net->last_errno=ER_NET_UNCOMPRESS_ERROR; - break; + net->pvio->set_error(net->pvio->mysql, CR_ERR_NET_UNCOMPRESS, SQLSTATE_UNKNOWN, 0); return packet_error; } buffer_length+= complen; diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index fe24af5e..fe8d35e6 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -1680,7 +1680,8 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon goto fail; if (!is_multi && mysql->net.extension->multi_status == COM_MULTI_ENABLED) - ma_multi_command(mysql, COM_MULTI_END); + if (ma_multi_command(mysql, COM_MULTI_END)) + goto fail; if (mysql->net.extension->multi_status > COM_MULTI_OFF) return 0; diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index a7631dc8..624c5945 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -685,7 +685,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused))) SKIP_SKYSQL; SKIP_MAXSCALE; -// SKIP_TLS; + SKIP_TLS; mysql= mysql_init(NULL); mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout);