#include <stdlib.h>
#include <isc/app.h>
+#include <isc/atomic.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/file.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/random.h>
+#include <isc/refcount.h>
#include <isc/socket.h>
#include <isc/stdtime.h>
#include <isc/string.h>
static bool failed = false;
static bool c_flag = false;
static isc_mem_t *rndc_mctx;
-static int sends, recvs, connects;
+static isc_refcount_t sends, recvs, connects;
static char *command;
static char *args;
static char program[256];
UNUSED(task);
- sends--;
- if (sevent->result != ISC_R_SUCCESS)
+ if (sevent->result != ISC_R_SUCCESS) {
fatal("send failed: %s", isc_result_totext(sevent->result));
+ }
isc_event_free(&event);
- if (sends == 0 && recvs == 0) {
+ if (isc_refcount_decrement(&sends) == 1 &&
+ isc_refcount_current(&recvs) == 0)
+ {
isc_socket_detach(&sock);
isc_task_shutdown(task);
isc_app_shutdown();
char *textmsg = NULL;
isc_result_t result;
- recvs--;
+ isc_refcount_decrement(&recvs);
if (ccmsg.result == ISC_R_EOF)
fatal("connection to remote host closed\n"
isc_event_free(&event);
isccc_sexpr_free(&response);
- if (sends == 0 && recvs == 0) {
+ if (isc_refcount_current(&sends) == 0
+ && isc_refcount_current(&recvs) == 0) {
isc_socket_detach(&sock);
isc_task_shutdown(task);
isc_app_shutdown();
isccc_sexpr_t *data;
isc_buffer_t b;
- recvs--;
+ isc_refcount_decrement(&recvs);
if (ccmsg.result == ISC_R_EOF)
fatal("connection to remote host closed\n"
isccc_ccmsg_cancelread(&ccmsg);
DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
rndc_recvdone, NULL));
- recvs++;
+ isc_refcount_increment(&recvs);
DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
NULL));
- sends++;
+ isc_refcount_increment(&sends);
isc_event_free(&event);
isccc_sexpr_free(&response);
isc_buffer_t b;
isc_result_t result;
- connects--;
+ isc_refcount_decrement(&connects);
if (sevent->result != ISC_R_SUCCESS) {
isc_sockaddr_format(&serveraddrs[currentaddr], socktext,
DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
rndc_recvnonce, NULL));
- recvs++;
+ isc_refcount_increment(&recvs);
DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
NULL));
- sends++;
+ isc_refcount_increment(&sends);
isc_event_free(&event);
isccc_sexpr_free(&request);
}
}
DO("connect", isc_socket_connect(sock, addr, task, rndc_connected,
NULL));
- connects++;
+ isc_refcount_increment(&connects);
}
static void
if (result != ISC_R_SUCCESS)
fatal("isc_app_run() failed: %s", isc_result_totext(result));
- if (connects > 0 || sends > 0 || recvs > 0)
+ if (isc_refcount_current(&connects) > 0 ||
+ isc_refcount_current(&sends) > 0 ||
+ isc_refcount_current(&recvs) > 0)
+ {
isc_socket_cancel(sock, task, ISC_SOCKCANCEL_ALL);
+ }
isc_task_detach(&task);
isc_taskmgr_destroy(&taskmgr);