2001-12-06 14:10:51 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 14:10:51 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2001-05-20 14:04:46 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 14:10:51 +02:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
2001-05-20 14:04:46 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Note that we can't have assertion on file descriptors; The reason for
|
|
|
|
this is that during mysql shutdown, another thread can close a file
|
|
|
|
we are working on. In this case we should just return read errors from
|
|
|
|
the file descriptior.
|
|
|
|
*/
|
|
|
|
|
2003-08-27 02:51:39 +03:00
|
|
|
#include "vio_priv.h"
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
int vio_errno(Vio *vio __attribute__((unused)))
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2001-10-08 23:20:19 +03:00
|
|
|
return socket_errno; /* On Win32 this mapped to WSAGetLastError() */
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_read(Vio * vio, uchar* buf, size_t size)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t r;
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_ENTER("vio_read");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
|
|
|
|
(uint) size));
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2005-03-06 00:10:08 +03:00
|
|
|
/* Ensure nobody uses vio_read_buff and vio_read simultaneously */
|
|
|
|
DBUG_ASSERT(vio->read_end == vio->read_pos);
|
2001-05-20 14:04:46 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
r = recv(vio->sd, buf, size,0);
|
|
|
|
#else
|
|
|
|
errno=0; /* For linux */
|
|
|
|
r = read(vio->sd, buf, size);
|
|
|
|
#endif /* __WIN__ */
|
|
|
|
#ifndef DBUG_OFF
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
if (r == (size_t) -1)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2001-06-05 03:38:10 +03:00
|
|
|
DBUG_PRINT("vio_error", ("Got error %d during read",errno));
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
#endif /* DBUG_OFF */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("exit", ("%ld", (long) r));
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-06 00:10:08 +03:00
|
|
|
/*
|
|
|
|
Buffered read: if average read size is small it may
|
|
|
|
reduce number of syscalls.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_read_buff(Vio *vio, uchar* buf, size_t size)
|
2005-03-06 00:10:08 +03:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t rc;
|
2005-03-06 00:10:08 +03:00
|
|
|
#define VIO_UNBUFFERED_READ_MIN_SIZE 2048
|
|
|
|
DBUG_ENTER("vio_read_buff");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
|
|
|
|
(uint) size));
|
2005-03-06 00:10:08 +03:00
|
|
|
|
|
|
|
if (vio->read_pos < vio->read_end)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
rc= min((size_t) (vio->read_end - vio->read_pos), size);
|
2005-03-06 00:10:08 +03:00
|
|
|
memcpy(buf, vio->read_pos, rc);
|
|
|
|
vio->read_pos+= rc;
|
|
|
|
/*
|
|
|
|
Do not try to read from the socket now even if rc < size:
|
|
|
|
vio_read can return -1 due to an error or non-blocking mode, and
|
|
|
|
the safest way to handle it is to move to a separate branch.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if (size < VIO_UNBUFFERED_READ_MIN_SIZE)
|
|
|
|
{
|
2007-08-13 16:11:25 +03:00
|
|
|
rc= vio_read(vio, (uchar*) vio->read_buffer, VIO_READ_BUFFER_SIZE);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
if (rc != 0 && rc != (size_t) -1)
|
2005-03-06 00:10:08 +03:00
|
|
|
{
|
|
|
|
if (rc > size)
|
|
|
|
{
|
|
|
|
vio->read_pos= vio->read_buffer + size;
|
|
|
|
vio->read_end= vio->read_buffer + rc;
|
|
|
|
rc= size;
|
|
|
|
}
|
|
|
|
memcpy(buf, vio->read_buffer, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc= vio_read(vio, buf, size);
|
|
|
|
DBUG_RETURN(rc);
|
|
|
|
#undef VIO_UNBUFFERED_READ_MIN_SIZE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_write(Vio * vio, const uchar* buf, size_t size)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t r;
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_ENTER("vio_write");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
|
|
|
|
(uint) size));
|
2002-11-15 00:16:30 +05:00
|
|
|
#ifdef __WIN__
|
|
|
|
r = send(vio->sd, buf, size,0);
|
2001-05-20 14:04:46 +02:00
|
|
|
#else
|
|
|
|
r = write(vio->sd, buf, size);
|
|
|
|
#endif /* __WIN__ */
|
|
|
|
#ifndef DBUG_OFF
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
if (r == (size_t) -1)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2001-10-08 23:20:19 +03:00
|
|
|
DBUG_PRINT("vio_error", ("Got error on write: %d",socket_errno));
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
#endif /* DBUG_OFF */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("exit", ("%u", (uint) r));
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
2002-08-08 03:12:02 +03:00
|
|
|
int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode,
|
|
|
|
my_bool *old_mode)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
int r=0;
|
|
|
|
DBUG_ENTER("vio_blocking");
|
2002-08-08 03:12:02 +03:00
|
|
|
|
|
|
|
*old_mode= test(!(vio->fcntl_mode & O_NONBLOCK));
|
|
|
|
DBUG_PRINT("enter", ("set_blocking_mode: %d old_mode: %d",
|
|
|
|
(int) set_blocking_mode, (int) *old_mode));
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2006-04-15 18:17:32 -07:00
|
|
|
#if !defined(__WIN__)
|
2001-05-20 14:04:46 +02:00
|
|
|
#if !defined(NO_FCNTL_NONBLOCK)
|
|
|
|
if (vio->sd >= 0)
|
|
|
|
{
|
|
|
|
int old_fcntl=vio->fcntl_mode;
|
|
|
|
if (set_blocking_mode)
|
|
|
|
vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */
|
|
|
|
else
|
|
|
|
vio->fcntl_mode |= O_NONBLOCK; /* set bit */
|
|
|
|
if (old_fcntl != vio->fcntl_mode)
|
2005-10-11 09:12:12 -07:00
|
|
|
{
|
|
|
|
r= fcntl(vio->sd, F_SETFL, vio->fcntl_mode);
|
|
|
|
if (r == -1)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("fcntl failed, errno %d", errno));
|
|
|
|
vio->fcntl_mode= old_fcntl;
|
|
|
|
}
|
|
|
|
}
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2002-08-26 12:28:49 +03:00
|
|
|
#else
|
|
|
|
r= set_blocking_mode ? 0 : 1;
|
2001-05-20 14:04:46 +02:00
|
|
|
#endif /* !defined(NO_FCNTL_NONBLOCK) */
|
2006-04-15 18:17:32 -07:00
|
|
|
#else /* !defined(__WIN__) */
|
2005-08-31 15:04:25 -07:00
|
|
|
if (vio->type != VIO_TYPE_NAMEDPIPE && vio->type != VIO_TYPE_SHARED_MEMORY)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
ulong arg;
|
|
|
|
int old_fcntl=vio->fcntl_mode;
|
|
|
|
if (set_blocking_mode)
|
|
|
|
{
|
|
|
|
arg = 0;
|
|
|
|
vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg = 1;
|
|
|
|
vio->fcntl_mode |= O_NONBLOCK; /* set bit */
|
|
|
|
}
|
|
|
|
if (old_fcntl != vio->fcntl_mode)
|
2005-07-12 10:31:09 -06:00
|
|
|
r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
2002-08-26 12:28:49 +03:00
|
|
|
else
|
|
|
|
r= test(!(vio->fcntl_mode & O_NONBLOCK)) != set_blocking_mode;
|
2006-04-15 18:17:32 -07:00
|
|
|
#endif /* !defined(__WIN__) */
|
2002-06-11 11:20:31 +03:00
|
|
|
DBUG_PRINT("exit", ("%d", r));
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
my_bool
|
2001-05-31 17:18:25 +03:00
|
|
|
vio_is_blocking(Vio * vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
my_bool r;
|
|
|
|
DBUG_ENTER("vio_is_blocking");
|
|
|
|
r = !(vio->fcntl_mode & O_NONBLOCK);
|
|
|
|
DBUG_PRINT("exit", ("%d", (int) r));
|
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
int vio_fastsend(Vio * vio __attribute__((unused)))
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
int r=0;
|
|
|
|
DBUG_ENTER("vio_fastsend");
|
|
|
|
|
2006-04-15 18:17:32 -07:00
|
|
|
#if defined(IPTOS_THROUGHPUT)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
int tos = IPTOS_THROUGHPUT;
|
2005-01-25 02:31:51 +03:00
|
|
|
r= setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos));
|
|
|
|
}
|
2006-04-15 18:17:32 -07:00
|
|
|
#endif /* IPTOS_THROUGHPUT */
|
2005-01-25 02:31:51 +03:00
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
#ifdef __WIN__
|
|
|
|
BOOL nodelay= 1;
|
|
|
|
#else
|
|
|
|
int nodelay = 1;
|
2007-05-24 11:21:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
|
2009-12-22 10:35:56 +01:00
|
|
|
IF_WIN((const char*), (void*)) &nodelay,
|
2005-01-25 02:31:51 +03:00
|
|
|
sizeof(nodelay));
|
2007-05-24 11:21:27 +02:00
|
|
|
|
2005-01-25 02:31:51 +03:00
|
|
|
}
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("warning", ("Couldn't set socket option for fast send"));
|
|
|
|
r= -1;
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
DBUG_PRINT("exit", ("%d", r));
|
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
int vio_keepalive(Vio* vio, my_bool set_keep_alive)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
int r=0;
|
|
|
|
uint opt = 0;
|
|
|
|
DBUG_ENTER("vio_keepalive");
|
2006-05-31 14:55:28 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d set_keep_alive: %d", vio->sd, (int)
|
2001-05-20 14:04:46 +02:00
|
|
|
set_keep_alive));
|
|
|
|
if (vio->type != VIO_TYPE_NAMEDPIPE)
|
|
|
|
{
|
|
|
|
if (set_keep_alive)
|
|
|
|
opt = 1;
|
|
|
|
r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
|
|
|
|
sizeof(opt));
|
|
|
|
}
|
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_bool
|
2009-12-22 10:35:56 +01:00
|
|
|
vio_should_retry(Vio * vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2001-10-08 23:20:19 +03:00
|
|
|
int en = socket_errno;
|
2009-12-22 10:35:56 +01:00
|
|
|
/*
|
|
|
|
man 2 read write
|
|
|
|
EAGAIN or EWOULDBLOCK when a socket is a non-blocking mode means
|
|
|
|
that the read/write would block.
|
|
|
|
man 7 socket
|
|
|
|
EAGAIN or EWOULDBLOCK when a socket is in a blocking mode means
|
|
|
|
that the corresponding receiving or sending timeout was reached.
|
|
|
|
*/
|
|
|
|
return en == SOCKET_EINTR ||
|
|
|
|
(!vio_is_blocking(vio) &&
|
|
|
|
(en == SOCKET_EAGAIN || en == SOCKET_EWOULDBLOCK));
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-30 19:19:28 +04:00
|
|
|
my_bool
|
2005-09-07 15:57:14 +04:00
|
|
|
vio_was_interrupted(Vio *vio __attribute__((unused)))
|
2005-08-30 19:19:28 +04:00
|
|
|
{
|
2005-09-07 15:57:14 +04:00
|
|
|
int en= socket_errno;
|
2005-08-30 19:19:28 +04:00
|
|
|
return (en == SOCKET_EAGAIN || en == SOCKET_EINTR ||
|
|
|
|
en == SOCKET_EWOULDBLOCK || en == SOCKET_ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
int vio_close(Vio * vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2003-10-17 13:17:15 +02:00
|
|
|
int r=0;
|
2001-05-20 14:04:46 +02:00
|
|
|
DBUG_ENTER("vio_close");
|
2009-11-02 23:19:58 +01:00
|
|
|
|
2004-07-12 07:38:46 +03:00
|
|
|
if (vio->type != VIO_CLOSED)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2009-11-02 23:19:58 +01:00
|
|
|
DBUG_ASSERT(vio->type == VIO_TYPE_TCPIP ||
|
|
|
|
vio->type == VIO_TYPE_SOCKET ||
|
|
|
|
vio->type == VIO_TYPE_SSL);
|
|
|
|
|
2004-07-12 07:38:46 +03:00
|
|
|
DBUG_ASSERT(vio->sd >= 0);
|
2006-09-15 14:27:45 +02:00
|
|
|
if (shutdown(vio->sd, SHUT_RDWR))
|
2001-05-20 14:04:46 +02:00
|
|
|
r= -1;
|
|
|
|
if (closesocket(vio->sd))
|
|
|
|
r= -1;
|
|
|
|
}
|
|
|
|
if (r)
|
|
|
|
{
|
2001-10-08 23:20:19 +03:00
|
|
|
DBUG_PRINT("vio_error", ("close() failed, error: %d",socket_errno));
|
2001-05-20 14:04:46 +02:00
|
|
|
/* FIXME: error handling (not critical for MySQL) */
|
|
|
|
}
|
|
|
|
vio->type= VIO_CLOSED;
|
|
|
|
vio->sd= -1;
|
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
const char *vio_description(Vio * vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
return vio->desc;
|
|
|
|
}
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
enum enum_vio_type vio_type(Vio* vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
return vio->type;
|
|
|
|
}
|
|
|
|
|
2001-05-31 17:18:25 +03:00
|
|
|
my_socket vio_fd(Vio* vio)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
return vio->sd;
|
|
|
|
}
|
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
/**
|
|
|
|
Convert a sock-address (AF_INET or AF_INET6) into the "normalized" form,
|
|
|
|
which is the IPv4 form for IPv4-mapped or IPv4-compatible IPv6 addresses.
|
|
|
|
|
|
|
|
@note Background: when IPv4 and IPv6 are used simultaneously, IPv4
|
|
|
|
addresses may be written in a form of IPv4-mapped or IPv4-compatible IPv6
|
|
|
|
addresses. That means, one address (a.b.c.d) can be written in three forms:
|
|
|
|
- IPv4: a.b.c.d;
|
|
|
|
- IPv4-compatible IPv6: ::a.b.c.d;
|
|
|
|
- IPv4-mapped IPv4: ::ffff:a.b.c.d;
|
|
|
|
|
|
|
|
Having three forms of one address makes it a little difficult to compare
|
|
|
|
addresses with each other (the IPv4-compatible IPv6-address of foo.bar
|
|
|
|
will be different from the IPv4-mapped IPv6-address of foo.bar).
|
|
|
|
|
|
|
|
@note This function can be made public when it's needed.
|
|
|
|
|
|
|
|
@param src [in] source IP address (AF_INET or AF_INET6).
|
|
|
|
@param src_length [in] length of the src.
|
|
|
|
@param dst [out] a buffer to store normalized IP address
|
|
|
|
(sockaddr_storage).
|
|
|
|
@param dst_length [out] actual length of the normalized IP address.
|
|
|
|
*/
|
|
|
|
static void vio_get_normalized_ip(const struct sockaddr *src,
|
|
|
|
int src_length,
|
|
|
|
struct sockaddr *dst,
|
|
|
|
int *dst_length)
|
|
|
|
{
|
|
|
|
switch (src->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
memcpy(dst, src, src_length);
|
|
|
|
*dst_length= src_length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
const struct sockaddr_in6 *src_addr6= (const struct sockaddr_in6 *) src;
|
|
|
|
const struct in6_addr *src_ip6= &(src_addr6->sin6_addr);
|
|
|
|
const uint32 *src_ip6_int32= (uint32 *) src_ip6->s6_addr;
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(src_ip6) || IN6_IS_ADDR_V4COMPAT(src_ip6))
|
|
|
|
{
|
|
|
|
struct sockaddr_in *dst_ip4= (struct sockaddr_in *) dst;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is an IPv4-mapped or IPv4-compatible IPv6 address. It should
|
|
|
|
be converted to the IPv4 form.
|
|
|
|
*/
|
|
|
|
|
|
|
|
*dst_length= sizeof (struct sockaddr_in);
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
memset(dst_ip4, 0, *dst_length);
|
|
|
|
dst_ip4->sin_family= AF_INET;
|
|
|
|
dst_ip4->sin_port= src_addr6->sin6_port;
|
|
|
|
|
|
|
|
/*
|
|
|
|
In an IPv4 mapped or compatible address, the last 32 bits represent
|
|
|
|
the IPv4 address. The byte orders for IPv6 and IPv4 addresses are
|
|
|
|
the same, so a simple copy is possible.
|
|
|
|
*/
|
|
|
|
dst_ip4->sin_addr.s_addr= src_ip6_int32[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is a "native" IPv6 address. */
|
|
|
|
|
|
|
|
memcpy(dst, src, src_length);
|
|
|
|
*dst_length= src_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_IPV6 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the normalized IP address string for a sock-address.
|
|
|
|
|
|
|
|
The idea is to return an IPv4-address for an IPv4-mapped and
|
|
|
|
IPv4-compatible IPv6 address.
|
|
|
|
|
|
|
|
The function writes the normalized IP address to the given buffer.
|
|
|
|
The buffer should have enough space, otherwise error flag is returned.
|
|
|
|
The system constant INET6_ADDRSTRLEN can be used to reserve buffers of
|
|
|
|
the right size.
|
|
|
|
|
|
|
|
@param addr [in] sockaddr object (AF_INET or AF_INET6).
|
|
|
|
@param addr_length [in] length of the addr.
|
|
|
|
@param ip_string [out] buffer to write normalized IP address.
|
|
|
|
@param ip_string_size [in] size of the ip_string.
|
|
|
|
|
|
|
|
@return Error status.
|
|
|
|
@retval TRUE in case of error (the ip_string buffer is not enough).
|
|
|
|
@retval FALSE on success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool vio_get_normalized_ip_string(const struct sockaddr *addr,
|
|
|
|
int addr_length,
|
|
|
|
char *ip_string,
|
|
|
|
size_t ip_string_size)
|
|
|
|
{
|
|
|
|
struct sockaddr_storage norm_addr_storage;
|
|
|
|
struct sockaddr *norm_addr= (struct sockaddr *) &norm_addr_storage;
|
|
|
|
int norm_addr_length;
|
|
|
|
int err_code;
|
|
|
|
|
|
|
|
vio_get_normalized_ip(addr, addr_length, norm_addr, &norm_addr_length);
|
|
|
|
|
|
|
|
err_code= vio_getnameinfo(norm_addr, ip_string, ip_string_size, NULL, 0,
|
|
|
|
NI_NUMERICHOST);
|
|
|
|
|
|
|
|
if (!err_code)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
DBUG_PRINT("error", ("getnameinfo() failed with %d (%s).",
|
|
|
|
(int) err_code,
|
|
|
|
(const char *) gai_strerror(err_code)));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return IP address and port of a VIO client socket.
|
|
|
|
|
|
|
|
The function returns an IPv4 address if IPv6 support is disabled.
|
|
|
|
|
|
|
|
The function returns an IPv4 address if the client socket is associated
|
|
|
|
with an IPv4-compatible or IPv4-mapped IPv6 address. Otherwise, the native
|
|
|
|
IPv6 address is returned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool vio_peer_addr(Vio *vio, char *ip_buffer, uint16 *port,
|
|
|
|
size_t ip_buffer_size)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("vio_peer_addr");
|
2009-11-25 13:53:23 +03:00
|
|
|
DBUG_PRINT("enter", ("Client socked fd: %d", (int) vio->sd));
|
|
|
|
|
2001-05-20 14:04:46 +02:00
|
|
|
if (vio->localhost)
|
|
|
|
{
|
2009-11-25 13:53:23 +03:00
|
|
|
/*
|
|
|
|
Initialize vio->remote and vio->addLen. Set vio->remote to IPv4 loopback
|
|
|
|
address.
|
|
|
|
*/
|
|
|
|
struct in_addr *ip4= &((struct sockaddr_in *) &(vio->remote))->sin_addr;
|
|
|
|
|
|
|
|
vio->remote.ss_family= AF_INET;
|
|
|
|
vio->addrLen= sizeof (struct sockaddr_in);
|
|
|
|
|
|
|
|
ip4->s_addr= htonl(INADDR_LOOPBACK);
|
|
|
|
|
|
|
|
/* Initialize ip_buffer and port. */
|
|
|
|
|
|
|
|
strmov(ip_buffer, "127.0.0.1");
|
2003-02-17 22:07:26 +02:00
|
|
|
*port= 0;
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-25 13:53:23 +03:00
|
|
|
int err_code;
|
|
|
|
char port_buffer[NI_MAXSERV];
|
|
|
|
|
|
|
|
struct sockaddr_storage addr_storage;
|
|
|
|
struct sockaddr *addr= (struct sockaddr *) &addr_storage;
|
|
|
|
size_socket addr_length= sizeof (addr_storage);
|
|
|
|
|
|
|
|
/* Get sockaddr by socked fd. */
|
|
|
|
|
|
|
|
err_code= getpeername(vio->sd, addr, &addr_length);
|
|
|
|
|
|
|
|
if (err_code)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2009-11-25 13:53:23 +03:00
|
|
|
DBUG_PRINT("exit", ("getpeername() gave error: %d", socket_errno));
|
|
|
|
DBUG_RETURN(TRUE);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
/* Normalize IP address. */
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
vio_get_normalized_ip(addr, addr_length,
|
|
|
|
(struct sockaddr *) &vio->remote, &vio->addrLen);
|
2005-02-15 14:42:13 +02:00
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
/* Get IP address & port number. */
|
2005-02-15 14:42:13 +02:00
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
err_code= vio_getnameinfo((struct sockaddr *) &vio->remote,
|
|
|
|
ip_buffer, ip_buffer_size,
|
|
|
|
port_buffer, NI_MAXSERV,
|
|
|
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
2005-02-15 14:42:13 +02:00
|
|
|
|
2009-11-25 13:53:23 +03:00
|
|
|
if (err_code)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("exit", ("getnameinfo() gave error: %s",
|
|
|
|
gai_strerror(err_code)));
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*port= (uint16) strtol(port_buffer, NULL, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_PRINT("exit", ("Client IP address: %s; port: %d",
|
|
|
|
(const char *) ip_buffer,
|
|
|
|
(int) *port));
|
|
|
|
DBUG_RETURN(FALSE);
|
2001-05-20 14:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
/**
|
|
|
|
Indicate whether there is data to read on a given socket.
|
|
|
|
|
|
|
|
@note An exceptional condition event and/or errors are
|
|
|
|
interpreted as if there is data to read.
|
|
|
|
|
|
|
|
@param sd A connected socket.
|
|
|
|
@param timeout Maximum time in seconds to poll.
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
@retval FALSE There is data to read.
|
|
|
|
@retval TRUE There is no data to read.
|
|
|
|
*/
|
2001-05-20 14:04:46 +02:00
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
static my_bool socket_poll_read(my_socket sd, uint timeout)
|
2001-05-20 14:04:46 +02:00
|
|
|
{
|
2009-11-10 17:09:27 -02:00
|
|
|
#ifdef __WIN__
|
2009-11-10 22:39:06 -02:00
|
|
|
int res;
|
2009-11-10 17:36:38 -02:00
|
|
|
my_socket fd= sd;
|
2009-11-10 17:09:27 -02:00
|
|
|
fd_set readfds, errorfds;
|
|
|
|
struct timeval tm;
|
2009-11-10 17:36:38 -02:00
|
|
|
DBUG_ENTER("socket_poll_read");
|
2009-11-10 17:09:27 -02:00
|
|
|
tm.tv_sec= timeout;
|
|
|
|
tm.tv_usec= 0;
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_ZERO(&errorfds);
|
|
|
|
FD_SET(fd, &readfds);
|
|
|
|
FD_SET(fd, &errorfds);
|
2009-11-25 13:53:23 +03:00
|
|
|
/* The first argument is ignored on Windows, so a conversion to int is OK */
|
|
|
|
if ((res= select((int) fd, &readfds, NULL, &errorfds, &tm) <= 0))
|
2009-11-10 17:09:27 -02:00
|
|
|
{
|
|
|
|
DBUG_RETURN(res < 0 ? 0 : 1);
|
|
|
|
}
|
|
|
|
res= FD_ISSET(fd, &readfds) || FD_ISSET(fd, &errorfds);
|
|
|
|
DBUG_RETURN(!res);
|
|
|
|
#elif defined(HAVE_POLL)
|
2001-05-20 14:04:46 +02:00
|
|
|
struct pollfd fds;
|
|
|
|
int res;
|
2009-11-10 17:36:38 -02:00
|
|
|
DBUG_ENTER("socket_poll_read");
|
|
|
|
fds.fd=sd;
|
2001-05-20 14:04:46 +02:00
|
|
|
fds.events=POLLIN;
|
|
|
|
fds.revents=0;
|
|
|
|
if ((res=poll(&fds,1,(int) timeout*1000)) <= 0)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(res < 0 ? 0 : 1); /* Don't return 1 on errors */
|
|
|
|
}
|
2009-11-10 17:09:27 -02:00
|
|
|
DBUG_RETURN(fds.revents & (POLLIN | POLLERR | POLLHUP) ? 0 : 1);
|
|
|
|
#else
|
|
|
|
return 0;
|
2001-05-20 14:04:46 +02:00
|
|
|
#endif
|
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2003-08-27 02:51:39 +03:00
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
/**
|
|
|
|
Retrieve the amount of data that can be read from a socket.
|
|
|
|
|
|
|
|
@param vio A VIO object.
|
|
|
|
@param bytes[out] The amount of bytes available.
|
|
|
|
|
|
|
|
@retval FALSE Success.
|
|
|
|
@retval TRUE Failure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static my_bool socket_peek_read(Vio *vio, uint *bytes)
|
2009-11-10 17:09:27 -02:00
|
|
|
{
|
|
|
|
#ifdef __WIN__
|
|
|
|
int len;
|
|
|
|
if (ioctlsocket(vio->sd, FIONREAD, &len))
|
|
|
|
return TRUE;
|
|
|
|
*bytes= len;
|
|
|
|
return FALSE;
|
2009-11-10 22:39:06 -02:00
|
|
|
#elif FIONREAD_IN_SYS_IOCTL
|
2009-11-10 17:09:27 -02:00
|
|
|
int len;
|
|
|
|
if (ioctl(vio->sd, FIONREAD, &len) < 0)
|
|
|
|
return TRUE;
|
|
|
|
*bytes= len;
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
char buf[1024];
|
|
|
|
ssize_t res= recv(vio->sd, &buf, sizeof(buf), MSG_PEEK);
|
|
|
|
if (res < 0)
|
|
|
|
return TRUE;
|
|
|
|
*bytes= res;
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Indicate whether there is data to read on a given socket.
|
|
|
|
|
|
|
|
@remark Errors are interpreted as if there is data to read.
|
|
|
|
|
|
|
|
@param sd A connected socket.
|
|
|
|
@param timeout Maximum time in seconds to wait.
|
|
|
|
|
|
|
|
@retval FALSE There is data (or EOF) to read. Also FALSE if error.
|
|
|
|
@retval TRUE There is _NO_ data to read or timed out.
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool vio_poll_read(Vio *vio, uint timeout)
|
|
|
|
{
|
|
|
|
my_socket sd= vio->sd;
|
|
|
|
DBUG_ENTER("vio_poll_read");
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
if (vio->type == VIO_TYPE_SSL)
|
|
|
|
sd= SSL_get_fd((SSL*) vio->ssl_arg);
|
|
|
|
#endif
|
|
|
|
DBUG_RETURN(socket_poll_read(sd, timeout));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Determine if the endpoint of a connection is still available.
|
|
|
|
|
|
|
|
@remark The socket is assumed to be disconnected if an EOF
|
|
|
|
condition is encountered.
|
|
|
|
|
|
|
|
@param vio The VIO object.
|
|
|
|
|
|
|
|
@retval TRUE EOF condition not found.
|
|
|
|
@retval FALSE EOF condition is signaled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool vio_is_connected(Vio *vio)
|
|
|
|
{
|
|
|
|
uint bytes= 0;
|
|
|
|
DBUG_ENTER("vio_is_connected");
|
|
|
|
|
|
|
|
/* In the presence of errors the socket is assumed to be connected. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
The first step of detecting a EOF condition is veryfing
|
|
|
|
whether there is data to read. Data in this case would
|
|
|
|
be the EOF.
|
|
|
|
*/
|
|
|
|
if (vio_poll_read(vio, 0))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The second step is read() or recv() from the socket returning
|
|
|
|
0 (EOF). Unfortunelly, it's not possible to call read directly
|
|
|
|
as we could inadvertently read meaningful connection data.
|
|
|
|
Simulate a read by retrieving the number of bytes available to
|
|
|
|
read -- 0 meaning EOF.
|
|
|
|
*/
|
|
|
|
if (socket_peek_read(vio, &bytes))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
/* There might be buffered data at the SSL layer. */
|
|
|
|
if (!bytes && vio->type == VIO_TYPE_SSL)
|
|
|
|
bytes= SSL_pending((SSL*) vio->ssl_arg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DBUG_RETURN(bytes ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-14 20:01:19 +04:00
|
|
|
void vio_timeout(Vio *vio, uint which, uint timeout)
|
2003-08-27 02:51:39 +03:00
|
|
|
{
|
2006-08-14 20:01:19 +04:00
|
|
|
#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
|
2007-05-24 11:21:27 +02:00
|
|
|
int r;
|
|
|
|
DBUG_ENTER("vio_timeout");
|
2006-08-14 20:01:19 +04:00
|
|
|
|
2007-05-24 11:21:27 +02:00
|
|
|
{
|
2003-08-27 02:51:39 +03:00
|
|
|
#ifdef __WIN__
|
2007-05-24 11:21:27 +02:00
|
|
|
/* Windows expects time in milliseconds as int */
|
2006-08-14 20:01:19 +04:00
|
|
|
int wait_timeout= (int) timeout * 1000;
|
2007-05-24 11:21:27 +02:00
|
|
|
#else
|
2006-08-14 20:01:19 +04:00
|
|
|
/* POSIX specifies time as struct timeval. */
|
|
|
|
struct timeval wait_timeout;
|
|
|
|
wait_timeout.tv_sec= timeout;
|
|
|
|
wait_timeout.tv_usec= 0;
|
2007-05-24 11:21:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
r= setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
|
2009-12-22 10:35:56 +01:00
|
|
|
IF_WIN((const char*), (const void*))&wait_timeout,
|
2007-05-24 11:21:27 +02:00
|
|
|
sizeof(wait_timeout));
|
2006-08-14 20:01:19 +04:00
|
|
|
|
2007-05-24 11:21:27 +02:00
|
|
|
}
|
2006-08-14 20:01:19 +04:00
|
|
|
|
2007-05-24 11:21:27 +02:00
|
|
|
if (r != 0)
|
|
|
|
DBUG_PRINT("error", ("setsockopt failed: %d, errno: %d", r, socket_errno));
|
2006-08-14 20:01:19 +04:00
|
|
|
|
2007-05-24 11:21:27 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
Platforms not suporting setting of socket timeout should either use
|
|
|
|
thr_alarm or just run without read/write timeout(s)
|
|
|
|
*/
|
|
|
|
#endif
|
2003-08-27 02:51:39 +03:00
|
|
|
}
|
2003-08-29 13:44:35 +03:00
|
|
|
|
|
|
|
|
2002-11-15 00:16:30 +05:00
|
|
|
#ifdef __WIN__
|
2009-11-02 23:19:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Finish pending IO on pipe. Honor wait timeout
|
|
|
|
*/
|
2009-11-20 13:09:50 +01:00
|
|
|
static size_t pipe_complete_io(Vio* vio, char* buf, size_t size, DWORD timeout_ms)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
|
|
|
DWORD length;
|
2009-11-02 23:19:58 +01:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
DBUG_ENTER("pipe_complete_io");
|
|
|
|
|
2009-11-20 13:09:50 +01:00
|
|
|
ret= WaitForSingleObject(vio->pipe_overlapped.hEvent, timeout_ms);
|
2009-11-02 23:19:58 +01:00
|
|
|
/*
|
|
|
|
WaitForSingleObjects will normally return WAIT_OBJECT_O (success, IO completed)
|
|
|
|
or WAIT_TIMEOUT.
|
|
|
|
*/
|
|
|
|
if(ret != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
CancelIo(vio->hPipe);
|
|
|
|
DBUG_PRINT("error",("WaitForSingleObject() returned %d", ret));
|
2009-11-20 13:09:50 +01:00
|
|
|
DBUG_RETURN((size_t)-1);
|
2009-11-02 23:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetOverlappedResult(vio->hPipe,&(vio->pipe_overlapped),&length, FALSE))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error",("GetOverlappedResult() returned last error %d",
|
|
|
|
GetLastError()));
|
2009-11-20 13:09:50 +01:00
|
|
|
DBUG_RETURN((size_t)-1);
|
2009-11-02 23:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t vio_read_pipe(Vio * vio, uchar *buf, size_t size)
|
|
|
|
{
|
|
|
|
DWORD bytes_read;
|
2009-11-20 13:09:50 +01:00
|
|
|
size_t retval;
|
2002-11-15 00:16:30 +05:00
|
|
|
DBUG_ENTER("vio_read_pipe");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
|
|
|
|
(uint) size));
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2009-11-20 13:09:50 +01:00
|
|
|
if (ReadFile(vio->hPipe, buf, (DWORD)size, &bytes_read,
|
2009-11-02 23:19:58 +01:00
|
|
|
&(vio->pipe_overlapped)))
|
2009-11-20 13:09:50 +01:00
|
|
|
{
|
|
|
|
retval= bytes_read;
|
|
|
|
}
|
|
|
|
else
|
2009-11-02 23:19:58 +01:00
|
|
|
{
|
|
|
|
if (GetLastError() != ERROR_IO_PENDING)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error",("ReadFile() returned last error %d",
|
|
|
|
GetLastError()));
|
|
|
|
DBUG_RETURN((size_t)-1);
|
|
|
|
}
|
2009-11-20 13:09:50 +01:00
|
|
|
retval= pipe_complete_io(vio, buf, size,vio->read_timeout_ms);
|
2009-11-02 23:19:58 +01:00
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2009-11-20 13:09:50 +01:00
|
|
|
DBUG_PRINT("exit", ("%lld", (longlong)retval));
|
|
|
|
DBUG_RETURN(retval);
|
2002-11-15 00:16:30 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_write_pipe(Vio * vio, const uchar* buf, size_t size)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
2009-11-02 23:19:58 +01:00
|
|
|
DWORD bytes_written;
|
2009-11-20 13:09:50 +01:00
|
|
|
size_t retval;
|
2002-11-15 00:16:30 +05:00
|
|
|
DBUG_ENTER("vio_write_pipe");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
|
|
|
|
(uint) size));
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2009-11-20 13:09:50 +01:00
|
|
|
if (WriteFile(vio->hPipe, buf, (DWORD)size, &bytes_written,
|
2009-11-02 23:19:58 +01:00
|
|
|
&(vio->pipe_overlapped)))
|
2009-11-20 13:09:50 +01:00
|
|
|
{
|
|
|
|
retval= bytes_written;
|
|
|
|
}
|
|
|
|
else
|
2009-11-02 23:19:58 +01:00
|
|
|
{
|
|
|
|
if (GetLastError() != ERROR_IO_PENDING)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("vio_error",("WriteFile() returned last error %d",
|
|
|
|
GetLastError()));
|
|
|
|
DBUG_RETURN((size_t)-1);
|
|
|
|
}
|
2009-11-20 13:09:50 +01:00
|
|
|
retval= pipe_complete_io(vio, (char *)buf, size, vio->write_timeout_ms);
|
2009-11-02 23:19:58 +01:00
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
|
2009-11-20 13:09:50 +01:00
|
|
|
DBUG_PRINT("exit", ("%lld", (longlong)retval));
|
|
|
|
DBUG_RETURN(retval);
|
2002-11-15 00:16:30 +05:00
|
|
|
}
|
|
|
|
|
2009-11-02 23:19:58 +01:00
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
my_bool vio_is_connected_pipe(Vio *vio)
|
|
|
|
{
|
|
|
|
if (PeekNamedPipe(vio->hPipe, NULL, 0, NULL, NULL, NULL))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return (GetLastError() != ERROR_BROKEN_PIPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-15 00:16:30 +05:00
|
|
|
int vio_close_pipe(Vio * vio)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
DBUG_ENTER("vio_close_pipe");
|
2009-11-02 23:19:58 +01:00
|
|
|
|
2002-11-15 00:16:30 +05:00
|
|
|
CancelIo(vio->hPipe);
|
2009-11-02 23:19:58 +01:00
|
|
|
CloseHandle(vio->pipe_overlapped.hEvent);
|
2002-11-15 00:16:30 +05:00
|
|
|
DisconnectNamedPipe(vio->hPipe);
|
2009-11-02 23:19:58 +01:00
|
|
|
r= CloseHandle(vio->hPipe);
|
2002-11-15 00:16:30 +05:00
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("vio_error", ("close() failed, error: %d",GetLastError()));
|
|
|
|
/* FIXME: error handling (not critical for MySQL) */
|
|
|
|
}
|
|
|
|
vio->type= VIO_CLOSED;
|
|
|
|
vio->sd= -1;
|
|
|
|
DBUG_RETURN(r);
|
|
|
|
}
|
|
|
|
|
2003-12-15 17:58:15 +02:00
|
|
|
|
2009-11-02 23:19:58 +01:00
|
|
|
void vio_win32_timeout(Vio *vio, uint which , uint timeout_sec)
|
2003-12-15 17:58:15 +02:00
|
|
|
{
|
2009-11-20 13:09:50 +01:00
|
|
|
DWORD timeout_ms;
|
2009-11-02 23:19:58 +01:00
|
|
|
/*
|
|
|
|
Windows is measuring timeouts in milliseconds. Check for possible int
|
|
|
|
overflow.
|
|
|
|
*/
|
|
|
|
if (timeout_sec > UINT_MAX/1000)
|
2009-11-20 13:09:50 +01:00
|
|
|
timeout_ms= INFINITE;
|
2009-11-02 23:19:58 +01:00
|
|
|
else
|
2009-11-20 13:09:50 +01:00
|
|
|
timeout_ms= timeout_sec * 1000;
|
2009-11-02 23:19:58 +01:00
|
|
|
|
|
|
|
/* which == 1 means "write", which == 0 means "read".*/
|
|
|
|
if(which)
|
2009-11-20 13:09:50 +01:00
|
|
|
vio->write_timeout_ms= timeout_ms;
|
2009-11-02 23:19:58 +01:00
|
|
|
else
|
2009-11-20 13:09:50 +01:00
|
|
|
vio->read_timeout_ms= timeout_ms;
|
2003-12-15 17:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-15 00:16:30 +05:00
|
|
|
#ifdef HAVE_SMEM
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_read_shared_memory(Vio * vio, uchar* buf, size_t size)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t length;
|
|
|
|
size_t remain_local;
|
2002-11-15 00:16:30 +05:00
|
|
|
char *current_postion;
|
2009-03-26 20:17:27 -03:00
|
|
|
HANDLE events[2];
|
2002-11-15 00:16:30 +05:00
|
|
|
|
|
|
|
DBUG_ENTER("vio_read_shared_memory");
|
2006-05-31 14:55:28 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf,
|
|
|
|
size));
|
2002-11-15 00:16:30 +05:00
|
|
|
|
|
|
|
remain_local = size;
|
|
|
|
current_postion=buf;
|
2009-03-26 20:17:27 -03:00
|
|
|
|
|
|
|
events[0]= vio->event_server_wrote;
|
|
|
|
events[1]= vio->event_conn_closed;
|
|
|
|
|
2003-10-17 13:17:15 +02:00
|
|
|
do
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
2003-10-17 13:17:15 +02:00
|
|
|
if (vio->shared_memory_remain == 0)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
2004-12-14 19:24:19 +05:00
|
|
|
/*
|
|
|
|
WaitForMultipleObjects can return next values:
|
|
|
|
WAIT_OBJECT_0+0 - event from vio->event_server_wrote
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read
|
|
|
|
anything
|
2004-12-14 19:24:19 +05:00
|
|
|
WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail. We can't read anything
|
|
|
|
*/
|
2009-03-26 20:17:27 -03:00
|
|
|
if (WaitForMultipleObjects(array_elements(events), events, FALSE,
|
2009-11-20 13:09:50 +01:00
|
|
|
vio->read_timeout_ms) != WAIT_OBJECT_0)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
};
|
2004-12-14 19:24:19 +05:00
|
|
|
|
2002-11-15 00:16:30 +05:00
|
|
|
vio->shared_memory_pos = vio->handle_map;
|
|
|
|
vio->shared_memory_remain = uint4korr((ulong*)vio->shared_memory_pos);
|
|
|
|
vio->shared_memory_pos+=4;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = size;
|
|
|
|
|
2003-10-17 13:17:15 +02:00
|
|
|
if (vio->shared_memory_remain < length)
|
2002-11-15 00:16:30 +05:00
|
|
|
length = vio->shared_memory_remain;
|
2003-10-17 13:17:15 +02:00
|
|
|
if (length > remain_local)
|
2002-11-15 00:16:30 +05:00
|
|
|
length = remain_local;
|
|
|
|
|
|
|
|
memcpy(current_postion,vio->shared_memory_pos,length);
|
|
|
|
|
|
|
|
vio->shared_memory_remain-=length;
|
|
|
|
vio->shared_memory_pos+=length;
|
|
|
|
current_postion+=length;
|
|
|
|
remain_local-=length;
|
|
|
|
|
2003-10-17 13:17:15 +02:00
|
|
|
if (!vio->shared_memory_remain)
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
{
|
|
|
|
if (!SetEvent(vio->event_client_read))
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
} while (remain_local);
|
|
|
|
length = size;
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("exit", ("%lu", (ulong) length));
|
2002-11-15 00:16:30 +05:00
|
|
|
DBUG_RETURN(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t vio_write_shared_memory(Vio * vio, const uchar* buf, size_t size)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t length, remain, sz;
|
2002-11-15 00:16:30 +05:00
|
|
|
HANDLE pos;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
const uchar *current_postion;
|
2009-03-26 20:25:10 -03:00
|
|
|
HANDLE events[2];
|
2002-11-15 00:16:30 +05:00
|
|
|
|
|
|
|
DBUG_ENTER("vio_write_shared_memory");
|
2006-05-31 14:55:28 +03:00
|
|
|
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf,
|
|
|
|
size));
|
2002-11-15 00:16:30 +05:00
|
|
|
|
|
|
|
remain = size;
|
|
|
|
current_postion = buf;
|
2009-03-26 20:17:27 -03:00
|
|
|
|
|
|
|
events[0]= vio->event_server_read;
|
|
|
|
events[1]= vio->event_conn_closed;
|
|
|
|
|
2003-10-17 13:17:15 +02:00
|
|
|
while (remain != 0)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
2009-03-26 20:17:27 -03:00
|
|
|
if (WaitForMultipleObjects(array_elements(events), events, FALSE,
|
2009-11-20 13:09:50 +01:00
|
|
|
vio->write_timeout_ms) != WAIT_OBJECT_0)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_RETURN((size_t) -1);
|
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
sz= (remain > shared_memory_buffer_length ? shared_memory_buffer_length :
|
|
|
|
remain);
|
2002-11-15 00:16:30 +05:00
|
|
|
|
|
|
|
int4store(vio->handle_map,sz);
|
|
|
|
pos = vio->handle_map + 4;
|
|
|
|
memcpy(pos,current_postion,sz);
|
|
|
|
remain-=sz;
|
|
|
|
current_postion+=sz;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
if (!SetEvent(vio->event_client_wrote))
|
|
|
|
DBUG_RETURN((size_t) -1);
|
2002-11-15 00:16:30 +05:00
|
|
|
}
|
|
|
|
length = size;
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
DBUG_PRINT("exit", ("%lu", (ulong) length));
|
2002-11-15 00:16:30 +05:00
|
|
|
DBUG_RETURN(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-10 17:36:38 -02:00
|
|
|
my_bool vio_is_connected_shared_memory(Vio *vio)
|
|
|
|
{
|
|
|
|
return (WaitForSingleObject(vio->event_conn_closed, 0) != WAIT_OBJECT_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-08 11:39:03 -04:00
|
|
|
/**
|
|
|
|
Close shared memory and DBUG_PRINT any errors that happen on closing.
|
|
|
|
@return Zero if all closing functions succeed, and nonzero otherwise.
|
|
|
|
*/
|
2002-11-15 00:16:30 +05:00
|
|
|
int vio_close_shared_memory(Vio * vio)
|
|
|
|
{
|
2006-09-08 11:39:03 -04:00
|
|
|
int error_count= 0;
|
2002-11-15 00:16:30 +05:00
|
|
|
DBUG_ENTER("vio_close_shared_memory");
|
2004-12-14 19:24:19 +05:00
|
|
|
if (vio->type != VIO_CLOSED)
|
2002-11-15 00:16:30 +05:00
|
|
|
{
|
2004-12-23 16:04:40 +05:00
|
|
|
/*
|
|
|
|
Set event_conn_closed for notification of both client and server that
|
|
|
|
connection is closed
|
|
|
|
*/
|
2004-12-14 19:24:19 +05:00
|
|
|
SetEvent(vio->event_conn_closed);
|
2004-12-23 16:04:40 +05:00
|
|
|
/*
|
|
|
|
Close all handlers. UnmapViewOfFile and CloseHandle return non-zero
|
|
|
|
result if they are success.
|
|
|
|
*/
|
2006-03-17 18:46:34 +01:00
|
|
|
if (UnmapViewOfFile(vio->handle_map) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("UnmapViewOfFile() failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->event_server_wrote) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->esw) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->event_server_read) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->esr) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->event_client_wrote) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecw) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->event_client_read) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecr) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->handle_file_map) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->hfm) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2006-03-17 18:46:34 +01:00
|
|
|
if (CloseHandle(vio->event_conn_closed) == 0)
|
2006-09-08 11:39:03 -04:00
|
|
|
{
|
|
|
|
error_count++;
|
2006-03-17 18:46:34 +01:00
|
|
|
DBUG_PRINT("vio_error", ("CloseHandle(vio->ecc) failed"));
|
2006-09-08 11:39:03 -04:00
|
|
|
}
|
2002-11-15 00:16:30 +05:00
|
|
|
}
|
|
|
|
vio->type= VIO_CLOSED;
|
|
|
|
vio->sd= -1;
|
2006-09-08 11:39:03 -04:00
|
|
|
DBUG_RETURN(error_count);
|
2002-11-15 00:16:30 +05:00
|
|
|
}
|
2003-08-29 13:44:35 +03:00
|
|
|
#endif /* HAVE_SMEM */
|
|
|
|
#endif /* __WIN__ */
|
2009-11-21 02:12:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Number of bytes in the read buffer.
|
|
|
|
|
|
|
|
@return number of bytes in the read buffer or < 0 if error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ssize_t vio_pending(Vio *vio)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
SSL *ssl= (SSL*) vio->ssl_arg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (vio->read_pos < vio->read_end)
|
|
|
|
return vio->read_end - vio->read_pos;
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
if (ssl)
|
|
|
|
return SSL_pending(ssl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-25 13:53:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a wrapper for the system getnameinfo(), because different OS
|
|
|
|
differ in the getnameinfo() implementation. For instance, Solaris 10
|
|
|
|
requires that the 2nd argument (salen) must match the actual size of the
|
|
|
|
struct sockaddr_storage passed to it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int vio_getnameinfo(const struct sockaddr *sa,
|
|
|
|
char *hostname, size_t hostname_size,
|
|
|
|
char *port, size_t port_size,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
int sa_length= 0;
|
|
|
|
|
|
|
|
switch (sa->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
sa_length= sizeof (struct sockaddr_in);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
case AF_INET6:
|
|
|
|
sa_length= sizeof (struct sockaddr_in6);
|
|
|
|
break;
|
|
|
|
#endif /* HAVE_IPV6 */
|
|
|
|
}
|
|
|
|
|
|
|
|
return getnameinfo(sa, sa_length,
|
|
|
|
hostname, hostname_size,
|
|
|
|
port, port_size,
|
|
|
|
flags);
|
|
|
|
}
|