2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Cleanup the public vs private ISCAPI remnants

Since all the libraries are internal now, just cleanup the ISCAPI remnants
in isc_socket, isc_task and isc_timer APIs.  This means, there's one less
layer as following changes have been done:

 * struct isc_socket and struct isc_socketmgr have been removed
 * struct isc__socket and struct isc__socketmgr have been renamed
   to struct isc_socket and struct isc_socketmgr
 * struct isc_task and struct isc_taskmgr have been removed
 * struct isc__task and struct isc__taskmgr have been renamed
   to struct isc_task and struct isc_taskmgr
 * struct isc_timer and struct isc_timermgr have been removed
 * struct isc__timer and struct isc__timermgr have been renamed
   to struct isc_timer and struct isc_timermgr
 * All the associated code that dealt with typing isc_<foo>
   to isc__<foo> and back has been removed.
This commit is contained in:
Ondřej Surý
2021-04-19 11:12:58 +02:00
committed by Ondřej Surý
parent 5937c1f787
commit 16fe0d1f41
8 changed files with 276 additions and 494 deletions

View File

@@ -93,17 +93,6 @@ typedef isc_event_t isc_appevent_t;
#define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1) #define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1)
#define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535) #define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535)
/*%
* This structure is actually just the common prefix of an application context
* implementation's version of an isc_appctx_t.
* \brief
* Direct use of this structure by clients is forbidden. app implementations
* may change the structure. 'magic' must be ISCAPI_APPCTX_MAGIC for any
* of the isc_app_ routines to work. app implementations must maintain
* all app context invariants.
*/
struct isc_appctx;
ISC_LANG_BEGINDECLS ISC_LANG_BEGINDECLS
isc_result_t isc_result_t

View File

@@ -191,45 +191,6 @@ typedef enum {
#define ISC_SOCKFLAG_NORETRY 0x00000002 /*%< drop failed UDP sends */ #define ISC_SOCKFLAG_NORETRY 0x00000002 /*%< drop failed UDP sends */
/*@}*/ /*@}*/
/*%
* This structure is actually just the common prefix of a socket manager
* object implementation's version of an isc_socketmgr_t.
* \brief
* Direct use of this structure by clients is forbidden. socket implementations
* may change the structure. 'magic' must be ISCAPI_SOCKETMGR_MAGIC for any
* of the isc_socket_ routines to work. socket implementations must maintain
* all socket invariants.
* In effect, this definition is used only for non-BIND9 version ("export")
* of the library, and the export version does not work for win32. So, to avoid
* the definition conflict with win32/socket.c, we enable this definition only
* for non-Win32 (i.e. Unix) platforms.
*/
#ifndef WIN32
struct isc_socketmgr {
unsigned int impmagic;
unsigned int magic;
};
#endif /* ifndef WIN32 */
#define ISCAPI_SOCKETMGR_MAGIC ISC_MAGIC('A', 's', 'm', 'g')
#define ISCAPI_SOCKETMGR_VALID(m) \
((m) != NULL && (m)->magic == ISCAPI_SOCKETMGR_MAGIC)
/*%
* This is the common prefix of a socket object. The same note as
* that for the socketmgr structure applies.
*/
#ifndef WIN32
struct isc_socket {
unsigned int impmagic;
unsigned int magic;
};
#endif /* ifndef WIN32 */
#define ISCAPI_SOCKET_MAGIC ISC_MAGIC('A', 's', 'c', 't')
#define ISCAPI_SOCKET_VALID(s) \
((s) != NULL && (s)->magic == ISCAPI_SOCKET_MAGIC)
/*** /***
*** Socket and Socket Manager Functions *** Socket and Socket Manager Functions
*** ***

View File

@@ -99,36 +99,6 @@ typedef enum {
isc_taskmgrmode_privileged isc_taskmgrmode_privileged
} isc_taskmgrmode_t; } isc_taskmgrmode_t;
/*%
* This structure is actually just the common prefix of a task manager
* object implementation's version of an isc_taskmgr_t.
* \brief
* Direct use of this structure by clients is forbidden. task implementations
* may change the structure. 'magic' must be ISCAPI_TASKMGR_MAGIC for any
* of the isc_task_ routines to work. task implementations must maintain
* all task invariants.
*/
struct isc_taskmgr {
unsigned int impmagic;
unsigned int magic;
};
#define ISCAPI_TASKMGR_MAGIC ISC_MAGIC('A', 't', 'm', 'g')
#define ISCAPI_TASKMGR_VALID(m) \
((m) != NULL && (m)->magic == ISCAPI_TASKMGR_MAGIC)
/*%
* This is the common prefix of a task object. The same note as
* that for the taskmgr structure applies.
*/
struct isc_task {
unsigned int impmagic;
unsigned int magic;
};
#define ISCAPI_TASK_MAGIC ISC_MAGIC('A', 't', 's', 't')
#define ISCAPI_TASK_VALID(s) ((s) != NULL && (s)->magic == ISCAPI_TASK_MAGIC)
isc_result_t isc_result_t
isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
isc_task_t **taskp); isc_task_t **taskp);

View File

@@ -97,36 +97,6 @@ typedef struct isc_timerevent {
#define ISC_TIMEREVENT_LIFE (ISC_EVENTCLASS_TIMER + 3) #define ISC_TIMEREVENT_LIFE (ISC_EVENTCLASS_TIMER + 3)
#define ISC_TIMEREVENT_LASTEVENT (ISC_EVENTCLASS_TIMER + 65535) #define ISC_TIMEREVENT_LASTEVENT (ISC_EVENTCLASS_TIMER + 65535)
/*%
* This structure is actually just the common prefix of a timer manager
* object implementation's version of an isc_timermgr_t.
* \brief
* Direct use of this structure by clients is forbidden. timer implementations
* may change the structure. 'magic' must be ISCAPI_TIMERMGR_MAGIC for any
* of the isc_timer_ routines to work. timer implementations must maintain
* all timer invariants.
*/
struct isc_timermgr {
unsigned int impmagic;
unsigned int magic;
};
#define ISCAPI_TIMERMGR_MAGIC ISC_MAGIC('A', 't', 'm', 'g')
#define ISCAPI_TIMERMGR_VALID(m) \
((m) != NULL && (m)->magic == ISCAPI_TIMERMGR_MAGIC)
/*%
* This is the common prefix of a timer object. The same note as
* that for the timermgr structure applies.
*/
struct isc_timer {
unsigned int impmagic;
unsigned int magic;
};
#define ISCAPI_TIMER_MAGIC ISC_MAGIC('A', 't', 'm', 'r')
#define ISCAPI_TIMER_VALID(s) ((s) != NULL && (s)->magic == ISCAPI_TIMER_MAGIC)
/*** /***
*** Timer and Timer Manager Functions *** Timer and Timer Manager Functions
*** ***

View File

@@ -97,14 +97,12 @@ static const char *statenames[] = {
#define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K') #define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K')
#define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC) #define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC)
typedef struct isc__task isc__task_t;
typedef struct isc__taskmgr isc__taskmgr_t;
typedef struct isc__taskqueue isc__taskqueue_t; typedef struct isc__taskqueue isc__taskqueue_t;
struct isc__task { struct isc_task {
/* Not locked. */ /* Not locked. */
isc_task_t common; unsigned int magic;
isc__taskmgr_t *manager; isc_taskmgr_t *manager;
isc_mutex_t lock; isc_mutex_t lock;
/* Locked by task lock. */ /* Locked by task lock. */
task_state_t state; task_state_t state;
@@ -123,9 +121,9 @@ struct isc__task {
/* Protected by atomics */ /* Protected by atomics */
atomic_uint_fast32_t flags; atomic_uint_fast32_t flags;
/* Locked by task manager lock. */ /* Locked by task manager lock. */
LINK(isc__task_t) link; LINK(isc_task_t) link;
LINK(isc__task_t) ready_link; LINK(isc_task_t) ready_link;
LINK(isc__task_t) ready_priority_link; LINK(isc_task_t) ready_priority_link;
}; };
#define TASK_F_SHUTTINGDOWN 0x01 #define TASK_F_SHUTTINGDOWN 0x01
@@ -142,7 +140,7 @@ struct isc__task {
#define TASK_MANAGER_MAGIC ISC_MAGIC('T', 'S', 'K', 'M') #define TASK_MANAGER_MAGIC ISC_MAGIC('T', 'S', 'K', 'M')
#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TASK_MANAGER_MAGIC) #define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TASK_MANAGER_MAGIC)
typedef ISC_LIST(isc__task_t) isc__tasklist_t; typedef ISC_LIST(isc_task_t) isc__tasklist_t;
struct isc__taskqueue { struct isc__taskqueue {
/* Everything locked by lock */ /* Everything locked by lock */
@@ -152,12 +150,12 @@ struct isc__taskqueue {
isc_condition_t work_available; isc_condition_t work_available;
isc_thread_t thread; isc_thread_t thread;
unsigned int threadid; unsigned int threadid;
isc__taskmgr_t *manager; isc_taskmgr_t *manager;
}; };
struct isc__taskmgr { struct isc_taskmgr {
/* Not locked. */ /* Not locked. */
isc_taskmgr_t common; unsigned int magic;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t lock; isc_mutex_t lock;
isc_mutex_t halt_lock; isc_mutex_t halt_lock;
@@ -172,7 +170,7 @@ struct isc__taskmgr {
/* Locked by task manager lock. */ /* Locked by task manager lock. */
unsigned int default_quantum; unsigned int default_quantum;
LIST(isc__task_t) tasks; LIST(isc_task_t) tasks;
atomic_uint_fast32_t mode; atomic_uint_fast32_t mode;
atomic_bool pause_req; atomic_bool pause_req;
atomic_bool exclusive_req; atomic_bool exclusive_req;
@@ -187,7 +185,7 @@ struct isc__taskmgr {
* will try to acquire it. * will try to acquire it.
*/ */
isc_mutex_t excl_lock; isc_mutex_t excl_lock;
isc__task_t *excl; isc_task_t *excl;
}; };
void void
@@ -207,29 +205,29 @@ isc__taskmgr_resume(isc_taskmgr_t *manager0);
*/ */
bool bool
isc_task_purgeevent(isc_task_t *task0, isc_event_t *event); isc_task_purgeevent(isc_task_t *task, isc_event_t *event);
void void
isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0); isc_taskmgr_setexcltask(isc_taskmgr_t *mgr, isc_task_t *task);
isc_result_t isc_result_t
isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp); isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp);
static inline bool static inline bool
empty_readyq(isc__taskmgr_t *manager, int c); empty_readyq(isc_taskmgr_t *manager, int c);
static inline isc__task_t * static inline isc_task_t *
pop_readyq(isc__taskmgr_t *manager, int c); pop_readyq(isc_taskmgr_t *manager, int c);
static inline void static inline void
push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c); push_readyq(isc_taskmgr_t *manager, isc_task_t *task, int c);
static inline void static inline void
wake_all_queues(isc__taskmgr_t *manager); wake_all_queues(isc_taskmgr_t *manager);
/*** /***
*** Tasks. *** Tasks.
***/ ***/
static inline void static inline void
wake_all_queues(isc__taskmgr_t *manager) { wake_all_queues(isc_taskmgr_t *manager) {
for (unsigned int i = 0; i < manager->workers; i++) { for (unsigned int i = 0; i < manager->workers; i++) {
LOCK(&manager->queues[i].lock); LOCK(&manager->queues[i].lock);
BROADCAST(&manager->queues[i].work_available); BROADCAST(&manager->queues[i].work_available);
@@ -238,8 +236,8 @@ wake_all_queues(isc__taskmgr_t *manager) {
} }
static void static void
task_finished(isc__task_t *task) { task_finished(isc_task_t *task) {
isc__taskmgr_t *manager = task->manager; isc_taskmgr_t *manager = task->manager;
REQUIRE(EMPTY(task->events)); REQUIRE(EMPTY(task->events));
REQUIRE(task->nevents == 0); REQUIRE(task->nevents == 0);
REQUIRE(EMPTY(task->on_shutdown)); REQUIRE(EMPTY(task->on_shutdown));
@@ -263,8 +261,7 @@ task_finished(isc__task_t *task) {
wake_all_queues(manager); wake_all_queues(manager);
} }
isc_mutex_destroy(&task->lock); isc_mutex_destroy(&task->lock);
task->common.impmagic = 0; task->magic = 0;
task->common.magic = 0;
isc_mem_put(manager->mctx, task, sizeof(*task)); isc_mem_put(manager->mctx, task, sizeof(*task));
} }
@@ -277,8 +274,8 @@ isc_task_create(isc_taskmgr_t *manager0, unsigned int quantum,
isc_result_t isc_result_t
isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum, isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
isc_task_t **taskp, int threadid) { isc_task_t **taskp, int threadid) {
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; isc_taskmgr_t *manager = (isc_taskmgr_t *)manager0;
isc__task_t *task; isc_task_t *task;
bool exiting; bool exiting;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@@ -339,17 +336,14 @@ isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
return (ISC_R_SHUTTINGDOWN); return (ISC_R_SHUTTINGDOWN);
} }
task->common.magic = ISCAPI_TASK_MAGIC; task->magic = TASK_MAGIC;
task->common.impmagic = TASK_MAGIC; *taskp = task;
*taskp = (isc_task_t *)task;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void void
isc_task_attach(isc_task_t *source0, isc_task_t **targetp) { isc_task_attach(isc_task_t *source, isc_task_t **targetp) {
isc__task_t *source = (isc__task_t *)source0;
/* /*
* Attach *targetp to source. * Attach *targetp to source.
*/ */
@@ -361,11 +355,11 @@ isc_task_attach(isc_task_t *source0, isc_task_t **targetp) {
isc_refcount_increment(&source->references); isc_refcount_increment(&source->references);
*targetp = (isc_task_t *)source; *targetp = source;
} }
static inline bool static inline bool
task_shutdown(isc__task_t *task) { task_shutdown(isc_task_t *task) {
bool was_idle = false; bool was_idle = false;
isc_event_t *event, *prev; isc_event_t *event, *prev;
@@ -409,9 +403,9 @@ task_shutdown(isc__task_t *task) {
* Caller must NOT hold queue lock. * Caller must NOT hold queue lock.
*/ */
static inline void static inline void
task_ready(isc__task_t *task) { task_ready(isc_task_t *task) {
isc__taskmgr_t *manager = task->manager; isc_taskmgr_t *manager = task->manager;
bool has_privilege = isc_task_privilege((isc_task_t *)task); bool has_privilege = isc_task_privilege(task);
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@@ -426,7 +420,7 @@ task_ready(isc__task_t *task) {
} }
static inline bool static inline bool
task_detach(isc__task_t *task) { task_detach(isc_task_t *task) {
/* /*
* Caller must be holding the task lock. * Caller must be holding the task lock.
*/ */
@@ -454,7 +448,7 @@ task_detach(isc__task_t *task) {
void void
isc_task_detach(isc_task_t **taskp) { isc_task_detach(isc_task_t **taskp) {
isc__task_t *task; isc_task_t *task;
bool was_idle; bool was_idle;
/* /*
@@ -462,7 +456,7 @@ isc_task_detach(isc_task_t **taskp) {
*/ */
REQUIRE(taskp != NULL); REQUIRE(taskp != NULL);
task = (isc__task_t *)*taskp; task = *taskp;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
XTRACE("isc_task_detach"); XTRACE("isc_task_detach");
@@ -479,7 +473,7 @@ isc_task_detach(isc_task_t **taskp) {
} }
static inline bool static inline bool
task_send(isc__task_t *task, isc_event_t **eventp, int c) { task_send(isc_task_t *task, isc_event_t **eventp, int c) {
bool was_idle = false; bool was_idle = false;
isc_event_t *event; isc_event_t *event;
@@ -514,8 +508,8 @@ task_send(isc__task_t *task, isc_event_t **eventp, int c) {
} }
void void
isc_task_send(isc_task_t *task0, isc_event_t **eventp) { isc_task_send(isc_task_t *task, isc_event_t **eventp) {
isc_task_sendto(task0, eventp, -1); isc_task_sendto(task, eventp, -1);
} }
void void
@@ -524,8 +518,7 @@ isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) {
} }
void void
isc_task_sendto(isc_task_t *task0, isc_event_t **eventp, int c) { isc_task_sendto(isc_task_t *task, isc_event_t **eventp, int c) {
isc__task_t *task = (isc__task_t *)task0;
bool was_idle; bool was_idle;
/* /*
@@ -575,7 +568,7 @@ isc_task_sendto(isc_task_t *task0, isc_event_t **eventp, int c) {
void void
isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) { isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) {
bool idle1, idle2; bool idle1, idle2;
isc__task_t *task; isc_task_t *task;
/* /*
* Send '*event' to '*taskp' and then detach '*taskp' from its * Send '*event' to '*taskp' and then detach '*taskp' from its
@@ -583,7 +576,7 @@ isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) {
*/ */
REQUIRE(taskp != NULL); REQUIRE(taskp != NULL);
task = (isc__task_t *)*taskp; task = *taskp;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
XTRACE("isc_task_sendanddetach"); XTRACE("isc_task_sendanddetach");
@@ -616,7 +609,7 @@ isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) {
#define PURGE_OK(event) (((event)->ev_attributes & ISC_EVENTATTR_NOPURGE) == 0) #define PURGE_OK(event) (((event)->ev_attributes & ISC_EVENTATTR_NOPURGE) == 0)
static unsigned int static unsigned int
dequeue_events(isc__task_t *task, void *sender, isc_eventtype_t first, dequeue_events(isc_task_t *task, void *sender, isc_eventtype_t first,
isc_eventtype_t last, void *tag, isc_eventlist_t *events, isc_eventtype_t last, void *tag, isc_eventlist_t *events,
bool purging) { bool purging) {
isc_event_t *event, *next_event; isc_event_t *event, *next_event;
@@ -657,9 +650,8 @@ dequeue_events(isc__task_t *task, void *sender, isc_eventtype_t first,
} }
unsigned int unsigned int
isc_task_purgerange(isc_task_t *task0, void *sender, isc_eventtype_t first, isc_task_purgerange(isc_task_t *task, void *sender, isc_eventtype_t first,
isc_eventtype_t last, void *tag) { isc_eventtype_t last, void *tag) {
isc__task_t *task = (isc__task_t *)task0;
unsigned int count; unsigned int count;
isc_eventlist_t events; isc_eventlist_t events;
isc_event_t *event, *next_event; isc_event_t *event, *next_event;
@@ -702,8 +694,7 @@ isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type,
} }
bool bool
isc_task_purgeevent(isc_task_t *task0, isc_event_t *event) { isc_task_purgeevent(isc_task_t *task, isc_event_t *event) {
isc__task_t *task = (isc__task_t *)task0;
isc_event_t *curr_event, *next_event; isc_event_t *curr_event, *next_event;
/* /*
@@ -756,7 +747,7 @@ isc_task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first,
XTRACE("isc_task_unsendrange"); XTRACE("isc_task_unsendrange");
return (dequeue_events((isc__task_t *)task, sender, first, last, tag, return (dequeue_events((isc_task_t *)task, sender, first, last, tag,
events, false)); events, false));
} }
@@ -769,13 +760,12 @@ isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, void *tag,
XTRACE("isc_task_unsend"); XTRACE("isc_task_unsend");
return (dequeue_events((isc__task_t *)task, sender, type, type, tag, return (dequeue_events((isc_task_t *)task, sender, type, type, tag,
events, false)); events, false));
} }
isc_result_t isc_result_t
isc_task_onshutdown(isc_task_t *task0, isc_taskaction_t action, void *arg) { isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg) {
isc__task_t *task = (isc__task_t *)task0;
bool disallowed = false; bool disallowed = false;
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
isc_event_t *event; isc_event_t *event;
@@ -809,8 +799,7 @@ isc_task_onshutdown(isc_task_t *task0, isc_taskaction_t action, void *arg) {
} }
void void
isc_task_shutdown(isc_task_t *task0) { isc_task_shutdown(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0;
bool was_idle; bool was_idle;
/* /*
@@ -841,9 +830,7 @@ isc_task_destroy(isc_task_t **taskp) {
} }
void void
isc_task_setname(isc_task_t *task0, const char *name, void *tag) { isc_task_setname(isc_task_t *task, const char *name, void *tag) {
isc__task_t *task = (isc__task_t *)task0;
/* /*
* Name 'task'. * Name 'task'.
*/ */
@@ -857,27 +844,21 @@ isc_task_setname(isc_task_t *task0, const char *name, void *tag) {
} }
const char * const char *
isc_task_getname(isc_task_t *task0) { isc_task_getname(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
return (task->name); return (task->name);
} }
void * void *
isc_task_gettag(isc_task_t *task0) { isc_task_gettag(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
return (task->tag); return (task->tag);
} }
void void
isc_task_getcurrenttime(isc_task_t *task0, isc_stdtime_t *t) { isc_task_getcurrenttime(isc_task_t *task, isc_stdtime_t *t) {
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
REQUIRE(t != NULL); REQUIRE(t != NULL);
@@ -887,9 +868,7 @@ isc_task_getcurrenttime(isc_task_t *task0, isc_stdtime_t *t) {
} }
void void
isc_task_getcurrenttimex(isc_task_t *task0, isc_time_t *t) { isc_task_getcurrenttimex(isc_task_t *task, isc_time_t *t) {
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
REQUIRE(t != NULL); REQUIRE(t != NULL);
@@ -910,7 +889,7 @@ isc_task_getcurrenttimex(isc_task_t *task0, isc_time_t *t) {
* Caller must hold the task manager lock. * Caller must hold the task manager lock.
*/ */
static inline bool static inline bool
empty_readyq(isc__taskmgr_t *manager, int c) { empty_readyq(isc_taskmgr_t *manager, int c) {
isc__tasklist_t queue; isc__tasklist_t queue;
if (atomic_load_relaxed(&manager->mode) == isc_taskmgrmode_normal) { if (atomic_load_relaxed(&manager->mode) == isc_taskmgrmode_normal) {
@@ -929,9 +908,9 @@ empty_readyq(isc__taskmgr_t *manager, int c) {
* *
* Caller must hold the task manager lock. * Caller must hold the task manager lock.
*/ */
static inline isc__task_t * static inline isc_task_t *
pop_readyq(isc__taskmgr_t *manager, int c) { pop_readyq(isc_taskmgr_t *manager, int c) {
isc__task_t *task; isc_task_t *task;
if (atomic_load_relaxed(&manager->mode) == isc_taskmgrmode_normal) { if (atomic_load_relaxed(&manager->mode) == isc_taskmgrmode_normal) {
task = HEAD(manager->queues[c].ready_tasks); task = HEAD(manager->queues[c].ready_tasks);
@@ -957,7 +936,7 @@ pop_readyq(isc__taskmgr_t *manager, int c) {
* Caller must hold the task queue lock. * Caller must hold the task queue lock.
*/ */
static inline void static inline void
push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c) { push_readyq(isc_taskmgr_t *manager, isc_task_t *task, int c) {
if (ISC_LINK_LINKED(task, ready_link)) { if (ISC_LINK_LINKED(task, ready_link)) {
return; return;
} }
@@ -971,8 +950,8 @@ push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c) {
} }
static void static void
dispatch(isc__taskmgr_t *manager, unsigned int threadid) { dispatch(isc_taskmgr_t *manager, unsigned int threadid) {
isc__task_t *task; isc_task_t *task;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@@ -1336,7 +1315,7 @@ static isc_threadresult_t
#endif /* ifdef _WIN32 */ #endif /* ifdef _WIN32 */
run(void *queuep) { run(void *queuep) {
isc__taskqueue_t *tq = queuep; isc__taskqueue_t *tq = queuep;
isc__taskmgr_t *manager = tq->manager; isc_taskmgr_t *manager = tq->manager;
int threadid = tq->threadid; int threadid = tq->threadid;
isc_thread_setaffinity(threadid); isc_thread_setaffinity(threadid);
@@ -1354,7 +1333,7 @@ static isc_threadresult_t
} }
static void static void
manager_free(isc__taskmgr_t *manager) { manager_free(isc_taskmgr_t *manager) {
for (unsigned int i = 0; i < manager->workers; i++) { for (unsigned int i = 0; i < manager->workers; i++) {
isc_mutex_destroy(&manager->queues[i].lock); isc_mutex_destroy(&manager->queues[i].lock);
isc_condition_destroy(&manager->queues[i].work_available); isc_condition_destroy(&manager->queues[i].work_available);
@@ -1365,8 +1344,7 @@ manager_free(isc__taskmgr_t *manager) {
isc_condition_destroy(&manager->halt_cond); isc_condition_destroy(&manager->halt_cond);
isc_mem_put(manager->mctx, manager->queues, isc_mem_put(manager->mctx, manager->queues,
manager->workers * sizeof(isc__taskqueue_t)); manager->workers * sizeof(isc__taskqueue_t));
manager->common.impmagic = 0; manager->magic = 0;
manager->common.magic = 0;
isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager)); isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager));
} }
@@ -1375,7 +1353,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
unsigned int default_quantum, isc_nm_t *nm, unsigned int default_quantum, isc_nm_t *nm,
isc_taskmgr_t **managerp) { isc_taskmgr_t **managerp) {
unsigned int i; unsigned int i;
isc__taskmgr_t *manager; isc_taskmgr_t *manager;
/* /*
* Create a new task manager. * Create a new task manager.
@@ -1385,8 +1363,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
REQUIRE(managerp != NULL && *managerp == NULL); REQUIRE(managerp != NULL && *managerp == NULL);
manager = isc_mem_get(mctx, sizeof(*manager)); manager = isc_mem_get(mctx, sizeof(*manager));
*manager = (isc__taskmgr_t){ .common.impmagic = TASK_MANAGER_MAGIC, *manager = (isc_taskmgr_t){ .magic = TASK_MANAGER_MAGIC };
.common.magic = ISCAPI_TASKMGR_MAGIC };
atomic_store(&manager->mode, isc_taskmgrmode_normal); atomic_store(&manager->mode, isc_taskmgrmode_normal);
isc_mutex_init(&manager->lock); isc_mutex_init(&manager->lock);
@@ -1449,8 +1426,8 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
void void
isc_taskmgr_destroy(isc_taskmgr_t **managerp) { isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
isc__taskmgr_t *manager; isc_taskmgr_t *manager;
isc__task_t *task; isc_task_t *task;
unsigned int i; unsigned int i;
bool exiting; bool exiting;
@@ -1459,7 +1436,7 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
*/ */
REQUIRE(managerp != NULL); REQUIRE(managerp != NULL);
manager = (isc__taskmgr_t *)*managerp; manager = (isc_taskmgr_t *)*managerp;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
XTHREADTRACE("isc_taskmgr_destroy"); XTHREADTRACE("isc_taskmgr_destroy");
@@ -1549,20 +1526,20 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
void void
isc_taskmgr_setprivilegedmode(isc_taskmgr_t *manager0) { isc_taskmgr_setprivilegedmode(isc_taskmgr_t *manager0) {
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; isc_taskmgr_t *manager = (isc_taskmgr_t *)manager0;
atomic_store(&manager->mode, isc_taskmgrmode_privileged); atomic_store(&manager->mode, isc_taskmgrmode_privileged);
} }
isc_taskmgrmode_t isc_taskmgrmode_t
isc_taskmgr_mode(isc_taskmgr_t *manager0) { isc_taskmgr_mode(isc_taskmgr_t *manager0) {
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; isc_taskmgr_t *manager = (isc_taskmgr_t *)manager0;
return (atomic_load(&manager->mode)); return (atomic_load(&manager->mode));
} }
void void
isc__taskmgr_pause(isc_taskmgr_t *manager0) { isc__taskmgr_pause(isc_taskmgr_t *manager0) {
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; isc_taskmgr_t *manager = (isc_taskmgr_t *)manager0;
LOCK(&manager->halt_lock); LOCK(&manager->halt_lock);
while (atomic_load_relaxed(&manager->exclusive_req) || while (atomic_load_relaxed(&manager->exclusive_req) ||
@@ -1584,7 +1561,7 @@ isc__taskmgr_pause(isc_taskmgr_t *manager0) {
void void
isc__taskmgr_resume(isc_taskmgr_t *manager0) { isc__taskmgr_resume(isc_taskmgr_t *manager0) {
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; isc_taskmgr_t *manager = (isc_taskmgr_t *)manager0;
LOCK(&manager->halt_lock); LOCK(&manager->halt_lock);
if (atomic_load(&manager->pause_req)) { if (atomic_load(&manager->pause_req)) {
atomic_store(&manager->pause_req, false); atomic_store(&manager->pause_req, false);
@@ -1597,23 +1574,19 @@ isc__taskmgr_resume(isc_taskmgr_t *manager0) {
} }
void void
isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0) { isc_taskmgr_setexcltask(isc_taskmgr_t *mgr, isc_task_t *task) {
isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0;
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_MANAGER(mgr)); REQUIRE(VALID_MANAGER(mgr));
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
LOCK(&mgr->excl_lock); LOCK(&mgr->excl_lock);
if (mgr->excl != NULL) { if (mgr->excl != NULL) {
isc_task_detach((isc_task_t **)&mgr->excl); isc_task_detach((isc_task_t **)&mgr->excl);
} }
isc_task_attach(task0, (isc_task_t **)&mgr->excl); isc_task_attach(task, (isc_task_t **)&mgr->excl);
UNLOCK(&mgr->excl_lock); UNLOCK(&mgr->excl_lock);
} }
isc_result_t isc_result_t
isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp) { isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp) {
isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0;
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
REQUIRE(VALID_MANAGER(mgr)); REQUIRE(VALID_MANAGER(mgr));
@@ -1631,9 +1604,8 @@ isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp) {
} }
isc_result_t isc_result_t
isc_task_beginexclusive(isc_task_t *task0) { isc_task_beginexclusive(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0; isc_taskmgr_t *manager;
isc__taskmgr_t *manager;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
@@ -1669,9 +1641,8 @@ isc_task_beginexclusive(isc_task_t *task0) {
} }
void void
isc_task_endexclusive(isc_task_t *task0) { isc_task_endexclusive(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0; isc_taskmgr_t *manager;
isc__taskmgr_t *manager;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
REQUIRE(task->state == task_state_running); REQUIRE(task->state == task_state_running);
@@ -1691,9 +1662,8 @@ isc_task_endexclusive(isc_task_t *task0) {
} }
void void
isc_task_pause(isc_task_t *task0) { isc_task_pause(isc_task_t *task) {
REQUIRE(ISCAPI_TASK_VALID(task0)); REQUIRE(VALID_TASK(task));
isc__task_t *task = (isc__task_t *)task0;
LOCK(&task->lock); LOCK(&task->lock);
task->pause_cnt++; task->pause_cnt++;
@@ -1718,11 +1688,10 @@ isc_task_pause(isc_task_t *task0) {
} }
void void
isc_task_unpause(isc_task_t *task0) { isc_task_unpause(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0;
bool was_idle = false; bool was_idle = false;
REQUIRE(ISCAPI_TASK_VALID(task0)); REQUIRE(VALID_TASK(task));
LOCK(&task->lock); LOCK(&task->lock);
task->pause_cnt--; task->pause_cnt--;
@@ -1752,10 +1721,9 @@ isc_task_unpause(isc_task_t *task0) {
} }
void void
isc_task_setprivilege(isc_task_t *task0, bool priv) { isc_task_setprivilege(isc_task_t *task, bool priv) {
REQUIRE(ISCAPI_TASK_VALID(task0)); REQUIRE(VALID_TASK(task));
isc__task_t *task = (isc__task_t *)task0; isc_taskmgr_t *manager = task->manager;
isc__taskmgr_t *manager = task->manager;
uint_fast32_t oldflags, newflags; uint_fast32_t oldflags, newflags;
oldflags = atomic_load_acquire(&task->flags); oldflags = atomic_load_acquire(&task->flags);
@@ -1783,8 +1751,7 @@ isc_task_setprivilege(isc_task_t *task0, bool priv) {
} }
bool bool
isc_task_privilege(isc_task_t *task0) { isc_task_privilege(isc_task_t *task) {
isc__task_t *task = (isc__task_t *)task0;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
return (TASK_PRIVILEGED(task)); return (TASK_PRIVILEGED(task));
@@ -1792,7 +1759,7 @@ isc_task_privilege(isc_task_t *task0) {
bool bool
isc_task_exiting(isc_task_t *t) { isc_task_exiting(isc_task_t *t) {
isc__task_t *task = (isc__task_t *)t; isc_task_t *task = (isc_task_t *)t;
REQUIRE(VALID_TASK(task)); REQUIRE(VALID_TASK(task));
return (TASK_SHUTTINGDOWN(task)); return (TASK_SHUTTINGDOWN(task));
@@ -1806,9 +1773,8 @@ isc_task_exiting(isc_task_t *t) {
goto error; \ goto error; \
} while (0) } while (0)
int int
isc_taskmgr_renderxml(isc_taskmgr_t *mgr0, void *writer0) { isc_taskmgr_renderxml(isc_taskmgr_t *mgr, void *writer0) {
isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0; isc_task_t *task = NULL;
isc__task_t *task = NULL;
int xmlrc; int xmlrc;
xmlTextWriterPtr writer = (xmlTextWriterPtr)writer0; xmlTextWriterPtr writer = (xmlTextWriterPtr)writer0;
@@ -1916,10 +1882,9 @@ error:
} while (0) } while (0)
isc_result_t isc_result_t
isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, void *tasks0) { isc_taskmgr_renderjson(isc_taskmgr_t *mgr, void *tasks0) {
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0; isc_task_t *task = NULL;
isc__task_t *task = NULL;
json_object *obj = NULL, *array = NULL, *taskobj = NULL; json_object *obj = NULL, *array = NULL, *taskobj = NULL;
json_object *tasks = (json_object *)tasks0; json_object *tasks = (json_object *)tasks0;

View File

@@ -124,13 +124,13 @@ get_tasks(void **state) {
/* two tasks in pool; make sure we can access them more than twice */ /* two tasks in pool; make sure we can access them more than twice */
isc_taskpool_gettask(pool, &task1); isc_taskpool_gettask(pool, &task1);
assert_true(ISCAPI_TASK_VALID(task1)); assert_non_null(task1);
isc_taskpool_gettask(pool, &task2); isc_taskpool_gettask(pool, &task2);
assert_true(ISCAPI_TASK_VALID(task2)); assert_non_null(task2);
isc_taskpool_gettask(pool, &task3); isc_taskpool_gettask(pool, &task3);
assert_true(ISCAPI_TASK_VALID(task3)); assert_non_null(task3);
isc_task_destroy(&task1); isc_task_destroy(&task1);
isc_task_destroy(&task2); isc_task_destroy(&task2);
@@ -159,9 +159,9 @@ set_privilege(void **state) {
isc_taskpool_gettask(pool, &task2); isc_taskpool_gettask(pool, &task2);
isc_taskpool_gettask(pool, &task3); isc_taskpool_gettask(pool, &task3);
assert_true(ISCAPI_TASK_VALID(task1)); assert_non_null(task1);
assert_true(ISCAPI_TASK_VALID(task2)); assert_non_null(task2);
assert_true(ISCAPI_TASK_VALID(task3)); assert_non_null(task3);
assert_true(isc_task_privilege(task1)); assert_true(isc_task_privilege(task1));
assert_true(isc_task_privilege(task2)); assert_true(isc_task_privilege(task2));

View File

@@ -55,13 +55,10 @@
#define TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R') #define TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R')
#define VALID_TIMER(t) ISC_MAGIC_VALID(t, TIMER_MAGIC) #define VALID_TIMER(t) ISC_MAGIC_VALID(t, TIMER_MAGIC)
typedef struct isc__timer isc__timer_t; struct isc_timer {
typedef struct isc__timermgr isc__timermgr_t;
struct isc__timer {
/*! Not locked. */ /*! Not locked. */
isc_timer_t common; unsigned int magic;
isc__timermgr_t *manager; isc_timermgr_t *manager;
isc_mutex_t lock; isc_mutex_t lock;
isc_refcount_t references; isc_refcount_t references;
/*! Locked by timer lock. */ /*! Locked by timer lock. */
@@ -75,20 +72,20 @@ struct isc__timer {
void *arg; void *arg;
unsigned int index; unsigned int index;
isc_time_t due; isc_time_t due;
LINK(isc__timer_t) link; LINK(isc_timer_t) link;
}; };
#define TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M') #define TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M')
#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC) #define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC)
struct isc__timermgr { struct isc_timermgr {
/* Not locked. */ /* Not locked. */
isc_timermgr_t common; unsigned int magic;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t lock; isc_mutex_t lock;
/* Locked by manager lock. */ /* Locked by manager lock. */
bool done; bool done;
LIST(isc__timer_t) timers; LIST(isc_timer_t) timers;
unsigned int nscheduled; unsigned int nscheduled;
isc_time_t due; isc_time_t due;
isc_condition_t wakeup; isc_condition_t wakeup;
@@ -100,9 +97,9 @@ void
isc_timermgr_poke(isc_timermgr_t *manager0); isc_timermgr_poke(isc_timermgr_t *manager0);
static inline isc_result_t static inline isc_result_t
schedule(isc__timer_t *timer, isc_time_t *now, bool signal_ok) { schedule(isc_timer_t *timer, isc_time_t *now, bool signal_ok) {
isc_result_t result; isc_result_t result;
isc__timermgr_t *manager; isc_timermgr_t *manager;
isc_time_t due; isc_time_t due;
int cmp; int cmp;
@@ -189,9 +186,9 @@ schedule(isc__timer_t *timer, isc_time_t *now, bool signal_ok) {
} }
static inline void static inline void
deschedule(isc__timer_t *timer) { deschedule(isc_timer_t *timer) {
bool need_wakeup = false; bool need_wakeup = false;
isc__timermgr_t *manager; isc_timermgr_t *manager;
/* /*
* The caller must ensure locking. * The caller must ensure locking.
@@ -214,8 +211,8 @@ deschedule(isc__timer_t *timer) {
} }
static void static void
destroy(isc__timer_t *timer) { destroy(isc_timer_t *timer) {
isc__timermgr_t *manager = timer->manager; isc_timermgr_t *manager = timer->manager;
/* /*
* The caller must ensure it is safe to destroy the timer. * The caller must ensure it is safe to destroy the timer.
@@ -232,22 +229,20 @@ destroy(isc__timer_t *timer) {
isc_task_detach(&timer->task); isc_task_detach(&timer->task);
isc_mutex_destroy(&timer->lock); isc_mutex_destroy(&timer->lock);
timer->common.impmagic = 0; timer->magic = 0;
timer->common.magic = 0;
isc_mem_put(manager->mctx, timer, sizeof(*timer)); isc_mem_put(manager->mctx, timer, sizeof(*timer));
} }
isc_result_t isc_result_t
isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type, isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval, const isc_time_t *expires, const isc_interval_t *interval,
isc_task_t *task, isc_taskaction_t action, void *arg, isc_task_t *task, isc_taskaction_t action, void *arg,
isc_timer_t **timerp) { isc_timer_t **timerp) {
REQUIRE(VALID_MANAGER(manager0)); REQUIRE(VALID_MANAGER(manager));
REQUIRE(task != NULL); REQUIRE(task != NULL);
REQUIRE(action != NULL); REQUIRE(action != NULL);
isc__timermgr_t *manager; isc_timer_t *timer;
isc__timer_t *timer;
isc_result_t result; isc_result_t result;
isc_time_t now; isc_time_t now;
@@ -258,7 +253,6 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
* called with 'arg' as the arg value. The new timer is returned * called with 'arg' as the arg value. The new timer is returned
* in 'timerp'. * in 'timerp'.
*/ */
manager = (isc__timermgr_t *)manager0;
if (expires == NULL) { if (expires == NULL) {
expires = isc_time_epoch; expires = isc_time_epoch;
} }
@@ -320,8 +314,7 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
timer->index = 0; timer->index = 0;
isc_mutex_init(&timer->lock); isc_mutex_init(&timer->lock);
ISC_LINK_INIT(timer, link); ISC_LINK_INIT(timer, link);
timer->common.impmagic = TIMER_MAGIC; timer->magic = TIMER_MAGIC;
timer->common.magic = ISCAPI_TIMER_MAGIC;
LOCK(&manager->lock); LOCK(&manager->lock);
@@ -336,15 +329,14 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
result = ISC_R_SUCCESS; result = ISC_R_SUCCESS;
} }
if (result == ISC_R_SUCCESS) { if (result == ISC_R_SUCCESS) {
*timerp = (isc_timer_t *)timer; *timerp = timer;
APPEND(manager->timers, timer, link); APPEND(manager->timers, timer, link);
} }
UNLOCK(&manager->lock); UNLOCK(&manager->lock);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
timer->common.impmagic = 0; timer->magic = 0;
timer->common.magic = 0;
isc_mutex_destroy(&timer->lock); isc_mutex_destroy(&timer->lock);
isc_task_detach(&timer->task); isc_task_detach(&timer->task);
isc_mem_put(manager->mctx, timer, sizeof(*timer)); isc_mem_put(manager->mctx, timer, sizeof(*timer));
@@ -355,12 +347,11 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
} }
isc_result_t isc_result_t
isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type, isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval, const isc_time_t *expires, const isc_interval_t *interval,
bool purge) { bool purge) {
isc__timer_t *timer;
isc_time_t now; isc_time_t now;
isc__timermgr_t *manager; isc_timermgr_t *manager;
isc_result_t result; isc_result_t result;
/* /*
@@ -369,8 +360,7 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type,
* are purged from its task's event queue. * are purged from its task's event queue.
*/ */
REQUIRE(VALID_TIMER(timer0)); REQUIRE(VALID_TIMER(timer));
timer = (isc__timer_t *)timer0;
manager = timer->manager; manager = timer->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@@ -433,12 +423,10 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type,
} }
isc_timertype_t isc_timertype_t
isc_timer_gettype(isc_timer_t *timer0) { isc_timer_gettype(isc_timer_t *timer) {
isc__timer_t *timer;
isc_timertype_t t; isc_timertype_t t;
REQUIRE(VALID_TIMER(timer0)); REQUIRE(VALID_TIMER(timer));
timer = (isc__timer_t *)timer0;
LOCK(&timer->lock); LOCK(&timer->lock);
t = timer->type; t = timer->type;
@@ -448,8 +436,7 @@ isc_timer_gettype(isc_timer_t *timer0) {
} }
isc_result_t isc_result_t
isc_timer_touch(isc_timer_t *timer0) { isc_timer_touch(isc_timer_t *timer) {
isc__timer_t *timer;
isc_result_t result; isc_result_t result;
isc_time_t now; isc_time_t now;
@@ -457,8 +444,7 @@ isc_timer_touch(isc_timer_t *timer0) {
* Set the last-touched time of 'timer' to the current time. * Set the last-touched time of 'timer' to the current time.
*/ */
REQUIRE(VALID_TIMER(timer0)); REQUIRE(VALID_TIMER(timer));
timer = (isc__timer_t *)timer0;
LOCK(&timer->lock); LOCK(&timer->lock);
@@ -480,31 +466,28 @@ isc_timer_touch(isc_timer_t *timer0) {
} }
void void
isc_timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) { isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
isc__timer_t *timer;
/* /*
* Attach *timerp to timer. * Attach *timerp to timer.
*/ */
REQUIRE(VALID_TIMER(timer0)); REQUIRE(VALID_TIMER(timer));
timer = (isc__timer_t *)timer0;
REQUIRE(timerp != NULL && *timerp == NULL); REQUIRE(timerp != NULL && *timerp == NULL);
isc_refcount_increment(&timer->references); isc_refcount_increment(&timer->references);
*timerp = (isc_timer_t *)timer; *timerp = timer;
} }
void void
isc_timer_detach(isc_timer_t **timerp) { isc_timer_detach(isc_timer_t **timerp) {
isc__timer_t *timer; isc_timer_t *timer;
/* /*
* Detach *timerp from its timer. * Detach *timerp from its timer.
*/ */
REQUIRE(timerp != NULL); REQUIRE(timerp != NULL);
timer = (isc__timer_t *)*timerp; timer = *timerp;
REQUIRE(VALID_TIMER(timer)); REQUIRE(VALID_TIMER(timer));
if (isc_refcount_decrement(&timer->references) == 1) { if (isc_refcount_decrement(&timer->references) == 1) {
@@ -515,11 +498,11 @@ isc_timer_detach(isc_timer_t **timerp) {
} }
static void static void
dispatch(isc__timermgr_t *manager, isc_time_t *now) { dispatch(isc_timermgr_t *manager, isc_time_t *now) {
bool done = false, post_event, need_schedule; bool done = false, post_event, need_schedule;
isc_timerevent_t *event; isc_timerevent_t *event;
isc_eventtype_t type = 0; isc_eventtype_t type = 0;
isc__timer_t *timer; isc_timer_t *timer;
isc_result_t result; isc_result_t result;
bool idle; bool idle;
@@ -625,7 +608,7 @@ static isc_threadresult_t
WINAPI WINAPI
#endif /* ifdef _WIN32 */ #endif /* ifdef _WIN32 */
run(void *uap) { run(void *uap) {
isc__timermgr_t *manager = uap; isc_timermgr_t *manager = uap;
isc_time_t now; isc_time_t now;
isc_result_t result; isc_result_t result;
@@ -660,7 +643,7 @@ static isc_threadresult_t
static bool static bool
sooner(void *v1, void *v2) { sooner(void *v1, void *v2) {
isc__timer_t *t1, *t2; isc_timer_t *t1, *t2;
t1 = v1; t1 = v1;
t2 = v2; t2 = v2;
@@ -675,7 +658,7 @@ sooner(void *v1, void *v2) {
static void static void
set_index(void *what, unsigned int index) { set_index(void *what, unsigned int index) {
isc__timer_t *timer; isc_timer_t *timer;
REQUIRE(VALID_TIMER(what)); REQUIRE(VALID_TIMER(what));
timer = what; timer = what;
@@ -685,7 +668,7 @@ set_index(void *what, unsigned int index) {
isc_result_t isc_result_t
isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) { isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
isc__timermgr_t *manager; isc_timermgr_t *manager;
isc_result_t result; isc_result_t result;
/* /*
@@ -696,8 +679,7 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
manager = isc_mem_get(mctx, sizeof(*manager)); manager = isc_mem_get(mctx, sizeof(*manager));
manager->common.impmagic = TIMER_MANAGER_MAGIC; manager->magic = TIMER_MANAGER_MAGIC;
manager->common.magic = ISCAPI_TIMERMGR_MAGIC;
manager->mctx = NULL; manager->mctx = NULL;
manager->done = false; manager->done = false;
INIT_LIST(manager->timers); INIT_LIST(manager->timers);
@@ -716,31 +698,28 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
isc_thread_create(run, manager, &manager->thread); isc_thread_create(run, manager, &manager->thread);
isc_thread_setname(manager->thread, "isc-timer"); isc_thread_setname(manager->thread, "isc-timer");
*managerp = (isc_timermgr_t *)manager; *managerp = manager;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void void
isc_timermgr_poke(isc_timermgr_t *manager0) { isc_timermgr_poke(isc_timermgr_t *manager) {
isc__timermgr_t *manager; REQUIRE(VALID_MANAGER(manager));
REQUIRE(VALID_MANAGER(manager0));
manager = (isc__timermgr_t *)manager0;
SIGNAL(&manager->wakeup); SIGNAL(&manager->wakeup);
} }
void void
isc_timermgr_destroy(isc_timermgr_t **managerp) { isc_timermgr_destroy(isc_timermgr_t **managerp) {
isc__timermgr_t *manager; isc_timermgr_t *manager;
/* /*
* Destroy a timer manager. * Destroy a timer manager.
*/ */
REQUIRE(managerp != NULL); REQUIRE(managerp != NULL);
manager = (isc__timermgr_t *)*managerp; manager = *managerp;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
LOCK(&manager->lock); LOCK(&manager->lock);
@@ -764,8 +743,7 @@ isc_timermgr_destroy(isc_timermgr_t **managerp) {
(void)isc_condition_destroy(&manager->wakeup); (void)isc_condition_destroy(&manager->wakeup);
isc_mutex_destroy(&manager->lock); isc_mutex_destroy(&manager->lock);
isc_heap_destroy(&manager->heap); isc_heap_destroy(&manager->heap);
manager->common.impmagic = 0; manager->magic = 0;
manager->common.magic = 0;
isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager)); isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager));
*managerp = NULL; *managerp = NULL;

View File

@@ -319,23 +319,21 @@ typedef isc_event_t intev_t;
*/ */
#define NRETRIES 10 #define NRETRIES 10
typedef struct isc__socket isc__socket_t;
typedef struct isc__socketmgr isc__socketmgr_t;
typedef struct isc__socketthread isc__socketthread_t; typedef struct isc__socketthread isc__socketthread_t;
#define NEWCONNSOCK(ev) ((isc__socket_t *)(ev)->newsocket) #define NEWCONNSOCK(ev) ((ev)->newsocket)
struct isc__socket { struct isc_socket {
/* Not locked. */ /* Not locked. */
isc_socket_t common; unsigned int magic;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
isc_mutex_t lock; isc_mutex_t lock;
isc_sockettype_t type; isc_sockettype_t type;
const isc_statscounter_t *statsindex; const isc_statscounter_t *statsindex;
isc_refcount_t references; isc_refcount_t references;
/* Locked by socket lock. */ /* Locked by socket lock. */
ISC_LINK(isc__socket_t) link; ISC_LINK(isc_socket_t) link;
int fd; int fd;
int pf; int pf;
int threadid; int threadid;
@@ -366,9 +364,9 @@ struct isc__socket {
#define SOCKET_MANAGER_MAGIC ISC_MAGIC('I', 'O', 'm', 'g') #define SOCKET_MANAGER_MAGIC ISC_MAGIC('I', 'O', 'm', 'g')
#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, SOCKET_MANAGER_MAGIC) #define VALID_MANAGER(m) ISC_MAGIC_VALID(m, SOCKET_MANAGER_MAGIC)
struct isc__socketmgr { struct isc_socketmgr {
/* Not locked. */ /* Not locked. */
isc_socketmgr_t common; unsigned int magic;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t lock; isc_mutex_t lock;
isc_stats_t *stats; isc_stats_t *stats;
@@ -376,20 +374,20 @@ struct isc__socketmgr {
isc__socketthread_t *threads; isc__socketthread_t *threads;
unsigned int maxsocks; unsigned int maxsocks;
/* Locked by manager lock. */ /* Locked by manager lock. */
ISC_LIST(isc__socket_t) socklist; ISC_LIST(isc_socket_t) socklist;
int reserved; /* unlocked */ int reserved; /* unlocked */
isc_condition_t shutdown_ok; isc_condition_t shutdown_ok;
size_t maxudp; size_t maxudp;
}; };
struct isc__socketthread { struct isc__socketthread {
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
int threadid; int threadid;
isc_thread_t thread; isc_thread_t thread;
int pipe_fds[2]; int pipe_fds[2];
isc_mutex_t *fdlock; isc_mutex_t *fdlock;
/* Locked by fdlock. */ /* Locked by fdlock. */
isc__socket_t **fds; isc_socket_t **fds;
int *fdstate; int *fdstate;
#ifdef USE_KQUEUE #ifdef USE_KQUEUE
int kqueue_fd; int kqueue_fd;
@@ -438,37 +436,37 @@ static isc_result_t
socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
isc_socket_t **socketp, isc_socket_t *dup_socket); isc_socket_t **socketp, isc_socket_t *dup_socket);
static void static void
send_recvdone_event(isc__socket_t *, isc_socketevent_t **); send_recvdone_event(isc_socket_t *, isc_socketevent_t **);
static void static void
send_senddone_event(isc__socket_t *, isc_socketevent_t **); send_senddone_event(isc_socket_t *, isc_socketevent_t **);
static void static void
send_connectdone_event(isc__socket_t *, isc_socket_connev_t **); send_connectdone_event(isc_socket_t *, isc_socket_connev_t **);
static void static void
free_socket(isc__socket_t **); free_socket(isc_socket_t **);
static isc_result_t static isc_result_t
allocate_socket(isc__socketmgr_t *, isc_sockettype_t, isc__socket_t **); allocate_socket(isc_socketmgr_t *, isc_sockettype_t, isc_socket_t **);
static void static void
destroy(isc__socket_t **); destroy(isc_socket_t **);
static void static void
internal_accept(isc__socket_t *); internal_accept(isc_socket_t *);
static void static void
internal_connect(isc__socket_t *); internal_connect(isc_socket_t *);
static void static void
internal_recv(isc__socket_t *); internal_recv(isc_socket_t *);
static void static void
internal_send(isc__socket_t *); internal_send(isc_socket_t *);
static void static void
process_cmsg(isc__socket_t *, struct msghdr *, isc_socketevent_t *); process_cmsg(isc_socket_t *, struct msghdr *, isc_socketevent_t *);
static void static void
build_msghdr_send(isc__socket_t *, char *, isc_socketevent_t *, struct msghdr *, build_msghdr_send(isc_socket_t *, char *, isc_socketevent_t *, struct msghdr *,
struct iovec *, size_t *); struct iovec *, size_t *);
static void static void
build_msghdr_recv(isc__socket_t *, char *, isc_socketevent_t *, struct msghdr *, build_msghdr_recv(isc_socket_t *, char *, isc_socketevent_t *, struct msghdr *,
struct iovec *, size_t *); struct iovec *, size_t *);
static bool static bool
process_ctlfd(isc__socketthread_t *thread); process_ctlfd(isc__socketthread_t *thread);
static void static void
setdscp(isc__socket_t *sock, isc_dscp_t dscp); setdscp(isc_socket_t *sock, isc_dscp_t dscp);
#define SELECT_POKE_SHUTDOWN (-1) #define SELECT_POKE_SHUTDOWN (-1)
#define SELECT_POKE_NOTHING (-2) #define SELECT_POKE_NOTHING (-2)
@@ -559,19 +557,19 @@ static const isc_statscounter_t rawstatsindex[] = {
}; };
static int static int
gen_threadid(isc__socket_t *sock); gen_threadid(isc_socket_t *sock);
static int static int
gen_threadid(isc__socket_t *sock) { gen_threadid(isc_socket_t *sock) {
return (sock->fd % sock->manager->nthreads); return (sock->fd % sock->manager->nthreads);
} }
static void static void
manager_log(isc__socketmgr_t *sockmgr, isc_logcategory_t *category, manager_log(isc_socketmgr_t *sockmgr, isc_logcategory_t *category,
isc_logmodule_t *module, int level, const char *fmt, ...) isc_logmodule_t *module, int level, const char *fmt, ...)
ISC_FORMAT_PRINTF(5, 6); ISC_FORMAT_PRINTF(5, 6);
static void static void
manager_log(isc__socketmgr_t *sockmgr, isc_logcategory_t *category, manager_log(isc_socketmgr_t *sockmgr, isc_logcategory_t *category,
isc_logmodule_t *module, int level, const char *fmt, ...) { isc_logmodule_t *module, int level, const char *fmt, ...) {
char msgbuf[2048]; char msgbuf[2048];
va_list ap; va_list ap;
@@ -612,11 +610,11 @@ thread_log(isc__socketthread_t *thread, isc_logcategory_t *category,
} }
static void static void
socket_log(isc__socket_t *sock, const isc_sockaddr_t *address, socket_log(isc_socket_t *sock, const isc_sockaddr_t *address,
isc_logcategory_t *category, isc_logmodule_t *module, int level, isc_logcategory_t *category, isc_logmodule_t *module, int level,
const char *fmt, ...) ISC_FORMAT_PRINTF(6, 7); const char *fmt, ...) ISC_FORMAT_PRINTF(6, 7);
static void static void
socket_log(isc__socket_t *sock, const isc_sockaddr_t *address, socket_log(isc_socket_t *sock, const isc_sockaddr_t *address,
isc_logcategory_t *category, isc_logmodule_t *module, int level, isc_logcategory_t *category, isc_logmodule_t *module, int level,
const char *fmt, ...) { const char *fmt, ...) {
char msgbuf[2048]; char msgbuf[2048];
@@ -923,7 +921,7 @@ wakeup_socket(isc__socketthread_t *thread, int fd, int msg) {
* will not get partial writes. * will not get partial writes.
*/ */
static void static void
select_poke(isc__socketmgr_t *mgr, int threadid, int fd, int msg) { select_poke(isc_socketmgr_t *mgr, int threadid, int fd, int msg) {
int cc; int cc;
int buf[2]; int buf[2];
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
@@ -1077,7 +1075,7 @@ cmsg_space(socklen_t len) {
* Process control messages received on a socket. * Process control messages received on a socket.
*/ */
static void static void
process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) { process_cmsg(isc_socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) {
#ifdef USE_CMSG #ifdef USE_CMSG
struct cmsghdr *cmsgp; struct cmsghdr *cmsgp;
struct in6_pktinfo *pktinfop; struct in6_pktinfo *pktinfop;
@@ -1195,7 +1193,7 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) {
* this transaction can send. * this transaction can send.
*/ */
static void static void
build_msghdr_send(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, build_msghdr_send(isc_socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev,
struct msghdr *msg, struct iovec *iov, size_t *write_countp) { struct msghdr *msg, struct iovec *iov, size_t *write_countp) {
unsigned int iovcount; unsigned int iovcount;
size_t write_count; size_t write_count;
@@ -1359,7 +1357,7 @@ build_msghdr_send(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev,
* this transaction can receive. * this transaction can receive.
*/ */
static void static void
build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, build_msghdr_recv(isc_socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev,
struct msghdr *msg, struct iovec *iov, size_t *read_countp) { struct msghdr *msg, struct iovec *iov, size_t *read_countp) {
unsigned int iovcount; unsigned int iovcount;
size_t read_count; size_t read_count;
@@ -1411,7 +1409,7 @@ build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev,
} }
static void static void
set_dev_address(const isc_sockaddr_t *address, isc__socket_t *sock, set_dev_address(const isc_sockaddr_t *address, isc_socket_t *sock,
isc_socketevent_t *dev) { isc_socketevent_t *dev) {
if (sock->type == isc_sockettype_udp) { if (sock->type == isc_sockettype_udp) {
if (address != NULL) { if (address != NULL) {
@@ -1476,7 +1474,7 @@ dump_msg(struct msghdr *msg) {
#define DOIO_EOF 3 /* EOF, no event sent */ #define DOIO_EOF 3 /* EOF, no event sent */
static int static int
doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) { doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) {
int cc; int cc;
struct iovec iov[MAXSCATTERGATHER_RECV]; struct iovec iov[MAXSCATTERGATHER_RECV];
size_t read_count; size_t read_count;
@@ -1651,7 +1649,7 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) {
* No other return values are possible. * No other return values are possible.
*/ */
static int static int
doio_send(isc__socket_t *sock, isc_socketevent_t *dev) { doio_send(isc_socket_t *sock, isc_socketevent_t *dev) {
int cc; int cc;
struct iovec iov[MAXSCATTERGATHER_SEND]; struct iovec iov[MAXSCATTERGATHER_SEND];
size_t write_count; size_t write_count;
@@ -1773,7 +1771,7 @@ resend:
* references exist. * references exist.
*/ */
static void static void
socketclose(isc__socketthread_t *thread, isc__socket_t *sock, int fd) { socketclose(isc__socketthread_t *thread, isc_socket_t *sock, int fd) {
int lockid = FDLOCK_ID(fd); int lockid = FDLOCK_ID(fd);
/* /*
* No one has this socket open, so the watcher doesn't have to be * No one has this socket open, so the watcher doesn't have to be
@@ -1826,10 +1824,10 @@ socketclose(isc__socketthread_t *thread, isc__socket_t *sock, int fd) {
} }
static void static void
destroy(isc__socket_t **sockp) { destroy(isc_socket_t **sockp) {
int fd = 0; int fd = 0;
isc__socket_t *sock = *sockp; isc_socket_t *sock = *sockp;
isc__socketmgr_t *manager = sock->manager; isc_socketmgr_t *manager = sock->manager;
isc__socketthread_t *thread = NULL; isc__socketthread_t *thread = NULL;
socket_log(sock, NULL, CREATION, "destroying"); socket_log(sock, NULL, CREATION, "destroying");
@@ -1870,14 +1868,13 @@ destroy(isc__socket_t **sockp) {
} }
static isc_result_t static isc_result_t
allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type,
isc__socket_t **socketp) { isc_socket_t **socketp) {
isc__socket_t *sock; isc_socket_t *sock;
sock = isc_mem_get(manager->mctx, sizeof(*sock)); sock = isc_mem_get(manager->mctx, sizeof(*sock));
sock->common.magic = 0; sock->magic = 0;
sock->common.impmagic = 0;
isc_refcount_init(&sock->references, 0); isc_refcount_init(&sock->references, 0);
sock->manager = manager; sock->manager = manager;
@@ -1913,8 +1910,7 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
*/ */
isc_mutex_init(&sock->lock); isc_mutex_init(&sock->lock);
sock->common.magic = ISCAPI_SOCKET_MAGIC; sock->magic = SOCKET_MAGIC;
sock->common.impmagic = SOCKET_MAGIC;
*socketp = sock; *socketp = sock;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
@@ -1928,8 +1924,8 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
* also close the socket. * also close the socket.
*/ */
static void static void
free_socket(isc__socket_t **socketp) { free_socket(isc_socket_t **socketp) {
isc__socket_t *sock = *socketp; isc_socket_t *sock = *socketp;
*socketp = NULL; *socketp = NULL;
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
@@ -1943,8 +1939,7 @@ free_socket(isc__socket_t **socketp) {
INSIST(!ISC_LINK_LINKED(sock, link)); INSIST(!ISC_LINK_LINKED(sock, link));
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
sock->common.magic = 0; sock->magic = 0;
sock->common.impmagic = 0;
isc_mutex_destroy(&sock->lock); isc_mutex_destroy(&sock->lock);
@@ -2068,7 +2063,7 @@ cleanup:
#endif /* ifdef SO_SNDBUF */ #endif /* ifdef SO_SNDBUF */
static void static void
use_min_mtu(isc__socket_t *sock) { use_min_mtu(isc_socket_t *sock) {
#if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) #if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU)
UNUSED(sock); UNUSED(sock);
#endif /* if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) */ #endif /* if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) */
@@ -2093,7 +2088,7 @@ use_min_mtu(isc__socket_t *sock) {
} }
static void static void
set_tcp_maxseg(isc__socket_t *sock, int size) { set_tcp_maxseg(isc_socket_t *sock, int size) {
#ifdef TCP_MAXSEG #ifdef TCP_MAXSEG
if (sock->type == isc_sockettype_tcp) { if (sock->type == isc_sockettype_tcp) {
(void)setsockopt(sock->fd, IPPROTO_TCP, TCP_MAXSEG, (void)setsockopt(sock->fd, IPPROTO_TCP, TCP_MAXSEG,
@@ -2103,7 +2098,7 @@ set_tcp_maxseg(isc__socket_t *sock, int size) {
} }
static void static void
set_ip_dontfrag(isc__socket_t *sock) { set_ip_dontfrag(isc_socket_t *sock) {
/* /*
* Set the Don't Fragment flag on IP packets * Set the Don't Fragment flag on IP packets
*/ */
@@ -2129,8 +2124,8 @@ set_ip_dontfrag(isc__socket_t *sock) {
} }
static isc_result_t static isc_result_t
opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, opensocket(isc_socketmgr_t *manager, isc_socket_t *sock,
isc__socket_t *dup_socket) { isc_socket_t *dup_socket) {
isc_result_t result; isc_result_t result;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
const char *err = "socket"; const char *err = "socket";
@@ -2433,10 +2428,9 @@ setup_done:
* socket is returned in 'socketp'. * socket is returned in 'socketp'.
*/ */
static isc_result_t static isc_result_t
socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
isc_socket_t **socketp, isc_socket_t *dup_socket) { isc_socket_t **socketp, isc_socket_t *dup_socket) {
isc__socket_t *sock = NULL; isc_socket_t *sock = NULL;
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
isc__socketthread_t *thread; isc__socketthread_t *thread;
isc_result_t result; isc_result_t result;
int lockid; int lockid;
@@ -2473,7 +2467,7 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
sock->pf = pf; sock->pf = pf;
result = opensocket(manager, sock, (isc__socket_t *)dup_socket); result = opensocket(manager, sock, dup_socket);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
free_socket(&sock); free_socket(&sock);
return (result); return (result);
@@ -2485,7 +2479,7 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
sock->threadid = gen_threadid(sock); sock->threadid = gen_threadid(sock);
isc_refcount_increment0(&sock->references); isc_refcount_increment0(&sock->references);
thread = &manager->threads[sock->threadid]; thread = &manager->threads[sock->threadid];
*socketp = (isc_socket_t *)sock; *socketp = sock;
/* /*
* Note we don't have to lock the socket like we normally would because * Note we don't have to lock the socket like we normally would because
@@ -2537,20 +2531,17 @@ isc_socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
* in 'socketp'. * in 'socketp'.
*/ */
isc_result_t isc_result_t
isc_socket_dup(isc_socket_t *sock0, isc_socket_t **socketp) { isc_socket_dup(isc_socket_t *sock, isc_socket_t **socketp) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(socketp != NULL && *socketp == NULL); REQUIRE(socketp != NULL && *socketp == NULL);
return (socket_create((isc_socketmgr_t *)sock->manager, sock->pf, return (socket_create(sock->manager, sock->pf, sock->type, socketp,
sock->type, socketp, sock0)); sock));
} }
isc_result_t isc_result_t
isc_socket_open(isc_socket_t *sock0) { isc_socket_open(isc_socket_t *sock) {
isc_result_t result; isc_result_t result;
isc__socket_t *sock = (isc__socket_t *)sock0;
isc__socketthread_t *thread; isc__socketthread_t *thread;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
@@ -2600,16 +2591,14 @@ isc_socket_open(isc_socket_t *sock0) {
* Attach to a socket. Caller must explicitly detach when it is done. * Attach to a socket. Caller must explicitly detach when it is done.
*/ */
void void
isc_socket_attach(isc_socket_t *sock0, isc_socket_t **socketp) { isc_socket_attach(isc_socket_t *sock, isc_socket_t **socketp) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(socketp != NULL && *socketp == NULL); REQUIRE(socketp != NULL && *socketp == NULL);
int old_refs = isc_refcount_increment(&sock->references); int old_refs = isc_refcount_increment(&sock->references);
REQUIRE(old_refs > 0); REQUIRE(old_refs > 0);
*socketp = (isc_socket_t *)sock; *socketp = sock;
} }
/* /*
@@ -2618,10 +2607,10 @@ isc_socket_attach(isc_socket_t *sock0, isc_socket_t **socketp) {
*/ */
void void
isc_socket_detach(isc_socket_t **socketp) { isc_socket_detach(isc_socket_t **socketp) {
isc__socket_t *sock; isc_socket_t *sock;
REQUIRE(socketp != NULL); REQUIRE(socketp != NULL);
sock = (isc__socket_t *)*socketp; sock = *socketp;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
if (isc_refcount_decrement(&sock->references) == 1) { if (isc_refcount_decrement(&sock->references) == 1) {
destroy(&sock); destroy(&sock);
@@ -2631,10 +2620,9 @@ isc_socket_detach(isc_socket_t **socketp) {
} }
isc_result_t isc_result_t
isc_socket_close(isc_socket_t *sock0) { isc_socket_close(isc_socket_t *sock) {
isc__socket_t *sock = (isc__socket_t *)sock0;
int fd; int fd;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
isc__socketthread_t *thread; isc__socketthread_t *thread;
fflush(stdout); fflush(stdout);
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
@@ -2682,7 +2670,7 @@ isc_socket_close(isc_socket_t *sock0) {
* Caller must have the socket locked if the event is attached to the socket. * Caller must have the socket locked if the event is attached to the socket.
*/ */
static void static void
send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) { send_recvdone_event(isc_socket_t *sock, isc_socketevent_t **dev) {
isc_task_t *task; isc_task_t *task;
task = (*dev)->ev_sender; task = (*dev)->ev_sender;
@@ -2707,7 +2695,7 @@ send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) {
* Caller must have the socket locked if the event is attached to the socket. * Caller must have the socket locked if the event is attached to the socket.
*/ */
static void static void
send_senddone_event(isc__socket_t *sock, isc_socketevent_t **dev) { send_senddone_event(isc_socket_t *sock, isc_socketevent_t **dev) {
isc_task_t *task; isc_task_t *task;
INSIST(dev != NULL && *dev != NULL); INSIST(dev != NULL && *dev != NULL);
@@ -2733,7 +2721,7 @@ send_senddone_event(isc__socket_t *sock, isc_socketevent_t **dev) {
* Caller must have the socket locked if the event is attached to the socket. * Caller must have the socket locked if the event is attached to the socket.
*/ */
static void static void
send_connectdone_event(isc__socket_t *sock, isc_socket_connev_t **dev) { send_connectdone_event(isc_socket_t *sock, isc_socket_connev_t **dev) {
isc_task_t *task; isc_task_t *task;
INSIST(dev != NULL && *dev != NULL); INSIST(dev != NULL && *dev != NULL);
@@ -2760,8 +2748,8 @@ send_connectdone_event(isc__socket_t *sock, isc_socket_connev_t **dev) {
* so just unlock and return. * so just unlock and return.
*/ */
static void static void
internal_accept(isc__socket_t *sock) { internal_accept(isc_socket_t *sock) {
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
isc__socketthread_t *thread, *nthread; isc__socketthread_t *thread, *nthread;
isc_socket_newconnev_t *dev; isc_socket_newconnev_t *dev;
isc_task_t *task; isc_task_t *task;
@@ -2998,7 +2986,7 @@ internal_accept(isc__socket_t *sock) {
} else { } else {
inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]); inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]);
isc_refcount_decrementz(&NEWCONNSOCK(dev)->references); isc_refcount_decrementz(&NEWCONNSOCK(dev)->references);
free_socket((isc__socket_t **)&dev->newsocket); free_socket((isc_socket_t **)&dev->newsocket);
} }
/* /*
@@ -3020,7 +3008,7 @@ soft_error:
} }
static void static void
internal_recv(isc__socket_t *sock) { internal_recv(isc_socket_t *sock) {
isc_socketevent_t *dev; isc_socketevent_t *dev;
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
@@ -3073,7 +3061,7 @@ finish:
} }
static void static void
internal_send(isc__socket_t *sock) { internal_send(isc_socket_t *sock) {
isc_socketevent_t *dev; isc_socketevent_t *dev;
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
@@ -3117,7 +3105,7 @@ finish:
*/ */
static void static void
process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) { process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) {
isc__socket_t *sock; isc_socket_t *sock;
int lockid = FDLOCK_ID(fd); int lockid = FDLOCK_ID(fd);
/* /*
@@ -3364,7 +3352,7 @@ process_ctlfd(isc__socketthread_t *thread) {
static isc_threadresult_t static isc_threadresult_t
netthread(void *uap) { netthread(void *uap) {
isc__socketthread_t *thread = uap; isc__socketthread_t *thread = uap;
isc__socketmgr_t *manager = thread->manager; isc_socketmgr_t *manager = thread->manager;
(void)manager; (void)manager;
bool done; bool done;
int cc; int cc;
@@ -3522,18 +3510,14 @@ netthread(void *uap) {
} }
void void
isc_socketmgr_setreserved(isc_socketmgr_t *manager0, uint32_t reserved) { isc_socketmgr_setreserved(isc_socketmgr_t *manager, uint32_t reserved) {
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
manager->reserved = reserved; manager->reserved = reserved;
} }
void void
isc_socketmgr_maxudp(isc_socketmgr_t *manager0, unsigned int maxudp) { isc_socketmgr_maxudp(isc_socketmgr_t *manager, unsigned int maxudp) {
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
manager->maxudp = maxudp; manager->maxudp = maxudp;
@@ -3554,9 +3538,9 @@ setup_thread(isc__socketthread_t *thread) {
REQUIRE(thread->threadid >= 0 && REQUIRE(thread->threadid >= 0 &&
thread->threadid < thread->manager->nthreads); thread->threadid < thread->manager->nthreads);
thread->fds = isc_mem_get(thread->manager->mctx, thread->fds =
thread->manager->maxsocks * isc_mem_get(thread->manager->mctx,
sizeof(isc__socket_t *)); thread->manager->maxsocks * sizeof(isc_socket_t *));
memset(thread->fds, 0, memset(thread->fds, 0,
thread->manager->maxsocks * sizeof(isc_socket_t *)); thread->manager->maxsocks * sizeof(isc_socket_t *));
@@ -3756,7 +3740,7 @@ cleanup_thread(isc_mem_t *mctx, isc__socketthread_t *thread) {
thread->manager->maxsocks * sizeof(uint32_t)); thread->manager->maxsocks * sizeof(uint32_t));
#endif /* if defined(USE_EPOLL) */ #endif /* if defined(USE_EPOLL) */
isc_mem_put(thread->manager->mctx, thread->fds, isc_mem_put(thread->manager->mctx, thread->fds,
thread->manager->maxsocks * sizeof(isc__socket_t *)); thread->manager->maxsocks * sizeof(isc_socket_t *));
isc_mem_put(thread->manager->mctx, thread->fdstate, isc_mem_put(thread->manager->mctx, thread->fdstate,
thread->manager->maxsocks * sizeof(int)); thread->manager->maxsocks * sizeof(int));
@@ -3776,7 +3760,7 @@ isc_result_t
isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
unsigned int maxsocks, int nthreads) { unsigned int maxsocks, int nthreads) {
int i; int i;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
REQUIRE(managerp != NULL && *managerp == NULL); REQUIRE(managerp != NULL && *managerp == NULL);
@@ -3794,8 +3778,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
manager->nthreads = nthreads; manager->nthreads = nthreads;
manager->stats = NULL; manager->stats = NULL;
manager->common.magic = ISCAPI_SOCKETMGR_MAGIC; manager->magic = SOCKET_MANAGER_MAGIC;
manager->common.impmagic = SOCKET_MANAGER_MAGIC;
manager->mctx = NULL; manager->mctx = NULL;
ISC_LIST_INIT(manager->socklist); ISC_LIST_INIT(manager->socklist);
isc_mutex_init(&manager->lock); isc_mutex_init(&manager->lock);
@@ -3819,14 +3802,13 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
isc_thread_setname(manager->threads[i].thread, tname); isc_thread_setname(manager->threads[i].thread, tname);
} }
*managerp = (isc_socketmgr_t *)manager; *managerp = manager;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
isc_result_t isc_result_t
isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager0, unsigned int *nsockp) { isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp) {
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
REQUIRE(nsockp != NULL); REQUIRE(nsockp != NULL);
@@ -3836,9 +3818,7 @@ isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager0, unsigned int *nsockp) {
} }
void void
isc_socketmgr_setstats(isc_socketmgr_t *manager0, isc_stats_t *stats) { isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats) {
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
REQUIRE(ISC_LIST_EMPTY(manager->socklist)); REQUIRE(ISC_LIST_EMPTY(manager->socklist));
REQUIRE(manager->stats == NULL); REQUIRE(manager->stats == NULL);
@@ -3849,14 +3829,14 @@ isc_socketmgr_setstats(isc_socketmgr_t *manager0, isc_stats_t *stats) {
void void
isc_socketmgr_destroy(isc_socketmgr_t **managerp) { isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
/* /*
* Destroy a socket manager. * Destroy a socket manager.
*/ */
REQUIRE(managerp != NULL); REQUIRE(managerp != NULL);
manager = (isc__socketmgr_t *)*managerp; manager = *managerp;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
LOCK(&manager->lock); LOCK(&manager->lock);
@@ -3898,15 +3878,14 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
isc_stats_detach(&manager->stats); isc_stats_detach(&manager->stats);
} }
isc_mutex_destroy(&manager->lock); isc_mutex_destroy(&manager->lock);
manager->common.magic = 0; manager->magic = 0;
manager->common.impmagic = 0;
isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager)); isc_mem_putanddetach(&manager->mctx, manager, sizeof(*manager));
*managerp = NULL; *managerp = NULL;
} }
static isc_result_t static isc_result_t
socket_recv(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, socket_recv(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
unsigned int flags) { unsigned int flags) {
int io_state; int io_state;
bool have_lock = false; bool have_lock = false;
@@ -3983,11 +3962,10 @@ socket_recv(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
} }
isc_result_t isc_result_t
isc_socket_recv(isc_socket_t *sock0, isc_region_t *region, unsigned int minimum, isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg) { isc_task_t *task, isc_taskaction_t action, void *arg) {
isc__socket_t *sock = (isc__socket_t *)sock0;
isc_socketevent_t *dev; isc_socketevent_t *dev;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(action != NULL); REQUIRE(action != NULL);
@@ -4003,15 +3981,13 @@ isc_socket_recv(isc_socket_t *sock0, isc_region_t *region, unsigned int minimum,
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
} }
return (isc_socket_recv2(sock0, region, minimum, task, dev, 0)); return (isc_socket_recv2(sock, region, minimum, task, dev, 0));
} }
isc_result_t isc_result_t
isc_socket_recv2(isc_socket_t *sock0, isc_region_t *region, isc_socket_recv2(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
unsigned int minimum, isc_task_t *task, isc_task_t *task, isc_socketevent_t *event,
isc_socketevent_t *event, unsigned int flags) { unsigned int flags) {
isc__socket_t *sock = (isc__socket_t *)sock0;
event->ev_sender = sock; event->ev_sender = sock;
event->result = ISC_R_UNSET; event->result = ISC_R_UNSET;
event->region = *region; event->region = *region;
@@ -4036,7 +4012,7 @@ isc_socket_recv2(isc_socket_t *sock0, isc_region_t *region,
} }
static isc_result_t static isc_result_t
socket_send(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, socket_send(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
unsigned int flags) { unsigned int flags) {
int io_state; int io_state;
@@ -4147,12 +4123,11 @@ isc_socket_send(isc_socket_t *sock, isc_region_t *region, isc_task_t *task,
} }
isc_result_t isc_result_t
isc_socket_sendto(isc_socket_t *sock0, isc_region_t *region, isc_task_t *task, isc_socket_sendto(isc_socket_t *sock, isc_region_t *region, isc_task_t *task,
isc_taskaction_t action, void *arg, isc_taskaction_t action, void *arg,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo) { const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo) {
isc__socket_t *sock = (isc__socket_t *)sock0;
isc_socketevent_t *dev; isc_socketevent_t *dev;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(region != NULL); REQUIRE(region != NULL);
@@ -4176,11 +4151,9 @@ isc_socket_sendto(isc_socket_t *sock0, isc_region_t *region, isc_task_t *task,
} }
isc_result_t isc_result_t
isc_socket_sendto2(isc_socket_t *sock0, isc_region_t *region, isc_task_t *task, isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region, isc_task_t *task,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
isc_socketevent_t *event, unsigned int flags) { isc_socketevent_t *event, unsigned int flags) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE((flags & ~(ISC_SOCKFLAG_IMMEDIATE | ISC_SOCKFLAG_NORETRY)) == REQUIRE((flags & ~(ISC_SOCKFLAG_IMMEDIATE | ISC_SOCKFLAG_NORETRY)) ==
0); 0);
@@ -4373,9 +4346,8 @@ isc_socket_permunix(const isc_sockaddr_t *sockaddr, uint32_t perm,
} }
isc_result_t isc_result_t
isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr, isc_socket_bind(isc_socket_t *sock, const isc_sockaddr_t *sockaddr,
isc_socket_options_t options) { isc_socket_options_t options) {
isc__socket_t *sock = (isc__socket_t *)sock0;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
int on = 1; int on = 1;
@@ -4463,8 +4435,7 @@ bind_socket:
#undef ENABLE_ACCEPTFILTER #undef ENABLE_ACCEPTFILTER
isc_result_t isc_result_t
isc_socket_filter(isc_socket_t *sock0, const char *filter) { isc_socket_filter(isc_socket_t *sock, const char *filter) {
isc__socket_t *sock = (isc__socket_t *)sock0;
#if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) #if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER)
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
struct accept_filter_arg afa; struct accept_filter_arg afa;
@@ -4495,7 +4466,7 @@ isc_socket_filter(isc_socket_t *sock0, const char *filter) {
* Try enabling TCP Fast Open for a given socket if the OS supports it. * Try enabling TCP Fast Open for a given socket if the OS supports it.
*/ */
static void static void
set_tcp_fastopen(isc__socket_t *sock, unsigned int backlog) { set_tcp_fastopen(isc_socket_t *sock, unsigned int backlog) {
#if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) #if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN)
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
@@ -4567,8 +4538,7 @@ set_tcp_fastopen(isc__socket_t *sock, unsigned int backlog) {
* as well keep things simple rather than having to track them. * as well keep things simple rather than having to track them.
*/ */
isc_result_t isc_result_t
isc_socket_listen(isc_socket_t *sock0, unsigned int backlog) { isc_socket_listen(isc_socket_t *sock, unsigned int backlog) {
isc__socket_t *sock = (isc__socket_t *)sock0;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
@@ -4605,13 +4575,12 @@ isc_socket_listen(isc_socket_t *sock0, unsigned int backlog) {
* This should try to do aggressive accept() XXXMLG * This should try to do aggressive accept() XXXMLG
*/ */
isc_result_t isc_result_t
isc_socket_accept(isc_socket_t *sock0, isc_task_t *task, isc_socket_accept(isc_socket_t *sock, isc_task_t *task, isc_taskaction_t action,
isc_taskaction_t action, void *arg) { void *arg) {
isc__socket_t *sock = (isc__socket_t *)sock0;
isc_socket_newconnev_t *dev; isc_socket_newconnev_t *dev;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
isc_task_t *ntask = NULL; isc_task_t *ntask = NULL;
isc__socket_t *nsock; isc_socket_t *nsock;
isc_result_t result; isc_result_t result;
bool do_poke = false; bool do_poke = false;
@@ -4655,7 +4624,7 @@ isc_socket_accept(isc_socket_t *sock0, isc_task_t *task,
nsock->statsindex = sock->statsindex; nsock->statsindex = sock->statsindex;
dev->ev_sender = ntask; dev->ev_sender = ntask;
dev->newsocket = (isc_socket_t *)nsock; dev->newsocket = nsock;
/* /*
* Poke watcher here. We still have the socket locked, so there * Poke watcher here. We still have the socket locked, so there
@@ -4673,12 +4642,11 @@ isc_socket_accept(isc_socket_t *sock0, isc_task_t *task,
} }
isc_result_t isc_result_t
isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr, isc_socket_connect(isc_socket_t *sock, const isc_sockaddr_t *addr,
isc_task_t *task, isc_taskaction_t action, void *arg) { isc_task_t *task, isc_taskaction_t action, void *arg) {
isc__socket_t *sock = (isc__socket_t *)sock0;
isc_socket_connev_t *dev; isc_socket_connev_t *dev;
isc_task_t *ntask = NULL; isc_task_t *ntask = NULL;
isc__socketmgr_t *manager; isc_socketmgr_t *manager;
int cc; int cc;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
char addrbuf[ISC_SOCKADDR_FORMATSIZE]; char addrbuf[ISC_SOCKADDR_FORMATSIZE];
@@ -4836,7 +4804,7 @@ queue:
* Called when a socket with a pending connect() finishes. * Called when a socket with a pending connect() finishes.
*/ */
static void static void
internal_connect(isc__socket_t *sock) { internal_connect(isc_socket_t *sock) {
isc_socket_connev_t *dev; isc_socket_connev_t *dev;
int cc; int cc;
isc_result_t result; isc_result_t result;
@@ -4937,8 +4905,7 @@ finish:
} }
isc_result_t isc_result_t
isc_socket_getpeername(isc_socket_t *sock0, isc_sockaddr_t *addressp) { isc_socket_getpeername(isc_socket_t *sock, isc_sockaddr_t *addressp) {
isc__socket_t *sock = (isc__socket_t *)sock0;
isc_result_t result; isc_result_t result;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
@@ -4959,8 +4926,7 @@ isc_socket_getpeername(isc_socket_t *sock0, isc_sockaddr_t *addressp) {
} }
isc_result_t isc_result_t
isc_socket_getsockname(isc_socket_t *sock0, isc_sockaddr_t *addressp) { isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp) {
isc__socket_t *sock = (isc__socket_t *)sock0;
socklen_t len; socklen_t len;
isc_result_t result; isc_result_t result;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
@@ -4997,9 +4963,7 @@ out:
* queued for task "task" of type "how". "how" is a bitmask. * queued for task "task" of type "how". "how" is a bitmask.
*/ */
void void
isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) { isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
/* /*
@@ -5079,7 +5043,7 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
isc_refcount_decrementz( isc_refcount_decrementz(
&NEWCONNSOCK(dev)->references); &NEWCONNSOCK(dev)->references);
free_socket((isc__socket_t **)&dev->newsocket); free_socket((isc_socket_t **)&dev->newsocket);
dev->result = ISC_R_CANCELED; dev->result = ISC_R_CANCELED;
dev->ev_sender = sock; dev->ev_sender = sock;
@@ -5120,17 +5084,14 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
} }
isc_sockettype_t isc_sockettype_t
isc_socket_gettype(isc_socket_t *sock0) { isc_socket_gettype(isc_socket_t *sock) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
return (sock->type); return (sock->type);
} }
void void
isc_socket_ipv6only(isc_socket_t *sock0, bool yes) { isc_socket_ipv6only(isc_socket_t *sock, bool yes) {
isc__socket_t *sock = (isc__socket_t *)sock0;
#if defined(IPV6_V6ONLY) #if defined(IPV6_V6ONLY)
int onoff = yes ? 1 : 0; int onoff = yes ? 1 : 0;
#else /* if defined(IPV6_V6ONLY) */ #else /* if defined(IPV6_V6ONLY) */
@@ -5158,7 +5119,7 @@ isc_socket_ipv6only(isc_socket_t *sock0, bool yes) {
} }
static void static void
setdscp(isc__socket_t *sock, isc_dscp_t dscp) { setdscp(isc_socket_t *sock, isc_dscp_t dscp) {
#if defined(IP_TOS) || defined(IPV6_TCLASS) #if defined(IP_TOS) || defined(IPV6_TCLASS)
int value = dscp << 2; int value = dscp << 2;
#endif /* if defined(IP_TOS) || defined(IPV6_TCLASS) */ #endif /* if defined(IP_TOS) || defined(IPV6_TCLASS) */
@@ -5195,9 +5156,7 @@ setdscp(isc__socket_t *sock, isc_dscp_t dscp) {
} }
void void
isc_socket_dscp(isc_socket_t *sock0, isc_dscp_t dscp) { isc_socket_dscp(isc_socket_t *sock, isc_dscp_t dscp) {
isc__socket_t *sock = (isc__socket_t *)sock0;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(dscp < 0x40); REQUIRE(dscp < 0x40);
@@ -5228,9 +5187,7 @@ isc_socket_socketevent(isc_mem_t *mctx, void *sender, isc_eventtype_t eventtype,
} }
void void
isc_socket_setname(isc_socket_t *socket0, const char *name, void *tag) { isc_socket_setname(isc_socket_t *sock, const char *name, void *tag) {
isc__socket_t *sock = (isc__socket_t *)socket0;
/* /*
* Name 'sock'. * Name 'sock'.
*/ */
@@ -5244,23 +5201,17 @@ isc_socket_setname(isc_socket_t *socket0, const char *name, void *tag) {
} }
const char * const char *
isc_socket_getname(isc_socket_t *socket0) { isc_socket_getname(isc_socket_t *sock) {
isc__socket_t *sock = (isc__socket_t *)socket0;
return (sock->name); return (sock->name);
} }
void * void *
isc_socket_gettag(isc_socket_t *socket0) { isc_socket_gettag(isc_socket_t *sock) {
isc__socket_t *sock = (isc__socket_t *)socket0;
return (sock->tag); return (sock->tag);
} }
int int
isc_socket_getfd(isc_socket_t *socket0) { isc_socket_getfd(isc_socket_t *sock) {
isc__socket_t *sock = (isc__socket_t *)socket0;
return ((short)sock->fd); return ((short)sock->fd);
} }
@@ -5336,9 +5287,8 @@ _socktype(isc_sockettype_t type) {
goto error; \ goto error; \
} while (0) } while (0)
int int
isc_socketmgr_renderxml(isc_socketmgr_t *mgr0, void *writer0) { isc_socketmgr_renderxml(isc_socketmgr_t *mgr, void *writer0) {
isc__socketmgr_t *mgr = (isc__socketmgr_t *)mgr0; isc_socket_t *sock = NULL;
isc__socket_t *sock = NULL;
char peerbuf[ISC_SOCKADDR_FORMATSIZE]; char peerbuf[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_t addr; isc_sockaddr_t addr;
socklen_t len; socklen_t len;
@@ -5444,10 +5394,9 @@ error:
} while (0) } while (0)
isc_result_t isc_result_t
isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, void *stats0) { isc_socketmgr_renderjson(isc_socketmgr_t *mgr, void *stats0) {
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
isc__socketmgr_t *mgr = (isc__socketmgr_t *)mgr0; isc_socket_t *sock = NULL;
isc__socket_t *sock = NULL;
char peerbuf[ISC_SOCKADDR_FORMATSIZE]; char peerbuf[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_t addr; isc_sockaddr_t addr;
socklen_t len; socklen_t len;