Divide poll.h to core and public headers

Also some cleanup of other headers.
This commit is contained in:
Esa Korhonen 2017-01-20 11:41:34 +02:00
parent 468411250d
commit 8cffa4ad58
12 changed files with 181 additions and 152 deletions

View File

@ -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 <maxscale/cdefs.h>
#include <maxscale/buffer.h>
#include <maxscale/dcb.h>
#include <maxscale/bitmask.h>
#include <maxscale/resultset.h>
#include <sys/epoll.h>
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

View File

@ -36,31 +36,32 @@
*/
#include <maxscale/cdefs.h>
#include <execinfo.h>
#include <ftw.h>
#include <getopt.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include <ini.h>
#include <openssl/opensslconf.h>
#include <pwd.h>
#include <sys/file.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <openssl/opensslconf.h>
#include <ini.h>
#include <maxscale/alloc.h>
#include <maxscale/config.h>
#include <maxscale/dcb.h>
#include <maxscale/paths.h>
#include <maxscale/housekeeper.h>
#include <maxscale/log_manager.h>
#include <maxscale/maxscale.h>
#include <maxscale/memlog.h>
#include <maxscale/poll.h>
#include <maxscale/paths.h>
#include <maxscale/query_classifier.h>
#include <maxscale/server.h>
#include <maxscale/session.h>
@ -69,10 +70,11 @@
#include <maxscale/version.h>
#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

View File

@ -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 <maxscale/poll.h>
#include <maxscale/bitmask.h>
#include <maxscale/resultset.h>
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

View File

@ -11,32 +11,36 @@
* Public License.
*/
#include <maxscale/poll.h>
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <mysql.h>
#include <sys/epoll.h>
#include <errno.h>
#include <maxscale/alloc.h>
#include <maxscale/poll.h>
#include <maxscale/dcb.h>
#include <maxscale/atomic.h>
#include <maxscale/bitmask.h>
#include <maxscale/log_manager.h>
#include <maxscale/housekeeper.h>
#include <maxscale/config.h>
#include <mysql.h>
#include <maxscale/dcb.h>
#include <maxscale/housekeeper.h>
#include <maxscale/log_manager.h>
#include <maxscale/platform.h>
#include <maxscale/query_classifier.h>
#include <maxscale/resultset.h>
#include <maxscale/server.h>
#include <maxscale/session.h>
#include <maxscale/statistics.h>
#include <maxscale/query_classifier.h>
#include <maxscale/utils.h>
#include <maxscale/server.h>
#include <maxscale/statistics.h>
#include <maxscale/thread.h>
#include <maxscale/platform.h>
#include <maxscale/utils.h>
#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;

View File

@ -50,6 +50,7 @@
#include <maxscale/paths.h>
#include "maxscale/monitor.h"
#include "maxscale/poll.h"
/** The latin1 charset */
#define SERVER_DEFAULT_CHARSET 0x08

View File

@ -15,14 +15,16 @@
*/
#include <maxscale/cdefs.h>
#include <maxscale/poll.h>
#include <maxscale/dcb.h>
#include <maxscale/housekeeper.h>
#include <maxscale/maxscale_test.h>
#include <maxscale/log_manager.h>
#include <maxscale/config.h>
#include "../maxscale/poll.h"
#include "../maxscale/statistics.h"
void init_test_env(char *path)
{
int argc = 3;

View File

@ -33,9 +33,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <maxscale/poll.h>
#include <maxscale/dcb.h>
#include <maxscale/listener.h>
#include "test_utils.h"
/**

View File

@ -41,6 +41,7 @@ extern int debug_check_fail;
#include <maxscale/random_jkiss.h>
#include <maxscale/hk_heartbeat.h>
#include <maxscale/alloc.h>
#include "test_utils.h"
/**

View File

@ -33,9 +33,10 @@
#include <stdlib.h>
#include <string.h>
#include <maxscale/maxscale_test.h>
#include "../maxscale/service.h"
#include <maxscale/paths.h>
#include <maxscale/alloc.h>
#include "../maxscale/service.h"
#include "test_utils.h"
/**

View File

@ -64,7 +64,6 @@
#include <maxscale/spinlock.h>
#include <maxscale/buffer.h>
#include <maxscale/dcb.h>
#include <maxscale/poll.h>
#include <maxscale/users.h>
#include <maxscale/config.h>
#include <maxscale/adminusers.h>
@ -76,11 +75,10 @@
#include <maxscale/version.h>
#include <maxscale/log_manager.h>
#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

View File

@ -43,7 +43,6 @@
#include <maxscale/spinlock.h>
#include <maxscale/dcb.h>
#include <maxscale/maxscale.h>
#include <maxscale/poll.h>
#include <maxscale/log_manager.h>
#include <maxscale/resultset.h>
#include <maxscale/version.h>
@ -52,8 +51,9 @@
#include <maxscale/users.h>
#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);

View File

@ -38,16 +38,16 @@
#include <maxscale/maxscale.h>
#include <maxscale/modinfo.h>
#include <maxscale/modutil.h>
#include <maxscale/poll.h>
#include <maxscale/resultset.h>
#include <maxscale/router.h>
#include <maxscale/service.h>
#include <maxscale/spinlock.h>
#include <maxscale/version.h>
#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);