Commit 38a127c3 authored by Witold Krecicki's avatar Witold Krecicki
Browse files

Remove layering from isc_task, isc_app, isc_socket, isc_timer, isc_mem

parent cdbac34c
......@@ -831,7 +831,7 @@ create_managers(void) {
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
isc__socketmgr_maxudp(named_g_socketmgr, maxudp);
isc_socketmgr_maxudp(named_g_socketmgr, maxudp);
result = isc_socketmgr_getmaxsockets(named_g_socketmgr, &socks);
if (result == ISC_R_SUCCESS) {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
......
......@@ -8120,7 +8120,7 @@ load_configuration(const char *filename, named_server_t *server,
"less than 128 UDP sockets available after "
"applying 'reserved-sockets' and 'maxsockets'");
}
isc__socketmgr_setreserved(named_g_socketmgr, reserved);
isc_socketmgr_setreserved(named_g_socketmgr, reserved);
#ifdef HAVE_GEOIP
/*
......
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <config.h>
#include <stdbool.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/magic.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/util.h>
static isc_mutex_t createlock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_appctxcreatefunc_t appctx_createfunc = NULL;
static bool is_running = false;
#define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
static void
initialize(void) {
RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
}
isc_result_t
isc_app_register(isc_appctxcreatefunc_t createfunc) {
isc_result_t result = ISC_R_SUCCESS;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
LOCK(&createlock);
if (appctx_createfunc == NULL)
appctx_createfunc = createfunc;
else
result = ISC_R_EXISTS;
UNLOCK(&createlock);
return (result);
}
isc_result_t
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
return (isc__appctx_create(mctx, ctxp));
}
void
isc_appctx_destroy(isc_appctx_t **ctxp) {
REQUIRE(ctxp != NULL && ISCAPI_APPCTX_VALID(*ctxp));
isc__appctx_destroy(ctxp);
ENSURE(*ctxp == NULL);
}
isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
return (isc__app_ctxstart(ctx));
}
isc_result_t
isc_app_ctxrun(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
return (isc__app_ctxrun(ctx));
}
isc_result_t
isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
isc_task_t *task, isc_taskaction_t action,
void *arg)
{
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
return (isc__app_ctxonrun(ctx, mctx, task, action, arg));
}
isc_result_t
isc_app_ctxsuspend(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
return (isc__app_ctxsuspend(ctx));
}
isc_result_t
isc_app_ctxshutdown(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
return (isc__app_ctxshutdown(ctx));
}
void
isc_app_ctxfinish(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
isc__app_ctxfinish(ctx);
}
void
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(taskmgr != NULL);
isc__appctx_settaskmgr(ctx, taskmgr);
}
void
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(socketmgr != NULL);
isc__appctx_setsocketmgr(ctx, socketmgr);
}
void
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(timermgr != NULL);
isc__appctx_settimermgr(ctx, timermgr);
}
isc_result_t
isc_app_start(void) {
return (isc__app_start());
}
isc_result_t
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task,
isc_taskaction_t action, void *arg)
{
return (isc__app_onrun(mctx, task, action, arg));
}
isc_result_t
isc_app_run() {
isc_result_t result;
is_running = ISC_TRUE;
result = isc__app_run();
is_running = ISC_FALSE;
return (result);
}
bool
isc_app_isrunning() {
return (is_running);
}
isc_result_t
isc_app_shutdown(void) {
return (isc__app_shutdown());
}
isc_result_t
isc_app_reload(void) {
return (isc__app_reload());
}
void
isc_app_finish(void) {
isc__app_finish();
}
void
isc_app_block(void) {
isc__app_block();
}
void
isc_app_unblock(void) {
isc__app_unblock();
}
......@@ -662,30 +662,6 @@ ISCMEMPOOLFUNC(get)(isc_mempool_t * _ISC_MEM_FLARG);
void
ISCMEMPOOLFUNC(put)(isc_mempool_t *, void * _ISC_MEM_FLARG);
/*%<
* See isc_mem_create2() above.
*/
typedef isc_result_t
(*isc_memcreatefunc_t)(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp, unsigned int flags);
isc_result_t
isc_mem_register(isc_memcreatefunc_t createfunc);
/*%<
* Register a new memory management implementation and add it to the list of
* supported implementations. This function must be called when a different
* memory management library is used than the one contained in the ISC library.
*/
isc_result_t
isc__mem_register(void);
/*%<
* A short cut function that specifies the memory management module in the ISC
* library for isc_mem_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
void
isc__mem_printactive(isc_mem_t *mctx, FILE *file);
/*%<
......
......@@ -62,55 +62,6 @@
#include <isc/types.h>
#include <isc/xml.h>
#ifdef WIN32
/* from the old namespace.h */
#define isc_socket_create isc__socket_create
#define isc_socket_dup isc__socket_dup
#define isc_socket_attach isc__socket_attach
#define isc_socket_detach isc__socket_detach
#define isc_socketmgr_create isc__socketmgr_create
#define isc_socketmgr_create2 isc__socketmgr_create2
#define isc_socketmgr_destroy isc__socketmgr_destroy
#define isc_socket_open isc__socket_open
#define isc_socket_close isc__socket_close
#define isc_socket_recvv isc__socket_recvv
#define isc_socket_recv isc__socket_recv
#define isc_socket_recv2 isc__socket_recv2
#define isc_socket_send isc__socket_send
#define isc_socket_sendto isc__socket_sendto
#define isc_socket_sendv isc__socket_sendv
#define isc_socket_sendtov isc__socket_sendtov
#define isc_socket_sendtov2 isc__socket_sendtov2
#define isc_socket_sendto2 isc__socket_sendto2
#define isc_socket_cleanunix isc__socket_cleanunix
#define isc_socket_permunix isc__socket_permunix
#define isc_socket_bind isc__socket_bind
#define isc_socket_filter isc__socket_filter
#define isc_socket_listen isc__socket_listen
#define isc_socket_accept isc__socket_accept
#define isc_socket_connect isc__socket_connect
#define isc_socket_getfd isc__socket_getfd
#define isc_socket_getname isc__socket_getname
#define isc_socket_gettag isc__socket_gettag
#define isc_socket_getpeername isc__socket_getpeername
#define isc_socket_getsockname isc__socket_getsockname
#define isc_socket_cancel isc__socket_cancel
#define isc_socket_gettype isc__socket_gettype
#define isc_socket_isbound isc__socket_isbound
#define isc_socket_ipv6only isc__socket_ipv6only
#define isc_socket_setname isc__socket_setname
#define isc_socketmgr_getmaxsockets isc__socketmgr_getmaxsockets
#define isc_socketmgr_setstats isc__socketmgr_setstats
#define isc_socketmgr_setreserved isc__socketmgr_setreserved
#define isc__socketmgr_maxudp isc___socketmgr_maxudp
#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate
#define isc_socket_fdwatchpoke isc__socket_fdwatchpoke
#define isc_socket_dscp isc__socket_dscp
#endif
ISC_LANG_BEGINDECLS
/***
......@@ -1082,7 +1033,7 @@ isc_socket_gettype(isc_socket_t *sock);
/*@{*/
bool
isc__socket_isbound(isc_socket_t *sock);
isc_socket_isbound(isc_socket_t *sock);
/*%
* Intended for internal use in BIND9 only
*/
......@@ -1175,13 +1126,13 @@ int isc_socket_getfd(isc_socket_t *socket);
*/
void
isc__socketmgr_setreserved(isc_socketmgr_t *mgr, uint32_t);
isc_socketmgr_setreserved(isc_socketmgr_t *mgr, uint32_t);
/*%<
* Temporary. For use by named only.
*/
void
isc__socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
isc_socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
/*%<
* Test interface. Drop UDP packet > 'maxudp'.
*/
......@@ -1208,23 +1159,6 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats);
typedef isc_result_t
(*isc_socketmgrcreatefunc_t)(isc_mem_t *mctx, isc_socketmgr_t **managerp);
isc_result_t
isc_socket_register(isc_socketmgrcreatefunc_t createfunc);
/*%<
* Register a new socket I/O implementation and add it to the list of
* supported implementations. This function must be called when a different
* event library is used than the one contained in the ISC library.
*/
isc_result_t
isc__socket_register(void);
/*%<
* A short cut function that specifies the socket I/O module in the ISC
* library for isc_socket_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_SOCKET_H */
......@@ -102,42 +102,6 @@ typedef enum {
isc_taskmgrmode_privileged
} isc_taskmgrmode_t;
/*% Task and task manager methods */
typedef struct isc_taskmgrmethods {
void (*destroy)(isc_taskmgr_t **managerp);
void (*setmode)(isc_taskmgr_t *manager,
isc_taskmgrmode_t mode);
isc_taskmgrmode_t (*mode)(isc_taskmgr_t *manager);
isc_result_t (*taskcreate)(isc_taskmgr_t *manager,
unsigned int quantum,
isc_task_t **taskp);
void (*setexcltask)(isc_taskmgr_t *mgr, isc_task_t *task);
isc_result_t (*excltask)(isc_taskmgr_t *mgr, isc_task_t **taskp);
} isc_taskmgrmethods_t;
typedef struct isc_taskmethods {
void (*attach)(isc_task_t *source, isc_task_t **targetp);
void (*detach)(isc_task_t **taskp);
void (*destroy)(isc_task_t **taskp);
void (*send)(isc_task_t *task, isc_event_t **eventp);
void (*sendanddetach)(isc_task_t **taskp, isc_event_t **eventp);
unsigned int (*unsend)(isc_task_t *task, void *sender, isc_eventtype_t type,
void *tag, isc_eventlist_t *events);
isc_result_t (*onshutdown)(isc_task_t *task, isc_taskaction_t action,
void *arg);
void (*shutdown)(isc_task_t *task);
void (*setname)(isc_task_t *task, const char *name, void *tag);
unsigned int (*purgeevents)(isc_task_t *task, void *sender,
isc_eventtype_t type, void *tag);
unsigned int (*purgerange)(isc_task_t *task, void *sender,
isc_eventtype_t first, isc_eventtype_t last,
void *tag);
isc_result_t (*beginexclusive)(isc_task_t *task);
void (*endexclusive)(isc_task_t *task);
void (*setprivilege)(isc_task_t *task, bool priv);
bool (*privilege)(isc_task_t *task);
} isc_taskmethods_t;
/*%
* This structure is actually just the common prefix of a task manager
* object implementation's version of an isc_taskmgr_t.
......@@ -150,7 +114,6 @@ typedef struct isc_taskmethods {
struct isc_taskmgr {
unsigned int impmagic;
unsigned int magic;
isc_taskmgrmethods_t *methods;
};
#define ISCAPI_TASKMGR_MAGIC ISC_MAGIC('A','t','m','g')
......@@ -164,7 +127,6 @@ struct isc_taskmgr {
struct isc_task {
unsigned int impmagic;
unsigned int magic;
isc_taskmethods_t *methods;
};
#define ISCAPI_TASK_MAGIC ISC_MAGIC('A','t','s','t')
......
......@@ -99,29 +99,6 @@ typedef struct isc_timerevent {
#define ISC_TIMEREVENT_LIFE (ISC_EVENTCLASS_TIMER + 3)
#define ISC_TIMEREVENT_LASTEVENT (ISC_EVENTCLASS_TIMER + 65535)
/*% Timer and timer manager methods */
typedef struct {
void (*destroy)(isc_timermgr_t **managerp);
isc_result_t (*timercreate)(isc_timermgr_t *manager,
isc_timertype_t type,
const isc_time_t *expires,
const isc_interval_t *interval,
isc_task_t *task,
isc_taskaction_t action,
void *arg,
isc_timer_t **timerp);
} isc_timermgrmethods_t;
typedef struct {
void (*attach)(isc_timer_t *timer, isc_timer_t **timerp);
void (*detach)(isc_timer_t **timerp);
isc_result_t (*reset)(isc_timer_t *timer, isc_timertype_t type,
const isc_time_t *expires,
const isc_interval_t *interval,
bool purge);
isc_result_t (*touch)(isc_timer_t *timer);
} isc_timermethods_t;
/*%
* This structure is actually just the common prefix of a timer manager
* object implementation's version of an isc_timermgr_t.
......@@ -134,7 +111,6 @@ typedef struct {
struct isc_timermgr {
unsigned int impmagic;
unsigned int magic;
isc_timermgrmethods_t *methods;
};
#define ISCAPI_TIMERMGR_MAGIC ISC_MAGIC('A','t','m','g')
......@@ -148,7 +124,6 @@ struct isc_timermgr {
struct isc_timer {
unsigned int impmagic;
unsigned int magic;
isc_timermethods_t *methods;
};
#define ISCAPI_TIMER_MAGIC ISC_MAGIC('A','t','m','r')
......
......@@ -79,5 +79,5 @@ isc_lib_initmsgcat(void) {
void
isc_lib_register(void) {
printf("ISC_LIB_REGISTER\n");
isc_bind9 = false;
}
......@@ -111,7 +111,6 @@ static ISC_LIST(isc__mem_t) contexts;
static isc_once_t once = ISC_ONCE_INIT;
static isc_mutex_t contextslock;
static isc_mutex_t createlock;
/*%
* Total size of lost memory due to a bug of external library.
......@@ -218,98 +217,6 @@ struct isc__mempool {
static void
print_active(isc__mem_t *ctx, FILE *out);
#endif /* ISC_MEM_TRACKLINES */
/*%
* The following are intended for internal use (indicated by "isc__"
* prefix) but are not declared as static, allowing direct access
* from unit tests, etc.
*/
isc_result_t
isc__mem_create2(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp, unsigned int flags);
void
isc__mem_attach(isc_mem_t *source, isc_mem_t **targetp);
void
isc__mem_detach(isc_mem_t **ctxp);
void
isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG);
void
isc__mem_destroy(isc_mem_t **ctxp);
void *
isc___mem_get(isc_mem_t *ctx, size_t size FLARG);
void
isc___mem_put(isc_mem_t *ctx, void *ptr, size_t size FLARG);
void
isc__mem_stats(isc_mem_t *ctx, FILE *out);
void *
isc___mem_allocate(isc_mem_t *ctx, size_t size FLARG);
void *
isc___mem_reallocate(isc_mem_t *ctx, void *ptr, size_t size FLARG);
void
isc___mem_free(isc_mem_t *ctx, void *ptr FLARG);
char *
isc___mem_strdup(isc_mem_t *mctx, const char *s FLARG);
void
isc__mem_setdestroycheck(isc_mem_t *ctx, bool flag);
void
isc__mem_setquota(isc_mem_t *ctx, size_t quota);
size_t
isc__mem_getquota(isc_mem_t *ctx);
size_t
isc__mem_inuse(isc_mem_t *ctx);
size_t
isc__mem_maxinuse(isc_mem_t *ctx);
size_t
isc__mem_total(isc_mem_t *ctx);
bool
isc__mem_isovermem(isc_mem_t *ctx);
void
isc__mem_setwater(isc_mem_t *ctx, isc_mem_water_t water, void *water_arg,
size_t hiwater, size_t lowater);
void
isc__mem_waterack(isc_mem_t *ctx0, int flag);
void
isc__mem_setname(isc_mem_t *ctx, const char *name, void *tag);
const char *
isc__mem_getname(isc_mem_t *ctx);
void *
isc__mem_gettag(isc_mem_t *ctx);
isc_result_t
isc__mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
void
isc__mempool_setname(isc_mempool_t *mpctx, const char *name);
void
isc__mempool_destroy(isc_mempool_t **mpctxp);
void
isc__mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
void *
isc___mempool_get(isc_mempool_t *mpctx FLARG);
void
isc___mempool_put(isc_mempool_t *mpctx, void *mem FLARG);
void
isc__mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);
unsigned int
isc__mempool_getfreemax(isc_mempool_t *mpctx);
unsigned int
isc__mempool_getfreecount(isc_mempool_t *mpctx);
void
isc__mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit);
unsigned int
isc__mempool_getmaxalloc(isc_mempool_t *mpctx);
unsigned int
isc__mempool_getallocated(isc_mempool_t *mpctx);
void
isc__mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
unsigned int
isc__mempool_getfillcount(isc_mempool_t *mpctx);
void
isc__mem_printactive(isc_mem_t *ctx0, FILE *file);
unsigned int
isc__mem_references(isc_mem_t *ctx0);
#if ISC_MEM_TRACKLINES
/*!
* mctx must be locked.
*/
......@@ -788,7 +695,6 @@ default_memfree(void *arg, void *ptr) {
static void
initialize_action(void) {
RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_mutex_init(&contextslock) == ISC_R_SUCCESS);
ISC_LIST_INIT(contexts);
totallost = 0;
......@@ -1026,7 +932,7 @@ destroy(isc__mem_t *ctx) {
}
void
isc__mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
isc__mem_t *source = (isc__mem_t *)source0;
REQUIRE(VALID_CONTEXT(source));
......@@ -1038,7 +944,7 @@ isc__mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
}
void
isc__mem_detach(isc_mem_t **ctxp) {
isc_mem_detach(isc_mem_t **ctxp) {
REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
isc__mem_t *ctx = (isc__mem_t *)*ctxp;
*ctxp = NULL;
......@@ -1060,7 +966,7 @@ isc__mem_detach(isc_mem_t **ctxp) {
*/
void
isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
REQUIRE(ptr != NULL);
isc__mem_t *ctx = (isc__mem_t *)*ctxp;
......@@ -1101,7 +1007,7 @@ destroy:
}
void
isc__mem_destroy(isc_mem_t **ctxp) {
isc_mem_destroy(isc_mem_t **ctxp) {
isc__mem_t *ctx;
/*
......@@ -1127,7 +1033,7 @@ isc__mem_destroy(isc_mem_t **ctxp) {
}
void *
isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
isc__mem_get(isc_mem_t *ctx0, size_t size FLARG) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
void *ptr;
bool call_water = false;
......@@ -1171,7 +1077,7 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
}
void
isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
bool call_water = false;
size_info *si;
......@@ -1223,7 +1129,7 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
}
void
isc__mem_waterack(isc_mem_t *ctx0, int flag) {
isc_mem_waterack(isc_mem_t *ctx0, int flag) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
REQUIRE(VALID_CONTEXT(ctx));
......@@ -1385,7 +1291,7 @@ mem_allocateunlocked(isc_mem_t *ctx0, size_t size) {
}