2004-10-23 11:32:52 +04:00
|
|
|
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H
|
|
|
|
#define INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H
|
|
|
|
/* Copyright (C) 2004 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.
|
2004-10-23 11:32:52 +04:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
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 */
|
|
|
|
|
|
|
|
#include <my_global.h>
|
2005-02-13 15:13:33 +03:00
|
|
|
#include <my_sys.h>
|
2004-10-23 11:32:52 +04:00
|
|
|
|
2005-09-23 21:28:56 +03:00
|
|
|
#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
|
2004-10-23 11:32:52 +04:00
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
This class is a simple implementation of the buffer of varying size.
|
|
|
|
It is used to store MySQL client-server protocol packets. This is why
|
|
|
|
the maximum buffer size if 16Mb. (See internals manual section
|
|
|
|
7. MySQL Client/Server Protocol)
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Buffer
|
|
|
|
{
|
|
|
|
private:
|
2005-09-20 03:14:07 +04:00
|
|
|
static const uint BUFFER_INITIAL_SIZE;
|
2004-10-23 11:32:52 +04:00
|
|
|
/* maximum buffer size is 16Mb */
|
2005-09-20 03:14:07 +04:00
|
|
|
static const uint MAX_BUFFER_SIZE;
|
2004-10-26 23:22:12 +04:00
|
|
|
size_t buffer_size;
|
2005-02-11 14:21:59 +03:00
|
|
|
/* Error flag. Triggered if we get an error of some kind */
|
|
|
|
int error;
|
2004-10-23 11:32:52 +04:00
|
|
|
public:
|
2005-02-11 14:21:59 +03:00
|
|
|
Buffer(size_t buffer_size_arg= BUFFER_INITIAL_SIZE)
|
2005-02-27 18:41:34 +03:00
|
|
|
:buffer_size(buffer_size_arg), error(0)
|
2004-10-23 11:32:52 +04:00
|
|
|
{
|
2005-02-11 14:21:59 +03:00
|
|
|
/*
|
|
|
|
As append() will invokes realloc() anyway, it's ok if malloc returns 0
|
|
|
|
*/
|
2005-02-13 15:13:33 +03:00
|
|
|
if (!(buffer= (char*) my_malloc(buffer_size, MYF(0))))
|
2005-02-11 14:21:59 +03:00
|
|
|
buffer_size= 0;
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~Buffer()
|
|
|
|
{
|
2005-06-01 04:40:22 +04:00
|
|
|
my_free(buffer, MYF(0));
|
2004-10-23 11:32:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
char *buffer;
|
2005-02-11 14:21:59 +03:00
|
|
|
int get_size();
|
|
|
|
int is_error();
|
2004-10-26 23:22:12 +04:00
|
|
|
int append(uint position, const char *string, uint len_arg);
|
2004-10-25 14:23:31 +04:00
|
|
|
int reserve(uint position, uint len_arg);
|
2004-10-23 11:32:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H */
|