Add trace and list commands to AsyncQueue
This commit is contained in:
66
asyncqueue.c
66
asyncqueue.c
@ -56,6 +56,7 @@ struct __AsyncQueue {
|
||||
int retries;
|
||||
int retryTimer; /* mSec delay before next retry */
|
||||
bool translate; /* translate binary output with escaped chars */
|
||||
bool trace;
|
||||
struct timeval tvLastCmd; /* time of completion of last command */
|
||||
int unit_count; /* number of units connected */
|
||||
pAsyncUnit units; /* head of unit chain */
|
||||
@ -519,10 +520,30 @@ static int MyCallback(void *context, int mode)
|
||||
self->protocol->handleInput(self->protocol, myCmd->tran,
|
||||
reply[i]);
|
||||
if (iRet == 0 || iRet == AQU_POP_CMD) { /* end of command */
|
||||
if (self->trace) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
SICSLogTimePrintf(eLog, &tv,
|
||||
"Input Trace on AsyncQueue %s", self->queue_name);
|
||||
SICSLogWriteHexTime(myCmd->tran->inp_buf, myCmd->tran->inp_idx, eLog, &tv);
|
||||
}
|
||||
PopCommand(self);
|
||||
break;
|
||||
} else if (iRet < 0) {
|
||||
SICSLogWrite("ERROR: Protocol error in AsyncQueue", eError);
|
||||
int excess = nchars - 1 - i;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
SICSLogTimePrintf(eError, &tv,
|
||||
"ERROR: Protocol error %d in AsyncQueue %s",
|
||||
iRet, self->queue_name);
|
||||
SICSLogWriteTime("Sent:", eError, &tv);
|
||||
SICSLogWriteHexTime(myCmd->tran->out_buf, myCmd->tran->out_len, eError, &tv);
|
||||
SICSLogWriteTime("Received:", eError, &tv);
|
||||
SICSLogWriteHexTime(myCmd->tran->inp_buf, myCmd->tran->inp_idx, eError, &tv);
|
||||
SICSLogWriteTime("Processed:", eError, &tv);
|
||||
SICSLogWriteHexTime(&reply[0], i, eError, &tv);
|
||||
SICSLogWriteTime("Unprocessed:", eError, &tv);
|
||||
SICSLogWriteHexTime(&reply[i], excess, eError, &tv);
|
||||
/* TODO: error */
|
||||
break;
|
||||
}
|
||||
@ -725,6 +746,13 @@ int AsyncUnitWrite(pAsyncUnit unit, void *buffer, int buflen)
|
||||
assert(unit);
|
||||
assert(unit->queue);
|
||||
if (buflen > 0) {
|
||||
if (unit->queue->trace) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
SICSLogTimePrintf(eLog, &tv,
|
||||
"Output Trace on AsyncQueue %s", unit->queue->queue_name);
|
||||
SICSLogWriteHexTime(buffer, buflen, eLog, &tv);
|
||||
}
|
||||
sock = AsyncUnitGetSocket(unit);
|
||||
iRet = NETWrite(sock, buffer, buflen);
|
||||
/* TODO handle errors */
|
||||
@ -991,6 +1019,42 @@ int AsyncQueueAction(SConnection * pCon, SicsInterp * pSics,
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
if (strcasecmp(argv[1], "trace") == 0) {
|
||||
if (argc > 2) {
|
||||
int value;
|
||||
int iRet;
|
||||
iRet = sscanf(argv[2], "%d", &value);
|
||||
if (iRet != 1) {
|
||||
snprintf(line, 132, "Invalid argument: %s", argv[2]);
|
||||
SCWrite(pCon, line, eError);
|
||||
return 0;
|
||||
} else {
|
||||
if (value == 0) {
|
||||
self->trace = false;
|
||||
return OKOK;
|
||||
} else if (value == 1) {
|
||||
self->trace = true;
|
||||
return OKOK;
|
||||
}
|
||||
snprintf(line, 132, "Invalid argument: %s", argv[2]);
|
||||
SCWrite(pCon, line, eError);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(line, 132, "%s.trace = %d", argv[0], self->trace);
|
||||
SCWrite(pCon, line, eStatus);
|
||||
return OKOK;
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
if (strcasecmp(argv[1], "list") == 0) {
|
||||
SCPrintf(pCon, eValue, "%s.delay = %d", argv[0], self->iDelay);
|
||||
SCPrintf(pCon, eValue, "%s.timeout = %d", argv[0], self->timeout);
|
||||
SCPrintf(pCon, eValue, "%s.retries = %d", argv[0], self->retries);
|
||||
SCPrintf(pCon, eValue, "%s.translate = %d", argv[0], self->translate);
|
||||
SCPrintf(pCon, eValue, "%s.trace = %d", argv[0], self->trace);
|
||||
return OKOK;
|
||||
}
|
||||
}
|
||||
snprintf(line, 132, "%s does not understand %s", argv[0], argv[1]);
|
||||
SCWrite(pCon, line, eError);
|
||||
|
Reference in New Issue
Block a user