~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to server-tools/instance-manager/buffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H
 
2
#define INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H
 
3
/* Copyright (C) 2004 MySQL AB
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; version 2 of the License.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
17
 
 
18
#include <my_global.h>
 
19
#include <my_sys.h>
 
20
 
 
21
#if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
 
22
#pragma interface
 
23
#endif
 
24
 
 
25
/*
 
26
  This class is a simple implementation of the buffer of varying size.
 
27
  It is used to store MySQL client-server protocol packets. This is why
 
28
  the maximum buffer size if 16Mb. (See internals manual section
 
29
  7. MySQL Client/Server Protocol)
 
30
*/
 
31
 
 
32
class Buffer
 
33
{
 
34
private:
 
35
  static const uint BUFFER_INITIAL_SIZE;
 
36
  /* maximum buffer size is 16Mb */
 
37
  static const uint MAX_BUFFER_SIZE;
 
38
  size_t buffer_size;
 
39
  /* Error flag. Triggered if we get an error of some kind */
 
40
  int error;
 
41
public:
 
42
  Buffer(size_t buffer_size_arg= BUFFER_INITIAL_SIZE)
 
43
    :buffer_size(buffer_size_arg), error(0)
 
44
  {
 
45
    /*
 
46
      As append() will invokes realloc() anyway, it's ok if malloc returns 0
 
47
    */
 
48
    if (!(buffer= (uchar*) my_malloc(buffer_size, MYF(0))))
 
49
        buffer_size= 0;
 
50
  }
 
51
 
 
52
  ~Buffer()
 
53
  {
 
54
    my_free(buffer, MYF(0));
 
55
  }
 
56
 
 
57
public:
 
58
  uchar *buffer;
 
59
  int get_size();
 
60
  int is_error();
 
61
  int append(size_t position, const char *string, size_t len_arg);
 
62
  int reserve(size_t position, size_t len_arg);
 
63
};
 
64
 
 
65
#endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_BUFFER_H */