Skip to content

Commit 8d35a3a

Browse files
committed
WL#15130 Socket-level TLS patch mysql#3: ndb_socket_poller
In ndb_socket_poller, check read sockets for SSL pending data. Change-Id: If3aa3897a5decaeaf2309031590f89bc27d4685c
1 parent c5f91bd commit 8d35a3a

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

storage/ndb/include/portlib/ndb_socket_poller.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class ndb_socket_poller {
3939
// Current number of fds in the list
4040
unsigned m_count;
4141

42+
// Number of sockets with SSL data ready to read when they
43+
// were added to the list.
44+
unsigned m_ssl_pending;
45+
4246
// The list of pollfds, initial size is 1 and m_pfds will
4347
// then point at m_one_pfd. After dynamic expand points at
4448
// dynamic list of pollfds
@@ -56,6 +60,7 @@ class ndb_socket_poller {
5660

5761
void clear(void) {
5862
m_count = 0;
63+
m_ssl_pending = 0;
5964
}
6065

6166
~ndb_socket_poller() {
@@ -67,9 +72,7 @@ class ndb_socket_poller {
6772

6873
unsigned add(ndb_socket_t sock, bool read, bool write);
6974

70-
unsigned add_readable(ndb_socket_t sock) {
71-
return add(sock, true, false);
72-
}
75+
unsigned add_readable(ndb_socket_t sock, struct ssl_st *ssl = nullptr);
7376

7477
unsigned add_writable(ndb_socket_t sock) {
7578
return add(sock, false, true);

storage/ndb/include/util/NdbSocket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void NdbSocket::close_with_reset(bool with_reset) {
263263
/* ndb_socket_poller.h */
264264
inline
265265
uint NdbSocket::add_readable(ndb_socket_poller * poller) const {
266-
return poller->add_readable(s);
266+
return poller->add_readable(s, ssl);
267267
}
268268

269269
inline
@@ -274,7 +274,7 @@ uint NdbSocket::add_writable(ndb_socket_poller * poller) const {
274274
inline
275275
int NdbSocket::poll_readable(int timeout) const {
276276
ndb_socket_poller poller;
277-
poller.add_readable(s);
277+
poller.add_readable(s, ssl);
278278
return poller.poll(timeout);
279279
}
280280

storage/ndb/src/common/portlib/ndb_socket_poller.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ bool ndb_socket_poller::set_max_count(unsigned count)
4747
return true;
4848
}
4949

50+
unsigned int
51+
ndb_socket_poller::add_readable(ndb_socket_t sock, SSL * ssl)
52+
{
53+
if(ssl && SSL_pending(ssl))
54+
{
55+
assert(m_count < m_max_count);
56+
const unsigned index = m_count;
57+
m_ssl_pending++;
58+
posix_poll_fd &pfd = m_pfds[m_count++];
59+
pfd.events = 0; // don't actually poll
60+
pfd.revents = POLLIN; // show that socket is ready to read
61+
return index;
62+
}
63+
64+
return add(sock, true, false);
65+
}
5066

5167
unsigned int
5268
ndb_socket_poller::add(ndb_socket_t sock, bool read, bool write)
@@ -73,14 +89,18 @@ ndb_socket_poller::add(ndb_socket_t sock, bool read, bool write)
7389
int
7490
ndb_socket_poller::poll(int timeout)
7591
{
92+
if(m_ssl_pending > 0 && m_ssl_pending == m_count)
93+
return m_ssl_pending; // no need to actually poll
7694

7795
do
7896
{
7997
const NDB_TICKS start = NdbTick_getCurrentTicks();
8098

8199
const int res = poll_unsafe(timeout);
82100
if (likely(res >= 0))
83-
return res;
101+
return res + m_ssl_pending;
102+
else if(m_ssl_pending)
103+
return m_ssl_pending;
84104

85105
const int error = ndb_socket_errno();
86106
if (res == -1 && (error == EINTR || error == EAGAIN))

0 commit comments

Comments
 (0)