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

« back to all changes in this revision

Viewing changes to storage/ndb/src/common/transporter/SendBuffer.cpp

  • 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
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "SendBuffer.hpp"
 
17
#include "TransporterInternalDefinitions.hpp"
 
18
 
 
19
SendBuffer::SendBuffer(Uint32 bufSize) {
 
20
 
 
21
  sizeOfBuffer = bufSize;
 
22
  if(sizeOfBuffer < MAX_MESSAGE_SIZE)
 
23
    sizeOfBuffer = 2 * MAX_MESSAGE_SIZE; 
 
24
  startOfBuffer = NULL;
 
25
 
 
26
  // Initalise pointers 
 
27
  endOfBuffer = NULL;
 
28
  insertPtr = NULL;
 
29
  sendPtr = NULL;
 
30
  sendDataSize = 0;
 
31
  dataSize = 0;
 
32
}
 
33
 
 
34
bool
 
35
SendBuffer::initBuffer(Uint32 aRemoteNodeId) {
 
36
 
 
37
  // Allocate memory for the buffer
 
38
#ifdef DEBUG_TRANSPORTER
 
39
  ndbout << "Allocating " << sizeOfBuffer << " bytes for send buffer" << endl;
 
40
#endif
 
41
 
 
42
  startOfBuffer = new Uint32[(sizeOfBuffer >> 2) + 1];
 
43
  endOfBuffer   = startOfBuffer + (sizeOfBuffer >> 2);
 
44
  
 
45
  emptyBuffer();
 
46
  theRemoteNodeId = aRemoteNodeId;
 
47
  return true;
 
48
}
 
49
 
 
50
SendBuffer::~SendBuffer() {
 
51
  // Deallocate the buffer memory
 
52
  if(startOfBuffer != NULL)
 
53
    delete[] startOfBuffer;
 
54
}
 
55
 
 
56
int
 
57
SendBuffer::bufferSize() {
 
58
  return dataSize;
 
59
}
 
60
 
 
61
Uint32
 
62
SendBuffer::bufferSizeRemaining() const {
 
63
  return (sizeOfBuffer - dataSize);
 
64
}
 
65
 
 
66
void
 
67
SendBuffer::emptyBuffer() {
 
68
  insertPtr    = startOfBuffer;
 
69
  sendPtr      = (char*)startOfBuffer;
 
70
  dataSize     = 0;
 
71
  sendDataSize = 0;
 
72
}
 
73
 
 
74
#ifdef DEBUG_TRANSPORTER
 
75
void
 
76
SendBuffer::print() {
 
77
  
 
78
  printf("SendBuffer status printouts\n");
 
79
  
 
80
  printf( "sizeOfBuffer:  %d\n", sizeOfBuffer);
 
81
  printf( "startOfBuffer: %.8x\n", startOfBuffer);
 
82
  printf( "endOfBuffer:   %.8x\n", endOfBuffer);
 
83
  printf( "insertPtr:     %.8x\n", insertPtr);
 
84
  printf( "sendPtr:       %.8x\n", sendPtr);
 
85
  printf( "sendDataSize:  %d\n", sendDataSize);
 
86
  printf( "dataSize:      %d\n", dataSize);
 
87
}
 
88
#endif