Skip to content

Commit 1591fab

Browse files
author
Andre Negrao
committed
Bug#26695357 SOME SELECTS STILL PRESENT IN XCOM CODE
Description: ----------- After fixing parent issue BUG#25892493, one noticed that selects are still present in XCom client code, which is used to connect from GR/GCS to the XCom running thread. Fix: --- This patch removes the two 'select()' calls that were still present in XCom: - In timed_connect(), the select is replaced by a poll function; - All code enclosed by '#ifdef USE_SELECT' has been removed, including a select() call contained inside one function implemented within one such conditional block.
1 parent b35783e commit 1591fab

File tree

4 files changed

+98
-259
lines changed

4 files changed

+98
-259
lines changed

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.c

Lines changed: 1 addition & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@
7373
#include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_cfg.h"
7474

7575
#ifndef _WIN32
76-
#ifndef USE_SELECT
7776
#include <poll.h>
7877
#endif
79-
#endif
8078

8179
#include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/retry.h"
8280
#include "plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xdr_utils.h"
@@ -88,15 +86,6 @@ task_arg null_arg = {a_end, {0}};
8886
struct iotasks;
8987
typedef struct iotasks iotasks;
9088

91-
#ifdef USE_SELECT
92-
struct iotasks {
93-
int maxfd;
94-
fd_set read_set;
95-
fd_set write_set;
96-
fd_set err_set;
97-
linkage tasks; /* OHKFIX Should be one each for read and write */
98-
};
99-
#else
10089
typedef struct {
10190
u_int pollfd_array_len;
10291
pollfd *pollfd_array_val;
@@ -117,7 +106,7 @@ struct iotasks {
117106
pollfd_array fd;
118107
task_env_p_array tasks;
119108
};
120-
#endif
109+
121110
int task_errno = 0;
122111
static task_env *extract_first_delayed();
123112
static task_env *task_ref(task_env *t);
@@ -593,149 +582,7 @@ static task_env *extract_first_delayed() {
593582
}
594583

595584
static iotasks iot;
596-
#ifdef USE_SELECT
597-
static void iotasks_init(iotasks *iot) {
598-
iot->maxfd = 0;
599-
FD_ZERO(&iot->read_set);
600-
FD_ZERO(&iot->write_set);
601-
FD_ZERO(&iot->err_set);
602-
link_init(&iot->tasks, type_hash("task_env"));
603-
}
604-
605-
static void iotasks_deinit(iotasks *iot)
606-
{
607-
DBGOUT(FN);
608-
}
609-
610-
#if TASK_DBUG_ON
611-
static void poll_debug() MY_ATTRIBUTE((unused));
612-
static void poll_debug() {
613-
GET_GOUT;
614-
if (!IS_XCOM_DEBUG_WITH(XCOM_DEBUG_TRACE))
615-
return;
616-
#if 0
617-
NDBG(FD_SETSIZE, d);
618-
PTREXP(&iot.tasks);
619-
NDBG(iot.tasks.type, u);
620-
NDBG(cardinal(&iot.tasks), d);
621-
PTREXP(iot.tasks.suc);
622-
PTREXP(iot.tasks.pred);
623-
#endif
624-
FWD_ITER(&iot.tasks, task_env, STRLIT("->"); PTREXP(link_iter);
625-
PTREXP(link_iter->l.suc); PTREXP(link_iter->l.pred);
626-
NDBG(link_iter->waitfd, d);
627-
NDBG(FD_ISSET(link_iter->waitfd, &iot.read_set), d);
628-
NDBG(FD_ISSET(link_iter->waitfd, &iot.write_set), d);
629-
NDBG(FD_ISSET(link_iter->waitfd, &iot.err_set), d););
630-
PRINT_GOUT;
631-
FREE_GOUT;
632-
}
633-
#endif
634-
635-
static int check_completion(task_env *t, fd_set *r, fd_set *w, fd_set *e) {
636-
int interrupt = 0;
637-
assert(&t->l != &iot.tasks);
638-
/* MAY_DBG(FN;
639-
STREXP(t->name);
640-
NDBG(t->waitfd,d);
641-
NDBG(FD_ISSET(t->waitfd,r),d);
642-
NDBG(FD_ISSET(t->waitfd,w),d);
643-
NDBG(FD_ISSET(t->waitfd,e),d);
644-
); */
645-
if (FD_ISSET(t->waitfd, e)) abort(); /* Close file here instead? */
646-
interrupt = (t->time != 0.0 && t->time < task_now());
647-
if (interrupt || /* timeout ? */
648-
FD_ISSET(t->waitfd, r) || FD_ISSET(t->waitfd, w)) {
649-
FD_CLR(t->waitfd, &iot.read_set);
650-
FD_CLR(t->waitfd, &iot.write_set);
651-
FD_CLR(t->waitfd, &iot.err_set);
652-
t->interrupt = interrupt;
653-
activate(t);
654-
if (iot.maxfd - 1 == t->waitfd)
655-
iot.maxfd = t->waitfd; /* Shrink set of watched files */
656-
return 1;
657-
} else {
658-
return 0;
659-
}
660-
}
661-
662-
static int poll_wait(int ms) {
663-
/* Wait at most ms milliseconds */
664-
int wake = 0;
665-
struct timeval select_timeout;
666-
MAY_DBG(FN; NDBG(ms, d));
667-
if (ms < 0 || ms > 1000) ms = 1000; /* Wait at most 1000 ms */
668-
/* convert milliseconds to seconds and microseconds */
669-
select_timeout.tv_sec = ms / 1000;
670-
select_timeout.tv_usec = (ms % 1000) * 1000;
671-
{
672-
result nfds = {0, 0};
673-
fd_set r = iot.read_set;
674-
fd_set w = iot.write_set;
675-
fd_set e = iot.err_set;
676-
MAY_DBG(FN; poll_debug());
677-
SET_OS_ERR(0);
678-
while ((nfds.val = select(iot.maxfd, &r, &w, &e, &select_timeout)) == -1) {
679-
nfds.funerr = to_errno(GET_OS_ERR);
680-
if (hard_select_err(nfds.funerr)) {
681-
task_dump_err(nfds.funerr);
682-
DBGOUT(STRLIT("select failed"); NDBG(iot.maxfd, d));
683-
return 0;
684-
}
685-
SET_OS_ERR(0);
686-
r = iot.read_set;
687-
w = iot.write_set;
688-
e = iot.err_set;
689-
}
690-
/* MAY_DBG(FN; poll_debug()); */
691-
/* Wake up ready tasks */
692-
/* if (nfds.val > 0) { */
693-
/* FWD_ITER(&iot.tasks, task_env, */
694-
/* nfds.val -= check_completion(link_iter, &r, &w, &e); */
695-
/* if (nfds.val == 0) break); */
696-
/* } */
697-
FWD_ITER(&iot.tasks, task_env,
698-
if (check_completion(link_iter, &r, &w, &e)) wake = 1);
699-
}
700-
return wake;
701-
}
702585

703-
static void add_fd(task_env *t, int fd, int op) {
704-
MAY_DBG(FN; PTREXP(t); STREXP(t->name); NDBG(fd, d); NDBG(op, c));
705-
assert(fd >= 0);
706-
t->waitfd = fd;
707-
if (fd >= iot.maxfd) iot.maxfd = fd + 1;
708-
FD_CLR(fd, &iot.err_set);
709-
if ('r' == op)
710-
FD_SET(fd, &iot.read_set);
711-
else
712-
FD_SET(fd, &iot.write_set);
713-
task_wait(t, &iot.tasks);
714-
/* MAY_DBG(FN; poll_debug()); */
715-
}
716-
717-
static void unpoll(int i) {
718-
FD_CLR(i, &iot.read_set);
719-
FD_CLR(i, &iot.write_set);
720-
FD_CLR(i, &iot.err_set);
721-
}
722-
723-
static void wake_all_io() {
724-
FWD_ITER(&iot.tasks, task_env, unpoll(link_iter->waitfd);
725-
activate(link_iter););
726-
}
727-
728-
void remove_and_wakeup(int fd) {
729-
MAY_DBG(FN; NDBG(fd, d));
730-
FWD_ITER(&iot.tasks, task_env, if (fd == link_iter->waitfd) {
731-
unpoll(link_iter->waitfd);
732-
activate(link_iter);
733-
if (iot.maxfd - 1 == link_iter->waitfd)
734-
iot.maxfd = link_iter->waitfd; /* Shrink set of watched files */
735-
});
736-
}
737-
738-
#else
739586
static void iotasks_init(iotasks *iot)
740587
{
741588
DBGOUT(FN);
@@ -864,7 +711,6 @@ void remove_and_wakeup(int fd) {
864711
}
865712
}
866713

867-
#endif
868714
task_env *stack = NULL;
869715

870716
task_env *wait_io(task_env *t, int fd, int op) {
@@ -1131,13 +977,8 @@ void task_loop() {
1131977
Wait until something happens.
1132978
*/
1133979
#ifdef DEBUG_TASKS
1134-
#ifdef USE_SELECT
1135-
MAY_DBG(FN; STRLIT("waiting tasks time "); NDBG(seconds(), f);
1136-
NDBG(cardinal(&iot.tasks), d); NDBG(task_time_q.curn, d));
1137-
#else
1138980
MAY_DBG(FN; STRLIT("waiting tasks time "); NDBG(seconds(), f);
1139981
NDBG(iot.nwait, d); NDBG(task_time_q.curn));
1140-
#endif
1141982
#endif
1142983
{
1143984
double time = seconds();

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ extern "C" {
4040
Nonblocking IO and event handling need to be rewritten for each new OS.
4141
*/
4242

43-
/* #define USE_SELECT */
4443
#ifdef TASK_EVENT_TRACE
4544
void add_base_event(double when, char const *file, int state);
4645
#define ADD_BASE_EVENT \

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task_os.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ extern "C" {
3434
#define SOCK_EAGAIN WSAEINPROGRESS
3535
#define SOCK_EWOULDBLOCK WSAEWOULDBLOCK
3636
#define SOCK_EINPROGRESS WSAEINPROGRESS
37+
#define SOCK_EALREADY WSAEALREADY
38+
#define SOCK_ECONNREFUSED WSAECONNREFUSED
3739
#define SOCK_ERRNO task_errno
3840
#define SOCK_OPT_REUSEADDR SO_EXCLUSIVEADDRUSE
3941
#define GET_OS_ERR WSAGetLastError()
4042
#define SET_OS_ERR(x) WSASetLastError(x)
41-
#define SOCK_ECONNREFUSED WSAECONNREFUSED
4243
#define CLOSESOCKET(x) closesocket(x)
4344
#define SOCK_SHUT_RDWR SD_BOTH
4445

@@ -63,6 +64,11 @@ static inline int poll(pollfd * fds, nfds_t nfds, int timeout) {
6364
return WSAPoll(fds, nfds, timeout);
6465
}
6566

67+
static inline int is_socket_error(int x)
68+
{
69+
return x == SOCKET_ERROR || x < 0;
70+
}
71+
6672
#else
6773
#include <errno.h>
6874
#include <netdb.h>
@@ -82,11 +88,12 @@ static inline int poll(pollfd * fds, nfds_t nfds, int timeout) {
8288
#define SOCK_EAGAIN EAGAIN
8389
#define SOCK_EWOULDBLOCK EWOULDBLOCK
8490
#define SOCK_EINPROGRESS EINPROGRESS
91+
#define SOCK_EALREADY EALREADY
92+
#define SOCK_ECONNREFUSED ECONNREFUSED
8593
#define SOCK_ERRNO task_errno
8694
#define SOCK_OPT_REUSEADDR SO_REUSEADDR
8795
#define GET_OS_ERR errno
8896
#define SET_OS_ERR(x) errno = (x)
89-
#define SOCK_ECONNREFUSED ECONNREFUSED
9097
#define CLOSESOCKET(x) close(x)
9198
#define SOCK_SHUT_RDWR (SHUT_RD | SHUT_WR)
9299

@@ -100,6 +107,11 @@ static inline int hard_select_err(int err) {
100107

101108
typedef struct pollfd pollfd;
102109

110+
static inline int is_socket_error(int x)
111+
{
112+
return x < 0;
113+
}
114+
103115
#endif
104116

105117
extern void remove_and_wakeup(int fd);

0 commit comments

Comments
 (0)