From 8cffa4ad58b41f4c3d02046776bd5bdce2a99387 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 20 Jan 2017 11:41:34 +0200 Subject: [PATCH] Divide poll.h to core and public headers Also some cleanup of other headers. --- include/maxscale/poll.h | 116 ++++++++++-------- server/core/gateway.cc | 22 ++-- server/core/maxscale/poll.h | 67 ++++++++++ server/core/poll.c | 101 ++++----------- server/core/server.c | 1 + server/core/test/test_utils.h | 4 +- server/core/test/testpoll.c | 2 +- server/core/test/testqueuemanager.c | 1 + server/core/test/testservice.c | 3 +- server/modules/routing/debugcli/debugcmd.c | 8 +- server/modules/routing/maxinfo/maxinfo.c | 4 +- server/modules/routing/maxinfo/maxinfo_exec.c | 4 +- 12 files changed, 181 insertions(+), 152 deletions(-) create mode 100644 server/core/maxscale/poll.h diff --git a/include/maxscale/poll.h b/include/maxscale/poll.h index 791472f97..d0ab34c0a 100644 --- a/include/maxscale/poll.h +++ b/include/maxscale/poll.h @@ -13,68 +13,82 @@ */ /** - * @file poll.h The poll related functionality - * - * @verbatim - * Revision History - * - * Date Who Description - * 19/06/13 Mark Riddoch Initial implementation - * 17/10/15 Martin Brampton Declare fake event functions - * - * @endverbatim + * @file include/maxscale/poll.h - The public poll interface */ #include + +#include #include -#include -#include -#include MXS_BEGIN_DECLS -#define MAX_EVENTS 1000 +/* + * Insert a fake hangup event for a DCB into the polling queue. + * + * This is used when a monitor detects that a server is not responding. + * + * @param dcb DCB to emulate an EPOLLOUT event for + */ +void poll_fake_hangup_event(DCB *dcb); + +/* + * Insert a fake write completion event for a DCB into the polling + * queue. + * + * This is used to trigger transmission activity on another DCB from + * within the event processing routine of a DCB. or to allow a DCB + * to defer some further output processing, to allow for other DCBs + * to receive a slice of the processing time. Fake events are added + * to the tail of the event queue, in the same way that real events + * are, so maintain the "fairness" of processing. + * + * @param dcb DCB to emulate an EPOLLOUT event for + */ +void poll_fake_write_event(DCB *dcb); + +/* + * Insert a fake read completion event for a DCB into the polling + * queue. + * + * This is used to trigger transmission activity on another DCB from + * within the event processing routine of a DCB. or to allow a DCB + * to defer some further input processing, to allow for other DCBs + * to receive a slice of the processing time. Fake events are added + * to the tail of the event queue, in the same way that real events + * are, so maintain the "fairness" of processing. + * + * @param dcb DCB to emulate an EPOLLIN event for + */ +void poll_fake_read_event(DCB *dcb); /** - * A statistic identifier that can be returned by poll_get_stat + * Add a DCB to the set of descriptors within the polling + * environment. + * + * @param dcb The descriptor to add to the poll + * @return -1 on error or 0 on success */ -typedef enum -{ - POLL_STAT_READ, - POLL_STAT_WRITE, - POLL_STAT_ERROR, - POLL_STAT_HANGUP, - POLL_STAT_ACCEPT, - POLL_STAT_EVQ_LEN, - POLL_STAT_EVQ_MAX, - POLL_STAT_MAX_QTIME, - POLL_STAT_MAX_EXECTIME -} POLL_STAT; +int poll_add_dcb(DCB *); -enum poll_message -{ - POLL_MSG_CLEAN_PERSISTENT = 0x01 -}; +/** + * Remove a descriptor from the set of descriptors within the + * polling environment. + * + * @param dcb The descriptor to remove + * @return -1 on error or 0 on success; actually always 0 + */ +int poll_remove_dcb(DCB *); -extern void poll_init(); -extern int poll_add_dcb(DCB *); -extern int poll_remove_dcb(DCB *); -extern void poll_waitevents(void *); -extern void poll_shutdown(); -extern GWBITMASK *poll_bitmask(); -extern void poll_set_maxwait(unsigned int); -extern void poll_set_nonblocking_polls(unsigned int); -extern void dprintPollStats(DCB *); -extern void dShowThreads(DCB *dcb); -extern void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); -extern void dShowEventQ(DCB *dcb); -extern void dShowEventStats(DCB *dcb); -extern int poll_get_stat(POLL_STAT stat); -extern RESULTSET *eventTimesGetList(); -extern void poll_fake_event(DCB *dcb, enum EPOLL_EVENTS ev); -extern void poll_fake_hangup_event(DCB *dcb); -extern void poll_fake_write_event(DCB *dcb); -extern void poll_fake_read_event(DCB *dcb); -extern void poll_send_message(enum poll_message msg, void *data); +/** + * Add given GWBUF to DCB's readqueue and add a pending EPOLLIN event for DCB. + * The event pretends that there is something to read for the DCB. Actually + * the incoming data is stored in the DCB's readqueue where it is read. + * + * @param dcb DCB where the event and data are added + * @param buf GWBUF including the data + * + */ +void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); MXS_END_DECLS diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 5f937d3f0..b2609f542 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -36,31 +36,32 @@ */ #include + #include #include #include -#include #include #include #include +#include +#include + +#include +#include +#include #include #include #include #include #include -#include -#include -#include -#include + #include -#include #include -#include #include #include #include #include -#include +#include #include #include #include @@ -69,10 +70,11 @@ #include #include "maxscale/config.h" +#include "maxscale/modules.h" +#include "maxscale/monitor.h" #include "maxscale/service.h" #include "maxscale/statistics.h" -#include "maxscale/monitor.h" -#include "maxscale/modules.h" +#include "maxscale/poll.h" #define STRING_BUFFER_SIZE 1024 #define PIDFD_CLOSED -1 diff --git a/server/core/maxscale/poll.h b/server/core/maxscale/poll.h new file mode 100644 index 000000000..ac22ef59c --- /dev/null +++ b/server/core/maxscale/poll.h @@ -0,0 +1,67 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +/** + * @file core/maxscale/poll.h - The private poll interface + */ + +#include + +#include +#include + +MXS_BEGIN_DECLS + +#define MAX_EVENTS 1000 + +/** + * A statistic identifier that can be returned by poll_get_stat + */ +typedef enum +{ + POLL_STAT_READ, + POLL_STAT_WRITE, + POLL_STAT_ERROR, + POLL_STAT_HANGUP, + POLL_STAT_ACCEPT, + POLL_STAT_EVQ_LEN, + POLL_STAT_EVQ_MAX, + POLL_STAT_MAX_QTIME, + POLL_STAT_MAX_EXECTIME +} POLL_STAT; + +enum poll_message +{ + POLL_MSG_CLEAN_PERSISTENT = 0x01 +}; + +void poll_init(); +void poll_shutdown(); + +void poll_waitevents(void *); +void poll_set_maxwait(unsigned int); +void poll_set_nonblocking_polls(unsigned int); + +void dprintPollStats(DCB *); +void dShowThreads(DCB *dcb); +void dShowEventQ(DCB *dcb); +void dShowEventStats(DCB *dcb); + +GWBITMASK *poll_bitmask(); +int poll_get_stat(POLL_STAT stat); +RESULTSET *eventTimesGetList(); + +void poll_send_message(enum poll_message msg, void *data); + +MXS_END_DECLS diff --git a/server/core/poll.c b/server/core/poll.c index 2fc4e8e67..b4ffe22f0 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -11,32 +11,36 @@ * Public License. */ +#include + +#include #include +#include #include #include -#include #include -#include +#include + +#include #include -#include + #include -#include -#include #include #include -#include -#include #include -#include +#include +#include +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include #include -#include +#include + +#include "maxscale/poll.h" #define PROFILE_POLL 0 @@ -325,15 +329,7 @@ poll_init() #endif } -/** - * Add a DCB to the set of descriptors within the polling - * environment. - * - * @param dcb The descriptor to add to the poll - * @return -1 on error or 0 on success - */ -int -poll_add_dcb(DCB *dcb) +int poll_add_dcb(DCB *dcb) { int rc = -1; dcb_state_t old_state = dcb->state; @@ -457,15 +453,7 @@ poll_add_dcb(DCB *dcb) return rc; } -/** - * Remove a descriptor from the set of descriptors within the - * polling environment. - * - * @param dcb The descriptor to remove - * @return -1 on error or 0 on success; actually always 0 - */ -int -poll_remove_dcb(DCB *dcb) +int poll_remove_dcb(DCB *dcb) { int dcbfd, rc = 0; struct epoll_event ev; @@ -1496,15 +1484,6 @@ poll_loadav(void *data) } } -/** - * Add given GWBUF to DCB's readqueue and add a pending EPOLLIN event for DCB. - * The event pretends that there is something to read for the DCB. Actually - * the incoming data is stored in the DCB's readqueue where it is read. - * - * @param dcb DCB where the event and data are added - * @param buf GWBUF including the data - * - */ void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf) { @@ -1551,53 +1530,17 @@ static void poll_add_event_to_dcb(DCB* dcb, } } -/* - * Insert a fake write completion event for a DCB into the polling - * queue. - * - * This is used to trigger transmission activity on another DCB from - * within the event processing routine of a DCB. or to allow a DCB - * to defer some further output processing, to allow for other DCBs - * to receive a slice of the processing time. Fake events are added - * to the tail of the event queue, in the same way that real events - * are, so maintain the "fairness" of processing. - * - * @param dcb DCB to emulate an EPOLLOUT event for - */ -void -poll_fake_write_event(DCB *dcb) +void poll_fake_write_event(DCB *dcb) { poll_add_event_to_dcb(dcb, NULL, EPOLLOUT); } -/* - * Insert a fake read completion event for a DCB into the polling - * queue. - * - * This is used to trigger transmission activity on another DCB from - * within the event processing routine of a DCB. or to allow a DCB - * to defer some further input processing, to allow for other DCBs - * to receive a slice of the processing time. Fake events are added - * to the tail of the event queue, in the same way that real events - * are, so maintain the "fairness" of processing. - * - * @param dcb DCB to emulate an EPOLLIN event for - */ -void -poll_fake_read_event(DCB *dcb) +void poll_fake_read_event(DCB *dcb) { poll_add_event_to_dcb(dcb, NULL, EPOLLIN); } -/* - * Insert a fake hangup event for a DCB into the polling queue. - * - * This is used when a monitor detects that a server is not responding. - * - * @param dcb DCB to emulate an EPOLLOUT event for - */ -void -poll_fake_hangup_event(DCB *dcb) +void poll_fake_hangup_event(DCB *dcb) { #ifdef EPOLLRDHUP uint32_t ev = EPOLLRDHUP; diff --git a/server/core/server.c b/server/core/server.c index 33d35fb18..85fe29563 100644 --- a/server/core/server.c +++ b/server/core/server.c @@ -50,6 +50,7 @@ #include #include "maxscale/monitor.h" +#include "maxscale/poll.h" /** The latin1 charset */ #define SERVER_DEFAULT_CHARSET 0x08 diff --git a/server/core/test/test_utils.h b/server/core/test/test_utils.h index bf36865f0..99bd44b1a 100644 --- a/server/core/test/test_utils.h +++ b/server/core/test/test_utils.h @@ -15,14 +15,16 @@ */ #include -#include #include #include #include #include #include + +#include "../maxscale/poll.h" #include "../maxscale/statistics.h" + void init_test_env(char *path) { int argc = 3; diff --git a/server/core/test/testpoll.c b/server/core/test/testpoll.c index ecd5892a9..4043ad8d3 100644 --- a/server/core/test/testpoll.c +++ b/server/core/test/testpoll.c @@ -33,9 +33,9 @@ #include #include #include -#include #include #include + #include "test_utils.h" /** diff --git a/server/core/test/testqueuemanager.c b/server/core/test/testqueuemanager.c index 4ba0840c2..4ee10339d 100644 --- a/server/core/test/testqueuemanager.c +++ b/server/core/test/testqueuemanager.c @@ -41,6 +41,7 @@ extern int debug_check_fail; #include #include #include + #include "test_utils.h" /** diff --git a/server/core/test/testservice.c b/server/core/test/testservice.c index 063295156..8853ae161 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -33,9 +33,10 @@ #include #include #include -#include "../maxscale/service.h" #include #include + +#include "../maxscale/service.h" #include "test_utils.h" /** diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 2775288fa..d3ff85e2c 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include #include @@ -76,11 +75,10 @@ #include #include -#include "../../../core/maxscale/monitor.h" - -#include "../../../core/maxscale/session.h" - #include "../../../core/maxscale/modules.h" +#include "../../../core/maxscale/monitor.h" +#include "../../../core/maxscale/session.h" +#include "../../../core/maxscale/poll.h" #define MAXARGS 12 diff --git a/server/modules/routing/maxinfo/maxinfo.c b/server/modules/routing/maxinfo/maxinfo.c index ffd2dd661..97059b047 100644 --- a/server/modules/routing/maxinfo/maxinfo.c +++ b/server/modules/routing/maxinfo/maxinfo.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -52,8 +51,9 @@ #include #include "../../../core/maxscale/modules.h" -#include "../../../core/maxscale/session.h" #include "../../../core/maxscale/monitor.h" +#include "../../../core/maxscale/session.h" +#include "../../../core/maxscale/poll.h" extern char *create_hex_sha1_sha1_passwd(char *passwd); diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index 6d261c208..c284b963d 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -38,16 +38,16 @@ #include #include #include -#include #include #include #include #include #include -#include "../../../core/maxscale/session.h" #include "../../../core/maxscale/modules.h" #include "../../../core/maxscale/monitor.h" +#include "../../../core/maxscale/poll.h" +#include "../../../core/maxscale/session.h" static void exec_show(DCB *dcb, MAXINFO_TREE *tree); static void exec_select(DCB *dcb, MAXINFO_TREE *tree);