static isc_result_t
open_socket(isc_socketmgr_t *mgr, const isc_sockaddr_t *local,
unsigned int options, isc_socket_t **sockp);
+static isc_socket_t *
+getentrysocket(dns_dispentry_t *resp);
+static isc_socket_t *
+getsocket(dns_dispatch_t *disp);
#define LVL(x) ISC_LOG_DEBUG(x)
ISC_EVENT_INIT(sendevent, sizeof(isc_socketevent_t), 0, NULL,
ISC_SOCKEVENT_SENDDONE, action, arg, NULL, NULL, NULL);
- sock = dns_dispatch_getentrysocket(resp);
+ sock = getentrysocket(resp);
if (dscp == -1) {
sendevent->attributes &= ~ISC_SOCKEVENTATTR_DSCP;
return (result);
}
+void
+dns_dispatch_cancel(dns_dispatch_t *disp, dns_dispentry_t *resp, bool sending,
+ bool connecting) {
+ isc_socket_t *sock = NULL;
+
+ REQUIRE(disp != NULL || resp != NULL);
+
+ if (resp != NULL) {
+ REQUIRE(VALID_RESPONSE(resp));
+ sock = getentrysocket(resp);
+ } else if (disp != NULL) {
+ REQUIRE(VALID_DISPATCH(disp));
+ sock = getsocket(disp);
+ } else {
+ INSIST(0);
+ ISC_UNREACHABLE();
+ }
+
+ if (sock == NULL) {
+ return;
+ }
+
+ if (connecting) {
+ isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
+ }
+
+ if (sending) {
+ isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
+ }
+}
+
/*
* disp must be locked.
*/
UNLOCK(&qid->lock);
}
-isc_socket_t *
-dns_dispatch_getsocket(dns_dispatch_t *disp) {
+static isc_socket_t *
+getsocket(dns_dispatch_t *disp) {
REQUIRE(VALID_DISPATCH(disp));
return (disp->socket);
}
-isc_socket_t *
-dns_dispatch_getentrysocket(dns_dispentry_t *resp) {
+static isc_socket_t *
+getentrysocket(dns_dispentry_t *resp) {
REQUIRE(VALID_RESPONSE(resp));
if (resp->disp->socktype == isc_sockettype_tcp) {
*\li 'disp' is NULL and 'resp' is valid.
*/
+void
+dns_dispatch_cancel(dns_dispatch_t *disp, dns_dispentry_t *resp, bool sending,
+ bool connecting);
+/*%<
+ * Cancel pending sends (if 'sending' is true) and connects (if
+ * 'connecting' is true) in 'resp' or 'disp'.
+ *
+ * Requires:
+ *\li 'resp' is NULL and 'disp' is valid, or
+ *\li 'disp' is NULL and 'resp' is valid.
+ */
+
isc_result_t
dns_dispatch_send(dns_dispentry_t *resp, bool tcp, isc_task_t *task,
isc_socketevent_t *sendevent, isc_region_t *r,
* argument to dns_dispatch_addresponse() when allocating '*resp'.
*/
-isc_socket_t *
-dns_dispatch_getentrysocket(dns_dispentry_t *resp);
-
-isc_socket_t *
-dns_dispatch_getsocket(dns_dispatch_t *disp);
-/*%<
- * Return the socket associated with dispatcher or dispatch entry.
- *
- * Requires:
- *\li disp is valid.
- *
- * Returns:
- *\li The socket the dispatcher is using.
- */
-
isc_result_t
dns_dispatch_getlocaladdress(dns_dispatch_t *disp, isc_sockaddr_t *addrp);
/*%<
dns_request_t **requestp) {
dns_request_t *request = NULL;
isc_task_t *tclone = NULL;
- isc_socket_t *sock = NULL;
isc_result_t result;
isc_mem_t *mctx;
dns_messageid_t id;
goto cleanup;
}
- sock = dns_dispatch_getentrysocket(request->dispentry);
- INSIST(sock != NULL);
-
isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0));
if (tcp) {
isc_buffer_putuint16(request->query, (uint16_t)r.length);
dns_request_t **requestp) {
dns_request_t *request = NULL;
isc_task_t *tclone = NULL;
- isc_socket_t *sock = NULL;
isc_result_t result;
isc_mem_t *mctx;
dns_messageid_t id;
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
- sock = dns_dispatch_getentrysocket(request->dispentry);
- INSIST(sock != NULL);
message->id = id;
if (settsigkey) {
dns_message_renderreset(message);
dns_dispatch_removeresponse(&request->dispentry, NULL);
dns_dispatch_detach(&request->dispatch);
- sock = NULL;
options |= DNS_REQUESTOPT_TCP;
settsigkey = false;
goto use_tcp;
*/
static void
req_cancel(dns_request_t *request) {
- isc_socket_t *sock = NULL;
-
REQUIRE(VALID_REQUEST(request));
req_log(ISC_LOG_DEBUG(3), "req_cancel: request %p", request);
isc_timer_detach(&request->timer);
}
- if (DNS_REQUEST_CONNECTING(request) || DNS_REQUEST_SENDING(request)) {
- if (request->dispentry != NULL) {
- sock = dns_dispatch_getentrysocket(request->dispentry);
- }
- if (DNS_REQUEST_CONNECTING(request) && sock != NULL) {
- isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
- }
- if (DNS_REQUEST_SENDING(request) && sock != NULL) {
- isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
- }
- }
if (request->dispentry != NULL) {
+ dns_dispatch_cancel(NULL, request->dispentry,
+ DNS_REQUEST_SENDING(request),
+ DNS_REQUEST_CONNECTING(request));
dns_dispatch_removeresponse(&request->dispentry, NULL);
}
dns_dispatch_detach(&request->dispatch);
#include <isc/random.h>
#include <isc/refcount.h>
#include <isc/siphash.h>
-#include <isc/socket.h>
#include <isc/stats.h>
#include <isc/string.h>
#include <isc/task.h>
unsigned int rtt, rttms;
unsigned int factor;
dns_adbfind_t *find = NULL;
- isc_socket_t *sock = NULL;
dns_adbaddrinfo_t *addrinfo;
isc_stdtime_t now;
/*
* Check for any outstanding socket events. If they exist, cancel
- * them and let the event handlers finish the cleanup. The resolver
- * only needs to worry about managing the connect and send events;
- * the dispatcher manages the recv events.
- */
- if (query->dispentry != NULL) {
- sock = dns_dispatch_getentrysocket(query->dispentry);
- } else {
- sock = dns_dispatch_getsocket(query->dispatch);
- }
-
- /* Cancel the connect. */
- if (sock != NULL && RESQUERY_CONNECTING(query)) {
- isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
- }
-
- /* Cancel the pending send. */
- if (sock != NULL && RESQUERY_SENDING(query)) {
- isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
- }
-
+ * them and let the event handlers finish the cleanup. (XXX:
+ * Currently the resolver, rather than dispatch, tracks whether
+ * it's sending or connecting; this will be moved into dispatch
+ * later.)
+ */
+ dns_dispatch_cancel(query->dispatch, query->dispentry,
+ RESQUERY_SENDING(query),
+ RESQUERY_CONNECTING(query));
if (query->dispentry != NULL) {
dns_dispatch_removeresponse(&query->dispentry, deventp);
}