MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transporter.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef Transporter_H
19 #define Transporter_H
20 
21 #include <ndb_global.h>
22 
23 #include <SocketClient.hpp>
24 
25 #include <TransporterRegistry.hpp>
26 #include <TransporterCallback.hpp>
27 #include "TransporterDefinitions.hpp"
28 #include "Packer.hpp"
29 
30 #include <NdbMutex.h>
31 #include <NdbThread.h>
32 
33 #include <ndb_socket.h>
34 
35 class Transporter {
36  friend class TransporterRegistry;
37 public:
38  virtual bool initTransporter() = 0;
39 
43  virtual ~Transporter();
44 
49  virtual bool connect_client();
50  bool connect_client(NDB_SOCKET_TYPE sockfd);
51  bool connect_server(NDB_SOCKET_TYPE socket, BaseString& errormsg);
52 
56  virtual void doDisconnect();
57 
61  bool isConnected() const;
62 
66  NodeId getRemoteNodeId() const;
67 
71  NodeId getLocalNodeId() const;
72 
76  int get_s_port() { return m_s_port; };
77 
81  void set_s_port(int port) {
82  m_s_port = port;
83  if(port<0)
84  port= -port;
85  if(m_socket_client)
86  m_socket_client->set_port(port);
87  };
88 
89  void update_status_overloaded(Uint32 used)
90  {
91  m_transporter_registry.set_status_overloaded(remoteNodeId,
92  used >= m_overload_limit);
93  }
94 
95  virtual int doSend() = 0;
96 
97  bool has_data_to_send()
98  {
99  return get_callback_obj()->has_data_to_send(remoteNodeId);
100  }
101 
102  /* Get the configured maximum send buffer usage. */
103  Uint32 get_max_send_buffer() { return m_max_send_buffer; }
104 
105 protected:
107  TransporterType,
108  const char *lHostName,
109  const char *rHostName,
110  int s_port,
111  bool isMgmConnection,
112  NodeId lNodeId,
113  NodeId rNodeId,
114  NodeId serverNodeId,
115  int byteorder,
116  bool compression,
117  bool checksum,
118  bool signalId,
119  Uint32 max_send_buffer);
120 
121  virtual bool configure(const TransporterConfiguration* conf);
122  virtual bool configure_derived(const TransporterConfiguration* conf) = 0;
123 
128  virtual bool connect_server_impl(NDB_SOCKET_TYPE sockfd) = 0;
129  virtual bool connect_client_impl(NDB_SOCKET_TYPE sockfd) = 0;
130  virtual int pre_connect_options(NDB_SOCKET_TYPE sockfd) { return 0;}
131 
135  virtual void disconnectImpl() = 0;
136 
140  char remoteHostName[256];
141  char localHostName[256];
142  struct in_addr remoteHostAddress;
143  struct in_addr localHostAddress;
144 
145  int m_s_port;
146 
147  const NodeId remoteNodeId;
148  const NodeId localNodeId;
149 
150  const bool isServer;
151 
152  unsigned createIndex;
153 
154  int byteOrder;
155  bool compressionUsed;
156  bool checksumUsed;
157  bool signalIdUsed;
158  Packer m_packer;
159  Uint32 m_max_send_buffer;
160  /* Overload limit, as configured with the OverloadLimit config parameter. */
161  Uint32 m_overload_limit;
162 
163 private:
164 
169  bool isMgmConnection;
170 
171  SocketClient *m_socket_client;
172  struct in_addr m_connect_address;
173 
174  virtual bool send_is_possible(int timeout_millisec) const = 0;
175  virtual bool send_limit_reached(int bufsize) = 0;
176 
177 protected:
178  Uint32 m_os_max_iovec;
179  Uint32 m_timeOutMillis;
180  bool m_connected; // Are we connected
181  TransporterType m_type;
182 
183  TransporterRegistry &m_transporter_registry;
184  TransporterCallback *get_callback_obj() { return m_transporter_registry.callbackObj; };
185  void do_disconnect(int err){m_transporter_registry.do_disconnect(remoteNodeId,err);};
186  void report_error(enum TransporterError err, const char *info = 0)
187  { m_transporter_registry.report_error(remoteNodeId, err, info); };
188 
189  Uint32 fetch_send_iovec_data(struct iovec dst[], Uint32 cnt);
190  void iovec_data_sent(int nBytesSent);
191 };
192 
193 inline
194 bool
196  return m_connected;
197 }
198 
199 inline
200 NodeId
202  return remoteNodeId;
203 }
204 
205 inline
206 NodeId
208  return localNodeId;
209 }
210 
215 inline
216 Uint32
217 Transporter::fetch_send_iovec_data(struct iovec dst[], Uint32 cnt)
218 {
219  return get_callback_obj()->get_bytes_to_send_iovec(remoteNodeId,
220  dst, cnt);
221 }
222 
223 inline
224 void
225 Transporter::iovec_data_sent(int nBytesSent)
226 {
227  Uint32 used_bytes
228  = get_callback_obj()->bytes_sent(remoteNodeId, nBytesSent);
229  update_status_overloaded(used_bytes);
230 }
231 
232 #endif // Define of Transporter_H