Copy the protocol name and adjust the kill code in asyncprotocol

This commit is contained in:
Douglas Clowes
2014-08-22 17:10:31 +10:00
parent 47d3d0a7e8
commit 3ff6377f85
2 changed files with 16 additions and 9 deletions

View File

@ -286,7 +286,6 @@ int AsyncProtocolAction(SConnection * pCon, SicsInterp * pSics,
void defaultKillPrivate(pAsyncProtocol p) void defaultKillPrivate(pAsyncProtocol p)
{ {
if (p->privateData) { if (p->privateData) {
/* TODO: should we do anything? */
free(p->privateData); free(p->privateData);
} }
} }
@ -295,15 +294,22 @@ void AsyncProtocolKill(void *pData)
{ {
pAsyncProtocol self = (pAsyncProtocol) pData; pAsyncProtocol self = (pAsyncProtocol) pData;
int i; int i;
if (self->pDes)
DeleteDescriptor(self->pDes);
if (self->sendTerminator != NULL)
free(self->sendTerminator);
for (i = 0; i < 10; ++i)
if (self->replyTerminator[i] != NULL)
free(self->replyTerminator[i]);
if (self->killPrivate) if (self->killPrivate)
self->killPrivate(self); self->killPrivate(self);
if (self->pDes)
DeleteDescriptor(self->pDes);
self->pDes = NULL;
if (self->protocolName)
free(self->protocolName);
self->protocolName = NULL;
if (self->sendTerminator != NULL)
free(self->sendTerminator);
self->sendTerminator = NULL;
for (i = 0; i < 10; ++i) {
if (self->replyTerminator[i] != NULL)
free(self->replyTerminator[i]);
self->replyTerminator[i] = NULL;
}
} }
pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics, pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics,
@ -338,6 +344,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics,
AsyncProtocolKill(self); AsyncProtocolKill(self);
return NULL; return NULL;
} }
self->protocolName = strdup(protocolName);
self->sendCommand = defaultSendCommand; self->sendCommand = defaultSendCommand;
self->handleInput = defaultHandleInput; self->handleInput = defaultHandleInput;
self->handleEvent = defaultHandleEvent; self->handleEvent = defaultHandleEvent;

View File

@ -45,7 +45,7 @@ struct __async_txn {
int inp_idx; /**< index of next character (number already received) */ int inp_idx; /**< index of next character (number already received) */
AsyncTxnHandler handleResponse; /**< Txn response handler of command sender */ AsyncTxnHandler handleResponse; /**< Txn response handler of command sender */
void *proto_private; /**< Protocol Private structure */ void *proto_private; /**< Protocol Private structure */
void (*kill_private) (struct __async_txn *pTxn); /**< if it needs killing */ void (*kill_private) (pAsyncTxn pTxn); /**< if it needs killing */
void *cntx; /**< opaque context used by command sender */ void *cntx; /**< opaque context used by command sender */
/* The cntx field may be used by protocol handler from sendCommand /* The cntx field may be used by protocol handler from sendCommand
* as long as it is restored when response is complete * as long as it is restored when response is complete