Move some definitions and add something private

definitions from asyncqueue to asyncprotocol to reduce dependency loops
add protocol-private data structure and killer routine
This commit is contained in:
Douglas Clowes
2014-08-20 13:34:15 +10:00
parent 3d475d3598
commit 5fa021ce88
3 changed files with 21 additions and 7 deletions

View File

@@ -167,6 +167,11 @@ static void AQ_Purge(pAsyncQueue self)
self->command_head = self->command_tail = NULL;
free(myCmd->tran->out_buf);
free(myCmd->tran->inp_buf);
if (myCmd->tran->proto_private)
if (myCmd->tran->kill_private)
myCmd->tran->kill_private(myCmd->tran);
else
free(myCmd->tran->proto_private);
free(myCmd->tran);
free(myCmd);
myCmd = self->command_head;
@@ -455,6 +460,11 @@ static int PopCommand(pAsyncQueue self)
self->command_head = self->command_tail = NULL;
free(myCmd->tran->out_buf);
free(myCmd->tran->inp_buf);
if (myCmd->tran->proto_private)
if (myCmd->tran->kill_private)
myCmd->tran->kill_private(myCmd->tran);
else
free(myCmd->tran->proto_private);
free(myCmd->tran);
free(myCmd);
return 1;
@@ -531,7 +541,7 @@ static int MyCallback(void *context, int mode)
for (i = 0; i < nchars; ++i) {
iRet =
self->protocol->handleInput(self->protocol, myCmd->tran,
reply[i]);
reply[i] & 0xFF);
if (iRet == 0 || iRet == AQU_POP_CMD) { /* end of command */
if (self->trace) {
struct timeval tv;
@@ -666,6 +676,7 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
}
if (unit->queue->protocol->prepareTxn) {
int iRet;
myTxn->inp_len = rsp_len; /* allowing protocol to change it */
iRet =
unit->queue->protocol->prepareTxn(unit->queue->protocol, myTxn,
command, cmd_len, rsp_len);
@@ -673,6 +684,7 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
free(myTxn);
return NULL;
}
rsp_len = myTxn->inp_len; /* allowed protocol to change it */
} else {
myTxn->out_buf = (char *) malloc(cmd_len + 5);
if (myTxn->out_buf == NULL) {