18 #include <ndb_global.h>
20 #include "Loopback_Transporter.hpp"
24 #include <EventLogger.hpp>
33 assert(isServer ==
false);
36 Loopback_Transporter::~Loopback_Transporter()
41 Loopback_Transporter::connect_client()
43 NDB_SOCKET_TYPE pair[2];
44 if (my_socketpair(pair))
46 perror(
"socketpair failed!");
50 if (!TCP_Transporter::setSocketNonBlocking(pair[0]) ||
51 !TCP_Transporter::setSocketNonBlocking(pair[1]))
57 m_send_socket = pair[1];
62 my_socket_close(pair[0]);
63 my_socket_close(pair[1]);
68 Loopback_Transporter::disconnectImpl()
70 NDB_SOCKET_TYPE pair[] = { theSocket, m_send_socket };
74 receiveBuffer.clear();
75 my_socket_invalidate(&theSocket);
76 my_socket_invalidate(&m_send_socket);
78 get_callback_obj()->unlock_transporter(remoteNodeId);
80 if (my_socket_valid(pair[0]))
81 my_socket_close(pair[0]);
83 if (my_socket_valid(pair[1]))
84 my_socket_close(pair[1]);
88 Loopback_Transporter::send_is_possible(
int timeout_millisec)
const
90 return TCP_Transporter::send_is_possible(m_send_socket, timeout_millisec);
93 #define DISCONNECT_ERRNO(e, sz) ((sz == 0) || \
94 (!((sz == -1) && ((e == SOCKET_EAGAIN) || (e == SOCKET_EWOULDBLOCK) || (e == SOCKET_EINTR)))))
97 Loopback_Transporter::doSend() {
107 for(Uint32
i = 0;
i<cnt;
i++)
109 assert(iov[
i].iov_len);
110 sum += iov[
i].iov_len;
118 if (cnt == NDB_ARRAY_SIZE(iov))
128 Uint32 iovcnt = cnt > m_os_max_iovec ? m_os_max_iovec : cnt;
129 int nBytesSent = (int)my_socket_writev(m_send_socket, iov+pos, iovcnt);
130 assert(nBytesSent <= (
int)remain);
132 if (Uint32(nBytesSent) == remain)
134 sum_sent += nBytesSent;
137 else if (nBytesSent > 0)
139 sum_sent += nBytesSent;
140 remain -= nBytesSent;
145 while (Uint32(nBytesSent) >= iov[pos].iov_len)
147 assert(iov[pos].iov_len > 0);
148 nBytesSent -= iov[pos].iov_len;
155 assert(iov[pos].iov_len > Uint32(nBytesSent));
156 iov[pos].iov_len -= nBytesSent;
157 iov[pos].iov_base = ((
char*)(iov[pos].iov_base))+nBytesSent;
163 int err = my_socket_errno();
164 if (!(DISCONNECT_ERRNO(err, nBytesSent)))
182 assert(sum >= sum_sent);
183 iovec_data_sent(sum_sent);
184 sendCount += send_cnt;
185 sendSize += sum_sent;
186 if(sendCount >= reportFreq)
188 get_callback_obj()->
reportSendLen(remoteNodeId, sendCount, sendSize);
193 return sum - sum_sent;