mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / src / common / transporter / SHM_Transporter.hpp
blob9363649c60ab67d6108dc3959a142f29b3d9e155
1 /* Copyright (c) 2003-2005 MySQL AB
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #ifndef SHM_Transporter_H
17 #define SHM_Transporter_H
19 #include "Transporter.hpp"
20 #include "SHM_Buffer.hpp"
22 #ifdef NDB_WIN32
23 typedef Uint32 key_t;
24 #endif
26 /**
27 * class SHMTransporter
28 * @brief - main class for the SHM transporter.
31 class SHM_Transporter : public Transporter {
32 friend class TransporterRegistry;
33 public:
34 SHM_Transporter(TransporterRegistry &,
35 const char *lHostName,
36 const char *rHostName,
37 int r_port,
38 bool isMgmConnection,
39 NodeId lNodeId,
40 NodeId rNodeId,
41 NodeId serverNodeId,
42 bool checksum,
43 bool signalId,
44 key_t shmKey,
45 Uint32 shmSize);
47 /**
48 * SHM destructor
50 virtual ~SHM_Transporter();
52 /**
53 * Do initialization
55 bool initTransporter();
57 Uint32 * getWritePtr(Uint32 lenBytes, Uint32 prio)
59 return (Uint32 *)writer->getWritePtr(lenBytes);
62 void updateWritePtr(Uint32 lenBytes, Uint32 prio)
64 writer->updateWritePtr(lenBytes);
65 m_last_signal += lenBytes;
66 if(m_last_signal >= m_signal_threshold)
68 doSend();
72 void getReceivePtr(Uint32 ** ptr, Uint32 ** eod){
73 reader->getReadPtr(* ptr, * eod);
76 void updateReceivePtr(Uint32 * ptr){
77 reader->updateReadPtr(ptr);
80 protected:
81 /**
82 * disconnect a segmnet
83 * -# deletes the shm buffer associated with a segment
84 * -# marks the segment for removal
86 void disconnectImpl();
88 /**
89 * Blocking
91 * -# Create shm segment
92 * -# Attach to it
93 * -# Wait for someone to attach (max wait = timeout), then rerun again
94 * until connection established.
95 * @param timeOutMillis - the time to sleep before (ms) trying again.
96 * @returns - True if the server managed to hook up with the client,
97 * i.e., both agrees that the other one has setup the segment.
98 * Otherwise false.
100 virtual bool connect_server_impl(NDB_SOCKET_TYPE sockfd);
103 * Blocking
105 * -# Attach to shm segment
106 * -# Check if the segment is setup
107 * -# Check if the server set it up
108 * -# If all clear, return.
109 * @param timeOutMillis - the time to sleep before (ms) trying again.
110 * @returns - True if the client managed to hook up with the server,
111 * i.e., both agrees that the other one has setup the segment.
112 * Otherwise false.
114 virtual bool connect_client_impl(NDB_SOCKET_TYPE sockfd);
116 bool connect_common(NDB_SOCKET_TYPE sockfd);
118 bool ndb_shm_create();
119 bool ndb_shm_get();
120 bool ndb_shm_attach();
123 * Check if there are two processes attached to the segment (a connection)
124 * @return - True if the above holds. Otherwise false.
126 bool checkConnected();
130 * Initialises the SHM_Reader and SHM_Writer on the segment
132 void setupBuffers();
135 * doSend (i.e signal receiver)
137 void doSend();
138 int m_remote_pid;
139 Uint32 m_last_signal;
140 Uint32 m_signal_threshold;
142 virtual Uint32 get_free_buffer() const;
144 private:
145 bool _shmSegCreated;
146 bool _attached;
147 bool m_connected;
149 key_t shmKey;
150 volatile Uint32 * serverStatusFlag;
151 volatile Uint32 * clientStatusFlag;
152 bool setupBuffersDone;
154 #ifdef NDB_WIN32
155 HANDLE hFileMapping;
156 #else
157 int shmId;
158 #endif
160 int shmSize;
161 char * shmBuf;
163 SHM_Reader * reader;
164 SHM_Writer * writer;
167 * @return - True if the reader has data to read on its segment.
169 bool hasDataToRead() const {
170 return reader->empty() == false;
173 void make_error_info(char info[], int sz);
176 #endif