2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 21:17:54 +00:00

hack on socket code more, trying to track down a bug

This commit is contained in:
Michael Graff 1999-07-28 23:04:33 +00:00
parent d524cd03ec
commit 11e2a221f1
3 changed files with 70 additions and 38 deletions

View File

@ -421,10 +421,13 @@ main(int argc, char *argv[])
isc_app_run(); isc_app_run();
fprintf(stderr, "canceling dispatcher\n");
dns_dispatch_cancel(disp); dns_dispatch_cancel(disp);
fprintf(stderr, "detaching from socket\n");
isc_socket_detach(&s0); isc_socket_detach(&s0);
fprintf(stderr, "detaching from dispatcher\n");
dns_dispatch_detach(&disp); dns_dispatch_detach(&disp);
fprintf(stderr, "Destroying socket manager\n"); fprintf(stderr, "Destroying socket manager\n");

View File

@ -243,6 +243,8 @@ destroy(dns_dispatch_t *disp)
dns_tcpmsg_invalidate(&disp->tcpmsg); dns_tcpmsg_invalidate(&disp->tcpmsg);
XDEBUG(("dispatch::destroy: detaching from sock %p and task %p\n",
disp->socket, disp->task));
isc_socket_detach(&disp->socket); isc_socket_detach(&disp->socket);
isc_task_detach(&disp->task); isc_task_detach(&disp->task);
@ -918,8 +920,11 @@ dns_dispatch_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task,
disp->task = NULL; disp->task = NULL;
isc_task_attach(task, &disp->task); isc_task_attach(task, &disp->task);
XDEBUG(("dns_dispatch_create: attaching to task %p\n", disp->task));
disp->socket = NULL; disp->socket = NULL;
isc_socket_attach(sock, &disp->socket); isc_socket_attach(sock, &disp->socket);
XDEBUG(("dns_dispatch_create: attaching to socket %p\n",
disp->socket));
dns_tcpmsg_init(disp->mctx, disp->socket, &disp->tcpmsg); dns_tcpmsg_init(disp->mctx, disp->socket, &disp->tcpmsg);
@ -1049,6 +1054,8 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, isc_sockaddr_t *dest,
disp->requests++; disp->requests++;
res->task = NULL; res->task = NULL;
isc_task_attach(task, &res->task); isc_task_attach(task, &res->task);
XDEBUG(("dns_dispatch_addresponse: attaching to task %p\n",
res->task));
res->magic = RESPONSE_MAGIC; res->magic = RESPONSE_MAGIC;
res->id = id; res->id = id;
@ -1117,6 +1124,8 @@ dns_dispatch_removeresponse(dns_dispatch_t *disp, dns_dispentry_t **resp,
ISC_LIST_UNLINK(disp->qid_table[bucket], res, link); ISC_LIST_UNLINK(disp->qid_table[bucket], res, link);
XDEBUG(("dns_dispatch_removeresponse: detaching from task %p\n",
res->task));
isc_task_detach(&res->task); isc_task_detach(&res->task);
if (ev != NULL) { if (ev != NULL) {
@ -1183,6 +1192,8 @@ dns_dispatch_addrequest(dns_dispatch_t *disp,
disp->requests++; disp->requests++;
res->task = NULL; res->task = NULL;
isc_task_attach(task, &res->task); isc_task_attach(task, &res->task);
XDEBUG(("dns_dispatch_addrequest: attaching to task %p\n",
res->task));
res->magic = REQUEST_MAGIC; res->magic = REQUEST_MAGIC;
res->bucket = INVALID_BUCKET; res->bucket = INVALID_BUCKET;
@ -1250,6 +1261,7 @@ dns_dispatch_removerequest(dns_dispatch_t *disp, dns_dispentry_t **resp,
ISC_LIST_UNLINK(disp->rq_handlers, res, link); ISC_LIST_UNLINK(disp->rq_handlers, res, link);
XDEBUG(("dns_dispatch_removerequest: detaching from task %p\n", res->task));
isc_task_detach(&res->task); isc_task_detach(&res->task);
if (ev != NULL) { if (ev != NULL) {

View File

@ -87,7 +87,7 @@
#define TRACE_SEND 0x0010 #define TRACE_SEND 0x0010
#define TRACE_MANAGER 0x0020 #define TRACE_MANAGER 0x0020
int trace_level = TRACE_WATCHER | TRACE_MANAGER | TRACE_RECV; int trace_level = 0xffff;
#define XTRACE(l, a) do { \ #define XTRACE(l, a) do { \
if ((l) & trace_level) { \ if ((l) & trace_level) { \
printf a; \ printf a; \
@ -385,15 +385,15 @@ free_socket(isc_socket_t **socketp)
{ {
isc_socket_t *sock = *socketp; isc_socket_t *sock = *socketp;
REQUIRE(sock->references == 0); INSIST(sock->references == 0);
REQUIRE(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
REQUIRE(!sock->connecting); INSIST(!sock->connecting);
REQUIRE(!sock->pending_recv); INSIST(!sock->pending_recv);
REQUIRE(!sock->pending_send); INSIST(!sock->pending_send);
REQUIRE(!sock->pending_accept); INSIST(!sock->pending_accept);
REQUIRE(EMPTY(sock->recv_list)); INSIST(EMPTY(sock->recv_list));
REQUIRE(EMPTY(sock->send_list)); INSIST(EMPTY(sock->send_list));
REQUIRE(EMPTY(sock->accept_list)); INSIST(EMPTY(sock->accept_list));
sock->magic = 0; sock->magic = 0;
@ -622,7 +622,7 @@ dispatch_connect(isc_socket_t *sock)
ev = sock->connect_ev; ev = sock->connect_ev;
INSIST(ev != NULL); INSIST(ev != NULL);
REQUIRE(sock->connecting); INSIST(sock->connecting);
sock->references++; /* keep socket around for this internal event */ sock->references++; /* keep socket around for this internal event */
iev->sender = sock; iev->sender = sock;
@ -702,14 +702,14 @@ internal_accept(isc_task_t *me, isc_event_t *ev)
(void)me; (void)me;
sock = ev->sender; sock = ev->sender;
REQUIRE(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock); LOCK(&sock->lock);
XTRACE(TRACE_LISTEN, XTRACE(TRACE_LISTEN,
("internal_accept called, locked parent sock %p\n", sock)); ("internal_accept called, locked parent sock %p\n", sock));
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); INSIST(VALID_MANAGER(manager));
INSIST(sock->listener); INSIST(sock->listener);
INSIST(sock->pending_accept == 1); INSIST(sock->pending_accept == 1);
@ -816,11 +816,10 @@ internal_accept(isc_task_t *me, isc_event_t *ev)
* Fill in the done event details and send it off. * Fill in the done event details and send it off.
*/ */
dev->result = result; dev->result = result;
task = (isc_task_t *)(dev->sender); task = dev->sender;
dev->sender = sock; dev->sender = sock;
ISC_TASK_SEND(task, (isc_event_t **)&dev); ISC_TASK_SENDANDDETACH(&task, (isc_event_t **)&dev);
isc_task_detach(&task);
} }
static void static void
@ -838,7 +837,7 @@ internal_recv(isc_task_t *me, isc_event_t *ev)
INSIST(ev->type == ISC_SOCKEVENT_INTR); INSIST(ev->type == ISC_SOCKEVENT_INTR);
sock = ev->sender; sock = ev->sender;
REQUIRE(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock); LOCK(&sock->lock);
XTRACE(TRACE_SEND, XTRACE(TRACE_SEND,
@ -967,7 +966,7 @@ internal_recv(isc_task_t *me, isc_event_t *ev)
* was read with a success result, and continue * was read with a success result, and continue
* the loop. * the loop.
*/ */
if (dev->minimum >= dev->n) { if (dev->minimum <= dev->n) {
send_recvdone_event(sock, &task, &dev, send_recvdone_event(sock, &task, &dev,
ISC_R_SUCCESS, 1); ISC_R_SUCCESS, 1);
goto next; goto next;
@ -1018,7 +1017,7 @@ internal_send(isc_task_t *me, isc_event_t *ev)
* Find out what socket this is and lock it. * Find out what socket this is and lock it.
*/ */
sock = (isc_socket_t *)ev->sender; sock = (isc_socket_t *)ev->sender;
REQUIRE(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock); LOCK(&sock->lock);
XTRACE(TRACE_SEND, XTRACE(TRACE_SEND,
@ -1558,9 +1557,13 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
isc_boolean_t was_empty; isc_boolean_t was_empty;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(region != NULL);
REQUIRE(region->length >= minimum);
REQUIRE(task != NULL);
REQUIRE(action != NULL);
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
REQUIRE(region->length >= minimum);
LOCK(&sock->lock); LOCK(&sock->lock);
@ -1705,7 +1708,7 @@ isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
XTRACE(TRACE_RECV, XTRACE(TRACE_RECV,
("isc_socket_recv: posted event %p, task %p\n", dev, task)); ("isc_socket_recv: queued event %p, task %p\n", dev, ntask));
out: out:
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@ -1716,6 +1719,9 @@ isc_result_t
isc_socket_send(isc_socket_t *sock, isc_region_t *region, isc_socket_send(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg) isc_task_t *task, isc_taskaction_t action, void *arg)
{ {
/*
* REQUIRE() checking performed in isc_socket_sendto()
*/
return (isc_socket_sendto(sock, region, task, action, arg, NULL)); return (isc_socket_sendto(sock, region, task, action, arg, NULL));
} }
@ -1731,6 +1737,10 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
isc_boolean_t was_empty; isc_boolean_t was_empty;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(region != NULL);
REQUIRE(task != NULL);
REQUIRE(action != NULL);
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@ -1861,7 +1871,7 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
XTRACE(TRACE_SEND, XTRACE(TRACE_SEND,
("isc_socket_send: posted event %p, task %p\n", dev, task)); ("isc_socket_send: queued event %p, task %p\n", dev, ntask));
out: out:
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@ -2027,7 +2037,12 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr,
int cc; int cc;
XENTER(TRACE_CONNECT, "isc_socket_connect"); XENTER(TRACE_CONNECT, "isc_socket_connect");
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(addr != NULL);
REQUIRE(task != NULL);
REQUIRE(action != NULL);
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
REQUIRE(addr != NULL); REQUIRE(addr != NULL);
@ -2036,11 +2051,9 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr,
REQUIRE(!sock->connecting); REQUIRE(!sock->connecting);
dev = (isc_socket_connev_t *)isc_event_allocate(manager->mctx, dev = (isc_socket_connev_t *)isc_event_allocate(manager->mctx, sock,
sock,
ISC_SOCKEVENT_CONNECT, ISC_SOCKEVENT_CONNECT,
action, action, arg,
arg,
sizeof (*dev)); sizeof (*dev));
if (dev == NULL) { if (dev == NULL) {
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@ -2134,9 +2147,10 @@ internal_connect(isc_task_t *me, isc_event_t *ev)
ISC_SOCKADDR_LEN_T optlen; ISC_SOCKADDR_LEN_T optlen;
(void)me; (void)me;
INSIST(ev->type = ISC_SOCKEVENT_INTW);
sock = ev->sender; sock = ev->sender;
REQUIRE(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock); LOCK(&sock->lock);
XTRACE(TRACE_CONNECT, XTRACE(TRACE_CONNECT,
@ -2216,10 +2230,9 @@ internal_connect(isc_task_t *me, isc_event_t *ev)
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
task = (isc_task_t *)(dev->sender); task = dev->sender;
dev->sender = sock; dev->sender = sock;
ISC_TASK_SEND(task, (isc_event_t **)&dev); ISC_TASK_SENDANDDETACH(&task, (isc_event_t **)&dev);
isc_task_detach(&task);
} }
isc_result_t isc_result_t
@ -2265,8 +2278,7 @@ isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp)
* 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 *sock, isc_task_t *task, isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how)
unsigned int how)
{ {
isc_boolean_t poke_needed; isc_boolean_t poke_needed;
@ -2351,9 +2363,8 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task,
dev->result = ISC_R_CANCELED; dev->result = ISC_R_CANCELED;
dev->sender = sock; dev->sender = sock;
ISC_TASK_SEND(current_task, ISC_TASK_SENDANDDETACH(&current_task,
(isc_event_t **)&dev); (isc_event_t **)&dev);
isc_task_detach(&current_task);
} }
dev = next; dev = next;
@ -2369,15 +2380,15 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task,
isc_task_t *current_task; isc_task_t *current_task;
dev = sock->connect_ev; dev = sock->connect_ev;
current_task = (isc_task_t *)dev->sender; current_task = dev->sender;
if ((task == NULL) || (task == current_task)) { if ((task == NULL) || (task == current_task)) {
sock->connect_ev = NULL; sock->connect_ev = NULL;
dev->result = ISC_R_CANCELED; dev->result = ISC_R_CANCELED;
dev->sender = sock; dev->sender = sock;
ISC_TASK_SEND(current_task, (isc_event_t **)&dev); ISC_TASK_SENDANDDETACH(&current_task,
isc_task_detach(&current_task); (isc_event_t **)&dev);
} }
} }
@ -2398,6 +2409,9 @@ isc_socket_recvmark(isc_socket_t *sock,
isc_task_t *ntask = NULL; isc_task_t *ntask = NULL;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(task != NULL);
REQUIRE(action != NULL);
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@ -2455,6 +2469,9 @@ isc_socket_sendmark(isc_socket_t *sock,
isc_task_t *ntask = NULL; isc_task_t *ntask = NULL;
REQUIRE(VALID_SOCKET(sock)); REQUIRE(VALID_SOCKET(sock));
REQUIRE(task != NULL);
REQUIRE(action != NULL);
manager = sock->manager; manager = sock->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));