1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

removed ma_errmsg from mysql.h

This commit is contained in:
Georg Richter
2016-11-16 17:27:59 +01:00
parent 3378c0d8b7
commit a499722377
4 changed files with 94 additions and 101 deletions

View File

@@ -60,7 +60,6 @@ typedef int my_socket;
#include "mariadb_version.h" #include "mariadb_version.h"
#include "ma_list.h" #include "ma_list.h"
#include "mariadb_ctype.h" #include "mariadb_ctype.h"
#include "ma_errmsg.h"
#ifndef ST_MA_USED_MEM_DEFINED #ifndef ST_MA_USED_MEM_DEFINED
#define ST_MA_USED_MEM_DEFINED #define ST_MA_USED_MEM_DEFINED

View File

@@ -1,26 +1,26 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2012-2016 SkySQL AB, MariaDB Corporation AB 2012-2016 SkySQL AB, MariaDB Corporation AB
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details. Library General Public License for more details.
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */ MA 02111-1307, USA */
/* Write and read of logical packets to/from socket /* Write and read of logical packets to/from socket
** Writes are cached into net_buffer_length big packets. ** Writes are cached into net_buffer_length big packets.
** Read packets are reallocated dynamicly when reading big packets. ** Read packets are reallocated dynamicly when reading big packets.
** Each logical packet has the following pre-info: ** Each logical packet has the following pre-info:
** 3 byte length & 1 byte package-number. ** 3 byte length & 1 byte package-number.
*/ */
#include <ma_global.h> #include <ma_global.h>
@@ -43,7 +43,7 @@
/* net_buffer_length and max_allowed_packet are defined in mysql.h /* net_buffer_length and max_allowed_packet are defined in mysql.h
See bug conc-57 See bug conc-57
*/ */
#undef net_buffer_length #undef net_buffer_length
#undef max_allowed_packet #undef max_allowed_packet
@@ -68,15 +68,15 @@ ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */
/* /*
** Give error if a too big packet is found ** Give error if a too big packet is found
** The server can change this with the -O switch, but because the client ** The server can change this with the -O switch, but because the client
** can't normally do this the client should have a bigger max-buffer. ** can't normally do this the client should have a bigger max-buffer.
*/ */
static int ma_net_write_buff(NET *net,const char *packet, size_t len); static int ma_net_write_buff(NET *net,const char *packet, size_t len);
/* Init with packet info */ /* Init with packet info */
int ma_net_init(NET *net, MARIADB_PVIO* pvio) int ma_net_init(NET *net, MARIADB_PVIO* pvio)
{ {
@@ -98,7 +98,7 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)
net->compress_pkt_nr= net->pkt_nr= 0; net->compress_pkt_nr= net->pkt_nr= 0;
net->write_pos=net->read_pos = net->buff; net->write_pos=net->read_pos = net->buff;
net->last_error[0]= net->sqlstate[0] =0; net->last_error[0]= net->sqlstate[0] =0;
net->compress=0; net->reading_or_writing=0; net->compress=0; net->reading_or_writing=0;
net->where_b = net->remain_in_buf=0; net->where_b = net->remain_in_buf=0;
net->last_errno=0; net->last_errno=0;
@@ -135,7 +135,7 @@ static my_bool net_realloc(NET *net, size_t length)
/* reallocate buffer: /* reallocate buffer:
size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */
if (!(buff=(uchar*) realloc(net->buff, if (!(buff=(uchar*) realloc(net->buff,
pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE)))
{ {
net->error=1; net->error=1;
return(1); return(1);
@@ -167,7 +167,7 @@ int ma_net_flush(NET *net)
if (net->buff != net->write_pos) if (net->buff != net->write_pos)
{ {
error=ma_net_real_write(net,(char*) net->buff, error=ma_net_real_write(net,(char*) net->buff,
(size_t) (net->write_pos - net->buff)); (size_t) (net->write_pos - net->buff));
net->write_pos=net->buff; net->write_pos=net->buff;
} }
if (net->compress) if (net->compress)
@@ -176,18 +176,17 @@ int ma_net_flush(NET *net)
} }
/***************************************************************************** /*****************************************************************************
** Write something to server/client buffer ** Write something to server/client buffer
*****************************************************************************/ *****************************************************************************/
/* /*
** Write a logical packet with packet header ** Write a logical packet with packet header
** Format: Packet length (3 bytes), packet number(1 byte) ** Format: Packet length (3 bytes), packet number(1 byte)
** When compression is used a 3 byte compression length is added ** When compression is used a 3 byte compression length is added
** NOTE: If compression is used the original package is destroyed! ** NOTE: If compression is used the original package is destroyed!
*/ */
int int ma_net_write(NET *net, const uchar *packet, size_t len)
ma_net_write(NET *net, const uchar *packet, size_t len)
{ {
uchar buff[NET_HEADER_SIZE]; uchar buff[NET_HEADER_SIZE];
while (len >= MAX_PACKET_LENGTH) while (len >= MAX_PACKET_LENGTH)
@@ -210,10 +209,9 @@ ma_net_write(NET *net, const uchar *packet, size_t len)
return 0; return 0;
} }
int int ma_net_write_command(NET *net, uchar command,
ma_net_write_command(NET *net, uchar command, const char *packet, size_t len,
const char *packet, size_t len, my_bool disable_flush)
my_bool disable_flush)
{ {
uchar buff[NET_HEADER_SIZE+1]; uchar buff[NET_HEADER_SIZE+1];
size_t buff_size= NET_HEADER_SIZE + 1; size_t buff_size= NET_HEADER_SIZE + 1;
@@ -230,7 +228,7 @@ ma_net_write_command(NET *net, uchar command,
{ {
int3store(buff, MAX_PACKET_LENGTH); int3store(buff, MAX_PACKET_LENGTH);
buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++);
if (ma_net_write_buff(net, (char *)buff, buff_size) || if (ma_net_write_buff(net, (char *)buff, buff_size) ||
ma_net_write_buff(net, packet, len)) ma_net_write_buff(net, packet, len))
return(1); return(1);
@@ -244,15 +242,14 @@ ma_net_write_command(NET *net, uchar command,
int3store(buff,length); int3store(buff,length);
buff[3]= (net->compress) ? 0 :(uchar) (net->pkt_nr++); buff[3]= (net->compress) ? 0 :(uchar) (net->pkt_nr++);
rc= test (ma_net_write_buff(net,(char *)buff, buff_size) || rc= test (ma_net_write_buff(net,(char *)buff, buff_size) ||
ma_net_write_buff(net,packet,len)); ma_net_write_buff(net,packet,len));
if (!rc && !disable_flush) if (!rc && !disable_flush)
return test(ma_net_flush(net)); return test(ma_net_flush(net));
return rc; return rc;
} }
static int static int ma_net_write_buff(NET *net,const char *packet, size_t len)
ma_net_write_buff(NET *net,const char *packet, size_t len)
{ {
size_t left_length; size_t left_length;
@@ -268,7 +265,7 @@ ma_net_write_buff(NET *net,const char *packet, size_t len)
{ {
memcpy((char*) net->write_pos,packet,left_length); memcpy((char*) net->write_pos,packet,left_length);
if (ma_net_real_write(net,(char*) net->buff, if (ma_net_real_write(net,(char*) net->buff,
(size_t)(net->write_pos - net->buff) + left_length)) (size_t)(net->write_pos - net->buff) + left_length))
return 1; return 1;
packet+=left_length; packet+=left_length;
len-=left_length; len-=left_length;
@@ -299,8 +296,7 @@ unsigned char *mysql_net_store_length(unsigned char *packet, size_t length);
/* Read and write using timeouts */ /* Read and write using timeouts */
int int ma_net_real_write(NET *net, const char *packet, size_t len)
ma_net_real_write(NET *net,const char *packet,size_t len)
{ {
ssize_t length; ssize_t length;
char *pos,*end; char *pos,*end;
@@ -357,66 +353,66 @@ ma_net_real_write(NET *net,const char *packet,size_t len)
} }
/***************************************************************************** /*****************************************************************************
** Read something from server/clinet ** Read something from server/clinet
*****************************************************************************/ *****************************************************************************/
static ulong static ulong ma_real_read(NET *net, size_t *complen)
ma_real_read(NET *net, size_t *complen)
{ {
uchar *pos; uchar *pos;
ssize_t length; ssize_t length;
uint i; uint i;
ulong len=packet_error; ulong len=packet_error;
size_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : size_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE); NET_HEADER_SIZE);
*complen = 0; *complen = 0;
net->reading_or_writing=1; net->reading_or_writing=1;
pos = net->buff + net->where_b; /* net->packet -4 */ pos = net->buff + net->where_b; /* net->packet -4 */
for (i=0 ; i < 2 ; i++) for (i=0 ; i < 2 ; i++)
{
while (remain > 0)
{ {
while (remain > 0) /* First read is done with non blocking mode */
if ((length=ma_pvio_cache_read(net->pvio, pos,remain)) <= 0L)
{ {
/* First read is done with non blocking mode */ len= packet_error;
if ((length=ma_pvio_cache_read(net->pvio, pos,remain)) <= 0L) net->error=2; /* Close socket */
{ goto end;
len= packet_error;
net->error=2; /* Close socket */
goto end;
}
remain -= (ulong) length;
pos+= (ulong) length;
} }
if (i == 0) remain -= (ulong) length;
{ /* First parts is packet length */ pos+= (ulong) length;
ulong helping; }
net->pkt_nr= net->buff[net->where_b + 3];
net->compress_pkt_nr= ++net->pkt_nr; if (i == 0)
{ /* First parts is packet length */
ulong helping;
net->pkt_nr= net->buff[net->where_b + 3];
net->compress_pkt_nr= ++net->pkt_nr;
#ifdef HAVE_COMPRESS #ifdef HAVE_COMPRESS
if (net->compress) if (net->compress)
{ {
/* complen is > 0 if package is really compressed */ /* complen is > 0 if package is really compressed */
*complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE])); *complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE]));
} }
#endif #endif
len=uint3korr(net->buff+net->where_b); len=uint3korr(net->buff+net->where_b);
if (!len) if (!len)
goto end;
helping = max(len,(ulong)*complen) + net->where_b;
/* The necessary size of net->buff */
if (helping >= net->max_packet)
{
if (net_realloc(net, helping))
{
len= packet_error; /* Return error */
goto end; goto end;
helping = max(len,(ulong)*complen) + net->where_b; }
/* The necessary size of net->buff */
if (helping >= net->max_packet)
{
if (net_realloc(net, helping))
{
len= packet_error; /* Return error */
goto end;
}
}
pos=net->buff + net->where_b;
remain = len;
} }
pos=net->buff + net->where_b;
remain = len;
} }
}
end: end:
net->reading_or_writing=0; net->reading_or_writing=0;
@@ -457,23 +453,23 @@ ulong ma_net_read(NET *net)
else else
{ {
/* /*
compressed protocol: compressed protocol:
-------------------------------------- --------------------------------------
packet_lengt h 3 packet_length 3
sequence_id 1 sequence_id 1
uncompressed_length 3 uncompressed_length 3
-------------------------------------- --------------------------------------
compressed data packet_length - 7 compressed data packet_length - 7
-------------------------------------- --------------------------------------
Another packet will follow if: Another packet will follow if:
packet_length == MAX_PACKET_LENGTH packet_length == MAX_PACKET_LENGTH
Last package will be identified by Last package will be identified by
- packet_length is zero (special case) - packet_length is zero (special case)
- packet_length < MAX_PACKET_LENGTH - packet_length < MAX_PACKET_LENGTH
*/ */
size_t packet_length, size_t packet_length,
buffer_length; buffer_length;
@@ -517,8 +513,8 @@ ulong ma_net_read(NET *net)
{ {
/* remove packet_header */ /* remove packet_header */
memmove(net->buff + current, memmove(net->buff + current,
net->buff + current + 4, net->buff + current + 4,
buffer_length - current); buffer_length - current);
buffer_length-= 4; buffer_length-= 4;
current+= packet_length; current+= packet_length;
} }
@@ -533,7 +529,7 @@ ulong ma_net_read(NET *net)
if (start) if (start)
{ {
memmove(net->buff, net->buff + start, memmove(net->buff, net->buff + start,
buffer_length - start); buffer_length - start);
/* decrease buflen*/ /* decrease buflen*/
buffer_length-= start; buffer_length-= start;
start= 0; start= 0;
@@ -579,12 +575,13 @@ ulong ma_net_read(NET *net)
} }
int net_add_multi_command(NET *net, uchar command, const uchar *packet, int net_add_multi_command(NET *net, uchar command, const uchar *packet,
size_t length) size_t length)
{ {
if (net->extension->multi_status == COM_MULTI_OFF) if (net->extension->multi_status == COM_MULTI_OFF)
{ {
return(1); return(1);
} }
/* don't increase packet number */
net->compress_pkt_nr= net->pkt_nr= 0; net->compress_pkt_nr= net->pkt_nr= 0;
return ma_net_write_command(net, command, (const char *)packet, length, 1); return ma_net_write_command(net, command, (const char *)packet, length, 1);
} }

View File

@@ -193,7 +193,7 @@ restart:
my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
CR_NET_PACKET_TOO_LARGE: CR_NET_PACKET_TOO_LARGE:
CR_SERVER_LOST, CR_SERVER_LOST,
SQLSTATE_UNKNOWN, 0); SQLSTATE_UNKNOWN, 0, errno);
return(packet_error); return(packet_error);
} }
if (net->read_pos[0] == 255) if (net->read_pos[0] == 255)

View File

@@ -129,12 +129,9 @@ static int bulk1(MYSQL *mysql)
mysql_free_result(res); mysql_free_result(res);
FAIL_IF(intval != array_size - 1, "Expected max value 1024"); FAIL_IF(intval != array_size - 1, "Expected max value 1024");
/*
rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1"); rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1");
check_mysql_rc(rc, mysql); check_mysql_rc(rc, mysql);
*/
return OK; return OK;
} }
static int bulk2(MYSQL *mysql) static int bulk2(MYSQL *mysql)