Commit 25ca5723 authored by unknown's avatar unknown

Manual merge of the 4.0.24 compile changes into the 4.1 tree.


include/my_sys.h:
  Auto merged
mysys/hash.c:
  Manually merged: 'static' for all, 'inline' for most platforms.
parents ae81d530 32773212
...@@ -189,11 +189,13 @@ void __CDECL hfree(void *ptr); ...@@ -189,11 +189,13 @@ void __CDECL hfree(void *ptr);
#endif #endif
#endif /* MSDOS */ #endif /* MSDOS */
#ifndef errno /* did we already get it? */
#ifdef HAVE_ERRNO_AS_DEFINE #ifdef HAVE_ERRNO_AS_DEFINE
#include <errno.h> /* errno is a define */ #include <errno.h> /* errno is a define */
#else #else
extern int errno; /* declare errno */ extern int errno; /* declare errno */
#endif #endif
#endif /* #ifndef errno */
extern const char ** NEAR my_errmsg[]; extern const char ** NEAR my_errmsg[];
extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
extern char *home_dir; /* Home directory for user */ extern char *home_dir; /* Home directory for user */
......
...@@ -175,7 +175,7 @@ static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax, ...@@ -175,7 +175,7 @@ static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax,
/* for compilers which can not handle inline */ /* for compilers which can not handle inline */
static static
#if !defined(__SUNPRO_C) && !defined(__USLC__) && !defined(__sgi) #if !defined(__USLC__) && !defined(__sgi)
inline inline
#endif #endif
unsigned int rec_hashnr(HASH *hash,const byte *record) unsigned int rec_hashnr(HASH *hash,const byte *record)
......
...@@ -16,18 +16,7 @@ ...@@ -16,18 +16,7 @@
/* /*
Handling of uchar arrays as large bitmaps. Handling of uchar arrays as large bitmaps.
We assume that the size of the used bitmap is less than ~(uint) 0
API limitations (or, rather asserted safety assumptions,
to encourage correct programming)
* the size of the used bitmap is less than ~(uint) 0
* it's a multiple of 8 (for efficiency reasons)
* when arguments are a bitmap and a bit number, the number
must be within bitmap size
* bitmap_set_prefix() is an exception - one can use ~0 to set all bits
* when both arguments are bitmaps, they must be of the same size
* bitmap_intersect() is an exception :)
(for for Bitmap::intersect(ulonglong map2buff))
TODO: TODO:
Make assembler THREAD safe versions of these using test-and-set instructions Make assembler THREAD safe versions of these using test-and-set instructions
...@@ -35,76 +24,60 @@ ...@@ -35,76 +24,60 @@
#include "mysys_priv.h" #include "mysys_priv.h"
#include <my_bitmap.h> #include <my_bitmap.h>
#include <assert.h>
#include <m_string.h> #include <m_string.h>
static inline void bitmap_lock(MY_BITMAP* map)
static inline void bitmap_lock(MY_BITMAP *map)
{ {
#ifdef THREAD #ifdef THREAD
if (map->mutex) if (map->thread_safe)
pthread_mutex_lock(map->mutex); pthread_mutex_lock(&map->mutex);
#endif #endif
} }
static inline void bitmap_unlock(MY_BITMAP* map)
static inline void bitmap_unlock(MY_BITMAP *map)
{ {
#ifdef THREAD #ifdef THREAD
if (map->mutex) if (map->thread_safe)
pthread_mutex_unlock(map->mutex); pthread_mutex_unlock(&map->mutex);
#endif #endif
} }
my_bool bitmap_init(MY_BITMAP *map, uint bitmap_size, my_bool thread_safe)
my_bool bitmap_init(MY_BITMAP *map, uchar *buf, uint bitmap_size,
my_bool thread_safe)
{ {
DBUG_ENTER("bitmap_init"); if (!(map->bitmap=(uchar*) my_malloc((bitmap_size+7)/8,
DBUG_ASSERT((bitmap_size & 7) == 0);
bitmap_size/=8;
if (!(map->bitmap=buf) &&
!(map->bitmap= (uchar*) my_malloc(bitmap_size +
(thread_safe ?
sizeof(pthread_mutex_t) : 0),
MYF(MY_WME | MY_ZEROFILL)))) MYF(MY_WME | MY_ZEROFILL))))
return 1; return 1;
map->bitmap_size=bitmap_size; DBUG_ASSERT(bitmap_size != ~(uint) 0);
#ifdef THREAD #ifdef THREAD
if (thread_safe) if ((map->thread_safe = thread_safe))
{ pthread_mutex_init(&map->mutex, MY_MUTEX_INIT_FAST);
map->mutex=(pthread_mutex_t *)(map->bitmap+bitmap_size);
pthread_mutex_init(map->mutex, MY_MUTEX_INIT_FAST);
}
else
map->mutex=0;
#endif #endif
DBUG_RETURN(0); map->bitmap_size=bitmap_size;
return 0;
} }
void bitmap_free(MY_BITMAP *map) void bitmap_free(MY_BITMAP *map)
{ {
DBUG_ENTER("bitmap_free");
if (map->bitmap) if (map->bitmap)
{ {
#ifdef THREAD
if (map->mutex)
pthread_mutex_destroy(map->mutex);
#endif
my_free((char*) map->bitmap, MYF(0)); my_free((char*) map->bitmap, MYF(0));
map->bitmap=0; map->bitmap=0;
#ifdef THREAD
if (map->thread_safe)
pthread_mutex_destroy(&map->mutex);
#endif
} }
DBUG_VOID_RETURN;
} }
void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit) void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit)
{ {
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8); if (bitmap_bit < map->bitmap_size)
{
bitmap_lock(map); bitmap_lock(map);
bitmap_fast_set_bit(map, bitmap_bit); map->bitmap[bitmap_bit / 8] |= (1 << (bitmap_bit & 7));
bitmap_unlock(map); bitmap_unlock(map);
}
} }
...@@ -112,10 +85,9 @@ uint bitmap_set_next(MY_BITMAP *map) ...@@ -112,10 +85,9 @@ uint bitmap_set_next(MY_BITMAP *map)
{ {
uchar *bitmap=map->bitmap; uchar *bitmap=map->bitmap;
uint bit_found = MY_BIT_NONE; uint bit_found = MY_BIT_NONE;
uint bitmap_size=map->bitmap_size*8; uint bitmap_size=map->bitmap_size;
uint i; uint i;
DBUG_ASSERT(map->bitmap);
bitmap_lock(map); bitmap_lock(map);
for (i=0; i < bitmap_size ; i++, bitmap++) for (i=0; i < bitmap_size ; i++, bitmap++)
{ {
...@@ -141,191 +113,32 @@ uint bitmap_set_next(MY_BITMAP *map) ...@@ -141,191 +113,32 @@ uint bitmap_set_next(MY_BITMAP *map)
void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit) void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit)
{ {
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8); if (bitmap_bit < map->bitmap_size)
bitmap_lock(map); {
bitmap_fast_clear_bit(map, bitmap_bit);
bitmap_unlock(map);
}
void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size)
{
uint prefix_bytes, prefix_bits;
DBUG_ASSERT(map->bitmap &&
(prefix_size <= map->bitmap_size*8 || prefix_size == (uint) ~0));
bitmap_lock(map); bitmap_lock(map);
set_if_smaller(prefix_size, map->bitmap_size*8); map->bitmap[bitmap_bit / 8] &= ~ (1 << (bitmap_bit & 7));
if ((prefix_bytes= prefix_size / 8))
memset(map->bitmap, 0xff, prefix_bytes);
if ((prefix_bits= prefix_size & 7))
map->bitmap[prefix_bytes++]= (1 << prefix_bits)-1;
if (prefix_bytes < map->bitmap_size)
bzero(map->bitmap+prefix_bytes, map->bitmap_size-prefix_bytes);
bitmap_unlock(map); bitmap_unlock(map);
}
void bitmap_clear_all(MY_BITMAP *map)
{
bitmap_set_prefix(map, 0);
}
void bitmap_set_all(MY_BITMAP *map)
{
bitmap_set_prefix(map, ~0);
}
my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size)
{
uint prefix_bits= prefix_size & 7, res= 0;
uchar *m= map->bitmap, *end_prefix= map->bitmap+prefix_size/8,
*end= map->bitmap+map->bitmap_size;
DBUG_ASSERT(map->bitmap && prefix_size <= map->bitmap_size*8);
bitmap_lock((MY_BITMAP *)map);
while (m < end_prefix)
if (*m++ != 0xff)
goto ret;
if (prefix_bits && *m++ != (1 << prefix_bits)-1)
goto ret;
while (m < end)
if (*m++ != 0)
goto ret;
res=1;
ret:
bitmap_unlock((MY_BITMAP *)map);
return res;
}
my_bool bitmap_is_clear_all(const MY_BITMAP *map)
{
return bitmap_is_prefix(map, 0);
}
my_bool bitmap_is_set_all(const MY_BITMAP *map)
{
return bitmap_is_prefix(map, map->bitmap_size*8);
}
my_bool bitmap_is_set(const MY_BITMAP *map, uint bitmap_bit)
{
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8);
return bitmap_fast_is_set(map, bitmap_bit);
}
my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2)
{
uint res=0;
uchar *m1=map1->bitmap, *m2=map2->bitmap, *end;
DBUG_ASSERT(map1->bitmap && map2->bitmap &&
map1->bitmap_size==map2->bitmap_size);
bitmap_lock((MY_BITMAP *)map1);
bitmap_lock((MY_BITMAP *)map2);
end= m1+map1->bitmap_size;
while (m1 < end)
{
if ((*m1++) & ~(*m2++))
goto ret;
} }
res=1;
ret:
bitmap_unlock((MY_BITMAP *)map2);
bitmap_unlock((MY_BITMAP *)map1);
return res;
} }
my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2) void bitmap_set_all(MY_BITMAP* map)
{ {
uint res;
DBUG_ASSERT(map1->bitmap && map2->bitmap &&
map1->bitmap_size==map2->bitmap_size);
bitmap_lock((MY_BITMAP *)map1);
bitmap_lock((MY_BITMAP *)map2);
res= memcmp(map1->bitmap, map2->bitmap, map1->bitmap_size)==0;
bitmap_unlock((MY_BITMAP *)map2);
bitmap_unlock((MY_BITMAP *)map1);
return res;
}
void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2)
{
uchar *to=map->bitmap, *from=map2->bitmap, *end;
uint len=map->bitmap_size, len2=map2->bitmap_size;
DBUG_ASSERT(map->bitmap && map2->bitmap);
bitmap_lock(map); bitmap_lock(map);
bitmap_lock((MY_BITMAP *)map2); memset(map->bitmap, 0xff, (map->bitmap_size+7)/8);
end= to+min(len,len2);
while (to < end)
*to++ &= *from++;
if (len2 < len)
{
end+=len-len2;
while (to < end)
*to++=0;
}
bitmap_unlock((MY_BITMAP *)map2);
bitmap_unlock(map); bitmap_unlock(map);
} }
my_bool bitmap_is_set(MY_BITMAP* map, uint bitmap_bit)
void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2)
{ {
uchar *to=map->bitmap, *from=map2->bitmap, *end; return (bitmap_bit < map->bitmap_size) ?
(map->bitmap[bitmap_bit / 8] & (1 << (bitmap_bit & 7))) :
DBUG_ASSERT(map->bitmap && map2->bitmap && 0;
map->bitmap_size==map2->bitmap_size);
bitmap_lock(map);
bitmap_lock((MY_BITMAP *)map2);
end= to+map->bitmap_size;
while (to < end)
*to++ &= ~(*from++);
bitmap_unlock((MY_BITMAP *)map2);
bitmap_unlock(map);
} }
void bitmap_clear_all(MY_BITMAP* map)
void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2)
{ {
uchar *to=map->bitmap, *from=map2->bitmap, *end;
DBUG_ASSERT(map->bitmap && map2->bitmap &&
map->bitmap_size==map2->bitmap_size);
bitmap_lock(map); bitmap_lock(map);
bitmap_lock((MY_BITMAP *)map2); bzero(map->bitmap,(map->bitmap_size+7)/8);
end= to+map->bitmap_size;
while (to < end)
*to++ |= *from++;
bitmap_unlock((MY_BITMAP *)map2);
bitmap_unlock(map); bitmap_unlock(map);
} }
...@@ -14,13 +14,6 @@ ...@@ -14,13 +14,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
This file is the net layer API for the MySQL client/server protocol,
which is a tightly coupled, proprietary protocol owned by MySQL AB.
Any re-implementations of this protocol must also be under GPL
unless one has got an license from MySQL AB stating otherwise.
*/
/* /*
Write and read of logical packets to/from socket Write and read of logical packets to/from socket
...@@ -33,10 +26,6 @@ ...@@ -33,10 +26,6 @@
C file. C file.
*/ */
/*
HFTODO this must be hidden if we don't want client capabilities in
embedded library
*/
#ifdef __WIN__ #ifdef __WIN__
#include <winsock.h> #include <winsock.h>
#endif #endif
...@@ -52,13 +41,6 @@ ...@@ -52,13 +41,6 @@
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#ifdef EMBEDDED_LIBRARY
#undef MYSQL_SERVER
#undef MYSQL_CLIENT
#define MYSQL_CLIENT
#endif /*EMBEDDED_LIBRARY */
/* /*
The following handles the differences when this is linked between the The following handles the differences when this is linked between the
client and the server. client and the server.
...@@ -84,15 +66,10 @@ void sql_print_error(const char *format,...); ...@@ -84,15 +66,10 @@ void sql_print_error(const char *format,...);
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
#define USE_QUERY_CACHE #define USE_QUERY_CACHE
/*
The following variables/functions should really not be declared
extern, but as it's hard to include mysql_priv.h here, we have to
live with this for a while.
*/
extern uint test_flags; extern uint test_flags;
extern void query_cache_insert(NET *net, const char *packet, ulong length);
extern ulong bytes_sent, bytes_received, net_big_packet_count; extern ulong bytes_sent, bytes_received, net_big_packet_count;
extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
extern void query_cache_insert(NET *net, const char *packet, ulong length);
#else #else
#undef statistic_add #undef statistic_add
#undef statistic_increment #undef statistic_increment
...@@ -108,7 +85,7 @@ static my_bool net_write_buff(NET *net,const char *packet,ulong len); ...@@ -108,7 +85,7 @@ static my_bool net_write_buff(NET *net,const char *packet,ulong len);
/* Init with packet info */ /* Init with packet info */
my_bool my_net_init(NET *net, Vio* vio) int my_net_init(NET *net, Vio* vio)
{ {
DBUG_ENTER("my_net_init"); DBUG_ENTER("my_net_init");
my_net_local_init(net); /* Set some limits */ my_net_local_init(net); /* Set some limits */
...@@ -127,7 +104,6 @@ my_bool my_net_init(NET *net, Vio* vio) ...@@ -127,7 +104,6 @@ my_bool my_net_init(NET *net, Vio* vio)
net->where_b = net->remain_in_buf=0; net->where_b = net->remain_in_buf=0;
net->last_errno=0; net->last_errno=0;
net->query_cache_query=0; net->query_cache_query=0;
net->report_error= 0;
if (vio != 0) /* If real connection */ if (vio != 0) /* If real connection */
{ {
...@@ -156,7 +132,7 @@ void net_end(NET *net) ...@@ -156,7 +132,7 @@ void net_end(NET *net)
/* Realloc the packet buffer */ /* Realloc the packet buffer */
my_bool net_realloc(NET *net, ulong length) static my_bool net_realloc(NET *net, ulong length)
{ {
uchar *buff; uchar *buff;
ulong pkt_length; ulong pkt_length;
...@@ -165,11 +141,10 @@ my_bool net_realloc(NET *net, ulong length) ...@@ -165,11 +141,10 @@ my_bool net_realloc(NET *net, ulong length)
if (length >= net->max_packet_size) if (length >= net->max_packet_size)
{ {
DBUG_PRINT("error", ("Packet too large. Max size: %lu", DBUG_PRINT("error",("Packet too large. Max sixe: %lu",
net->max_packet_size)); net->max_packet_size));
net->error= 1; net->error=1;
net->report_error= 1; net->last_errno=ER_NET_PACKET_TOO_LARGE;
net->last_errno= ER_NET_PACKET_TOO_LARGE;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
...@@ -181,9 +156,10 @@ my_bool net_realloc(NET *net, ulong length) ...@@ -181,9 +156,10 @@ my_bool net_realloc(NET *net, ulong length)
NET_HEADER_SIZE + COMP_HEADER_SIZE, NET_HEADER_SIZE + COMP_HEADER_SIZE,
MYF(MY_WME)))) MYF(MY_WME))))
{ {
net->error= 1; net->error=1;
net->report_error= 1; #ifdef MYSQL_SERVER
net->last_errno= ER_OUT_OF_RESOURCES; net->last_errno=ER_OUT_OF_RESOURCES;
#endif
DBUG_RETURN(1); DBUG_RETURN(1);
} }
net->buff=net->write_pos=buff; net->buff=net->write_pos=buff;
...@@ -217,14 +193,14 @@ void net_clear(NET *net) ...@@ -217,14 +193,14 @@ void net_clear(NET *net)
/* Flush write_buffer if not empty. */ /* Flush write_buffer if not empty. */
my_bool net_flush(NET *net) int net_flush(NET *net)
{ {
my_bool error= 0; int error=0;
DBUG_ENTER("net_flush"); DBUG_ENTER("net_flush");
if (net->buff != net->write_pos) if (net->buff != net->write_pos)
{ {
error=test(net_real_write(net,(char*) net->buff, error=net_real_write(net,(char*) net->buff,
(ulong) (net->write_pos - net->buff))); (ulong) (net->write_pos - net->buff));
net->write_pos=net->buff; net->write_pos=net->buff;
} }
/* Sync packet number if using compression */ /* Sync packet number if using compression */
...@@ -247,7 +223,7 @@ my_bool net_flush(NET *net) ...@@ -247,7 +223,7 @@ my_bool net_flush(NET *net)
If compression is used the original package is modified! If compression is used the original package is modified!
*/ */
my_bool int
my_net_write(NET *net,const char *packet,ulong len) my_net_write(NET *net,const char *packet,ulong len)
{ {
uchar buff[NET_HEADER_SIZE]; uchar buff[NET_HEADER_SIZE];
...@@ -274,46 +250,23 @@ my_net_write(NET *net,const char *packet,ulong len) ...@@ -274,46 +250,23 @@ my_net_write(NET *net,const char *packet,ulong len)
buff[3]= (uchar) net->pkt_nr++; buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE)) if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE))
return 1; return 1;
#ifndef DEBUG_DATA_PACKETS
DBUG_DUMP("packet_header",(char*) buff,NET_HEADER_SIZE); DBUG_DUMP("packet_header",(char*) buff,NET_HEADER_SIZE);
#endif
return test(net_write_buff(net,packet,len)); return test(net_write_buff(net,packet,len));
} }
/* /*
Send a command to the server. Send a command to the server.
SYNOPSIS
net_write_command()
net NET handler
command Command in MySQL server (enum enum_server_command)
header Header to write after command
head_len Length of header
packet Query or parameter to query
len Length of packet
DESCRIPTION
The reason for having both header and packet is so that libmysql
can easy add a header to a special command (like prepared statements)
without having to re-alloc the string.
As the command is part of the first data packet, we have to do some data As the command is part of the first data packet, we have to do some data
juggling to put the command in there, without having to create a new juggling to put the command in there, without having to create a new
packet. packet.
This function will split big packets into sub-packets if needed. This function will split big packets into sub-packets if needed.
(Each sub packet can only be 2^24 bytes) (Each sub packet can only be 2^24 bytes)
RETURN VALUES
0 ok
1 error
*/ */
my_bool int
net_write_command(NET *net,uchar command, net_write_command(NET *net,uchar command,const char *packet,ulong len)
const char *header, ulong head_len,
const char *packet, ulong len)
{ {
ulong length=len+1+head_len; /* 1 extra byte for command */ ulong length=len+1; /* 1 extra byte for command */
uchar buff[NET_HEADER_SIZE+1]; uchar buff[NET_HEADER_SIZE+1];
uint header_size=NET_HEADER_SIZE+1; uint header_size=NET_HEADER_SIZE+1;
DBUG_ENTER("net_write_command"); DBUG_ENTER("net_write_command");
...@@ -324,28 +277,25 @@ net_write_command(NET *net,uchar command, ...@@ -324,28 +277,25 @@ net_write_command(NET *net,uchar command,
if (length >= MAX_PACKET_LENGTH) if (length >= MAX_PACKET_LENGTH)
{ {
/* Take into account that we have the command in the first header */ /* Take into account that we have the command in the first header */
len= MAX_PACKET_LENGTH - 1 - head_len; len= MAX_PACKET_LENGTH -1;
do do
{ {
int3store(buff, MAX_PACKET_LENGTH); int3store(buff, MAX_PACKET_LENGTH);
buff[3]= (uchar) net->pkt_nr++; buff[3]= (uchar) net->pkt_nr++;
if (net_write_buff(net,(char*) buff, header_size) || if (net_write_buff(net,(char*) buff, header_size) ||
net_write_buff(net, header, head_len) || net_write_buff(net,packet,len))
net_write_buff(net, packet, len))
DBUG_RETURN(1); DBUG_RETURN(1);
packet+= len; packet+= len;
length-= MAX_PACKET_LENGTH; length-= MAX_PACKET_LENGTH;
len= MAX_PACKET_LENGTH; len= MAX_PACKET_LENGTH;
head_len= 0;
header_size= NET_HEADER_SIZE; header_size= NET_HEADER_SIZE;
} while (length >= MAX_PACKET_LENGTH); } while (length >= MAX_PACKET_LENGTH);
len=length; /* Data left to be written */ len=length; /* Data left to be written */
} }
int3store(buff,length); int3store(buff,length);
buff[3]= (uchar) net->pkt_nr++; buff[3]= (uchar) net->pkt_nr++;
DBUG_RETURN(test(net_write_buff(net, (char*) buff, header_size) || DBUG_RETURN(test(net_write_buff(net,(char*) buff,header_size) ||
(head_len && net_write_buff(net, (char*) header, head_len)) || net_write_buff(net,packet,len) || net_flush(net)));
net_write_buff(net, packet, len) || net_flush(net)));
} }
/* /*
...@@ -386,9 +336,6 @@ net_write_buff(NET *net,const char *packet,ulong len) ...@@ -386,9 +336,6 @@ net_write_buff(NET *net,const char *packet,ulong len)
else else
left_length= (ulong) (net->buff_end - net->write_pos); left_length= (ulong) (net->buff_end - net->write_pos);
#ifdef DEBUG_DATA_PACKETS
DBUG_DUMP("data", packet, len);
#endif
if (len > left_length) if (len > left_length)
{ {
if (net->write_pos != net->buff) if (net->write_pos != net->buff)
...@@ -464,12 +411,10 @@ net_real_write(NET *net,const char *packet,ulong len) ...@@ -464,12 +411,10 @@ net_real_write(NET *net,const char *packet,ulong len)
COMP_HEADER_SIZE, MYF(MY_WME)))) COMP_HEADER_SIZE, MYF(MY_WME))))
{ {
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno= ER_OUT_OF_RESOURCES; net->last_errno=ER_OUT_OF_RESOURCES;
net->error= 2; net->error=2;
/* TODO is it needed to set this variable if we have no socket */
net->report_error= 1;
#endif #endif
net->reading_or_writing= 0; net->reading_or_writing=0;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
memcpy(b+header_length,packet,len); memcpy(b+header_length,packet,len);
...@@ -516,10 +461,9 @@ net_real_write(NET *net,const char *packet,ulong len) ...@@ -516,10 +461,9 @@ net_real_write(NET *net,const char *packet,ulong len)
my_progname,vio_errno(net->vio)); my_progname,vio_errno(net->vio));
#endif /* EXTRA_DEBUG */ #endif /* EXTRA_DEBUG */
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno= ER_NET_ERROR_ON_WRITE; net->last_errno=ER_NET_ERROR_ON_WRITE;
#endif #endif
net->error= 2; /* Close socket */ net->error=2; /* Close socket */
net->report_error= 1;
goto end; goto end;
} }
retry_count=0; retry_count=0;
...@@ -545,8 +489,7 @@ net_real_write(NET *net,const char *packet,ulong len) ...@@ -545,8 +489,7 @@ net_real_write(NET *net,const char *packet,ulong len)
continue; continue;
} }
#endif /* defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) */ #endif /* defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) */
net->error= 2; /* Close socket */ net->error=2; /* Close socket */
net->report_error= 1;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED : net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED :
ER_NET_ERROR_ON_WRITE); ER_NET_ERROR_ON_WRITE);
...@@ -724,10 +667,9 @@ my_real_read(NET *net, ulong *complen) ...@@ -724,10 +667,9 @@ my_real_read(NET *net, ulong *complen)
my_progname,vio_errno(net->vio)); my_progname,vio_errno(net->vio));
#endif /* EXTRA_DEBUG */ #endif /* EXTRA_DEBUG */
len= packet_error; len= packet_error;
net->error= 2; /* Close socket */ net->error=2; /* Close socket */
net->report_error= 1;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno= ER_NET_FCNTL_ERROR; net->last_errno=ER_NET_FCNTL_ERROR;
#endif #endif
goto end; goto end;
} }
...@@ -756,8 +698,7 @@ my_real_read(NET *net, ulong *complen) ...@@ -756,8 +698,7 @@ my_real_read(NET *net, ulong *complen)
DBUG_PRINT("error",("Couldn't read packet: remain: %u errno: %d length: %ld", DBUG_PRINT("error",("Couldn't read packet: remain: %u errno: %d length: %ld",
remain, vio_errno(net->vio), length)); remain, vio_errno(net->vio), length));
len= packet_error; len= packet_error;
net->error= 2; /* Close socket */ net->error=2; /* Close socket */
net->report_error= 1;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno= (interrupted ? ER_NET_READ_INTERRUPTED : net->last_errno= (interrupted ? ER_NET_READ_INTERRUPTED :
ER_NET_READ_ERROR); ER_NET_READ_ERROR);
...@@ -771,8 +712,6 @@ my_real_read(NET *net, ulong *complen) ...@@ -771,8 +712,6 @@ my_real_read(NET *net, ulong *complen)
if (i == 0) if (i == 0)
{ /* First parts is packet length */ { /* First parts is packet length */
ulong helping; ulong helping;
DBUG_DUMP("packet_header",(char*) net->buff+net->where_b,
NET_HEADER_SIZE);
if (net->buff[net->where_b + 3] != (uchar) net->pkt_nr) if (net->buff[net->where_b + 3] != (uchar) net->pkt_nr)
{ {
if (net->buff[net->where_b] != (uchar) 255) if (net->buff[net->where_b] != (uchar) 255)
...@@ -781,6 +720,7 @@ my_real_read(NET *net, ulong *complen) ...@@ -781,6 +720,7 @@ my_real_read(NET *net, ulong *complen)
("Packets out of order (Found: %d, expected %u)", ("Packets out of order (Found: %d, expected %u)",
(int) net->buff[net->where_b + 3], (int) net->buff[net->where_b + 3],
net->pkt_nr)); net->pkt_nr));
DBUG_DUMP("packet_header",(char*) net->buff+net->where_b, 4);
#ifdef EXTRA_DEBUG #ifdef EXTRA_DEBUG
fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n",
(int) net->buff[net->where_b + 3], (int) net->buff[net->where_b + 3],
...@@ -788,7 +728,6 @@ my_real_read(NET *net, ulong *complen) ...@@ -788,7 +728,6 @@ my_real_read(NET *net, ulong *complen)
#endif #endif
} }
len= packet_error; len= packet_error;
net->report_error= 1;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno=ER_NET_PACKETS_OUT_OF_ORDER; net->last_errno=ER_NET_PACKETS_OUT_OF_ORDER;
#endif #endif
...@@ -837,10 +776,6 @@ end: ...@@ -837,10 +776,6 @@ end:
vio_blocking(net->vio, net_blocking, &old_mode); vio_blocking(net->vio, net_blocking, &old_mode);
} }
net->reading_or_writing=0; net->reading_or_writing=0;
#ifdef DEBUG_DATA_PACKETS
if (len != packet_error)
DBUG_DUMP("data",(char*) net->buff+net->where_b, len);
#endif
return(len); return(len);
} }
...@@ -973,8 +908,7 @@ my_net_read(NET *net) ...@@ -973,8 +908,7 @@ my_net_read(NET *net)
if (my_uncompress((byte*) net->buff + net->where_b, &packet_len, if (my_uncompress((byte*) net->buff + net->where_b, &packet_len,
&complen)) &complen))
{ {
net->error= 2; /* caller will close socket */ net->error=2; /* caller will close socket */
net->report_error= 1;
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
net->last_errno=ER_NET_UNCOMPRESS_ERROR; net->last_errno=ER_NET_UNCOMPRESS_ERROR;
#endif #endif
...@@ -995,3 +929,12 @@ my_net_read(NET *net) ...@@ -995,3 +929,12 @@ my_net_read(NET *net)
return len; return len;
} }
bool net_request_file(NET* net, const char* fname)
{
char tmp [FN_REFLEN+1],*end;
DBUG_ENTER("net_request_file");
tmp[0] = (char) 251; /* NULL_LENGTH */
end=strnmov(tmp+1,fname,sizeof(tmp)-2);
DBUG_RETURN(my_net_write(net,tmp,(uint) (end-tmp)) ||
net_flush(net));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment