MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SHM_Transporter.hpp
1 /*
2  Copyright (C) 2003-2006, 2008 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef SHM_Transporter_H
20 #define SHM_Transporter_H
21 
22 #include "Transporter.hpp"
23 #include "SHM_Buffer.hpp"
24 
25 #ifdef NDB_WIN32
26 typedef Uint32 key_t;
27 #endif
28 
34 class SHM_Transporter : public Transporter {
35  friend class TransporterRegistry;
36 public:
38  const char *lHostName,
39  const char *rHostName,
40  int r_port,
41  bool isMgmConnection,
42  NodeId lNodeId,
43  NodeId rNodeId,
44  NodeId serverNodeId,
45  bool checksum,
46  bool signalId,
47  key_t shmKey,
48  Uint32 shmSize);
49 
53  virtual ~SHM_Transporter();
54 
55  virtual bool configure_derived(const TransporterConfiguration* conf);
56 
60  bool initTransporter();
61 
62  void getReceivePtr(Uint32 ** ptr, Uint32 ** eod){
63  reader->getReadPtr(* ptr, * eod);
64  }
65 
66  void updateReceivePtr(Uint32 * ptr){
67  reader->updateReadPtr(ptr);
68  }
69 
70 protected:
76  void disconnectImpl();
77 
90  virtual bool connect_server_impl(NDB_SOCKET_TYPE sockfd);
91 
104  virtual bool connect_client_impl(NDB_SOCKET_TYPE sockfd);
105 
106  bool connect_common(NDB_SOCKET_TYPE sockfd);
107 
108  bool ndb_shm_create();
109  bool ndb_shm_get();
110  bool ndb_shm_attach();
111 
116  bool checkConnected();
117 
118 
122  void setupBuffers();
123 
127  int doSend();
128  int m_remote_pid;
129  Uint32 m_signal_threshold;
130 
131 private:
132  bool _shmSegCreated;
133  bool _attached;
134  bool m_connected;
135 
136  key_t shmKey;
137  volatile Uint32 * serverStatusFlag;
138  volatile Uint32 * clientStatusFlag;
139  bool setupBuffersDone;
140 
141 #ifdef NDB_WIN32
142  HANDLE hFileMapping;
143 #else
144  int shmId;
145 #endif
146 
147  int shmSize;
148  char * shmBuf;
149 
150  SHM_Reader * reader;
151  SHM_Writer * writer;
152 
156  bool hasDataToRead() const {
157  return reader->empty() == false;
158  }
159 
160  void make_error_info(char info[], int sz);
161 
162  bool send_limit_reached(int bufsize)
163  {
164  return ((Uint32)bufsize >= m_signal_threshold);
165  }
166  bool send_is_possible(int timeout_millisec) const { return 1; }
167 };
168 
169 #endif