implement some TODOs, add malloc checks and logging
r1984 | dcl | 2007-05-25 16:12:10 +1000 (Fri, 25 May 2007) | 2 lines
This commit is contained in:
44
asyncqueue.c
44
asyncqueue.c
@@ -181,7 +181,7 @@ static int StartCommand(pAsyncQueue self)
|
||||
char reply[1];
|
||||
int iRet;
|
||||
iRet = NETRead(sock, reply, 1, 0);
|
||||
if (iRet < 0) { /* TODO: EOF */
|
||||
if (iRet < 0) { /* EOF */
|
||||
iRet = AQ_Reconnect(self);
|
||||
if (iRet == 0)
|
||||
return 0;
|
||||
@@ -306,7 +306,7 @@ static int MyCallback(void* context, int mode)
|
||||
char reply[1];
|
||||
|
||||
iRet = NETRead(self->pSock, reply, 1, 0);
|
||||
if (iRet < 0) { /* TODO: EOF */
|
||||
if (iRet < 0) { /* EOF */
|
||||
iRet = AQ_Reconnect(self);
|
||||
if (iRet <= 0)
|
||||
return iRet;
|
||||
@@ -342,7 +342,10 @@ int AsyncUnitEnqueHead(pAsyncUnit unit, pAsyncTxn context)
|
||||
|
||||
assert(unit && unit->queue && unit->queue->protocol);
|
||||
myCmd = (pAQ_Cmd) malloc(sizeof(AQ_Cmd));
|
||||
/* TODO: check malloc */
|
||||
if (myCmd == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitEnqueHead", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(myCmd, 0, sizeof(AQ_Cmd));
|
||||
myCmd->tran = context;
|
||||
myCmd->unit = unit;
|
||||
@@ -358,7 +361,10 @@ int AsyncUnitEnqueueTxn(pAsyncUnit unit, pAsyncTxn pTxn)
|
||||
|
||||
assert(unit && unit->queue && unit->queue->protocol);
|
||||
myCmd = (pAQ_Cmd) malloc(sizeof(AQ_Cmd));
|
||||
/* TODO: check malloc */
|
||||
if (myCmd == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitEnqueueTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(myCmd, 0, sizeof(AQ_Cmd));
|
||||
myCmd->tran = pTxn;
|
||||
myCmd->unit = unit;
|
||||
@@ -377,7 +383,10 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
|
||||
|
||||
assert(unit);
|
||||
myTxn = (pAsyncTxn) malloc(sizeof(AsyncTxn));
|
||||
assert(myTxn);
|
||||
if (myTxn == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(myTxn, 0, sizeof(AsyncTxn));
|
||||
if (unit->queue->protocol->prepareTxn) {
|
||||
int iRet;
|
||||
@@ -385,6 +394,11 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
|
||||
}
|
||||
else {
|
||||
myTxn->out_buf = (char*) malloc(cmd_len + 5);
|
||||
if (myTxn->out_buf == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError);
|
||||
free(myTxn);
|
||||
return 0;
|
||||
}
|
||||
memcpy(myTxn->out_buf, command, cmd_len);
|
||||
myTxn->out_len = cmd_len;
|
||||
if (myTxn->out_len < 2 ||
|
||||
@@ -399,6 +413,12 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit,
|
||||
myTxn->inp_buf = NULL;
|
||||
else {
|
||||
myTxn->inp_buf = malloc(rsp_len + 1);
|
||||
if (myTxn->inp_buf == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError);
|
||||
free(myTxn->out_buf);
|
||||
free(myTxn);
|
||||
return 0;
|
||||
}
|
||||
memset(myTxn->inp_buf, 0, rsp_len + 1);
|
||||
}
|
||||
myTxn->inp_len = rsp_len;
|
||||
@@ -477,7 +497,7 @@ int AsyncUnitWrite(pAsyncUnit unit, void* buffer, int buflen)
|
||||
sock = AsyncUnitGetSocket(unit);
|
||||
iRet = NETWrite(sock, buffer, buflen);
|
||||
/* TODO handle errors */
|
||||
if (iRet < 0) { /* TODO: EOF */
|
||||
if (iRet < 0) { /* EOF */
|
||||
iRet = AQ_Reconnect(unit->queue);
|
||||
if (iRet == 0)
|
||||
return 0;
|
||||
@@ -708,7 +728,7 @@ static pAsyncQueue AQ_Create(const char* host, const char* port)
|
||||
}
|
||||
if (self == NULL) {
|
||||
channel = NETConnectWithFlags(host, port_no, 0);
|
||||
/* TODO */
|
||||
/* TODO handle asynchronous connection */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,7 +758,7 @@ static pAsyncQueue AQ_Create(const char* host, const char* port)
|
||||
|
||||
static int AQ_Init(pAsyncQueue self)
|
||||
{
|
||||
/* TODO: Init the controller */
|
||||
/* Init the controller */
|
||||
if (self->nw_ctx == NULL)
|
||||
NetWatchRegisterCallback(&self->nw_ctx,
|
||||
self->pSock->sockid,
|
||||
@@ -830,7 +850,7 @@ int AsyncQueueFactory(SConnection *pCon, SicsInterp *pSics,
|
||||
SCWrite(pCon, line, eError);
|
||||
}
|
||||
}
|
||||
/* TODO: asynchronous connection */
|
||||
/* TODO: implement asynchronous connection */
|
||||
channel = NETConnectWithFlags(argv[3], port_no, 0);
|
||||
}
|
||||
|
||||
@@ -895,7 +915,11 @@ int AsyncUnitCreateHost(const char* host, const char* port, pAsyncUnit* handle)
|
||||
status = AQ_Init(self);
|
||||
|
||||
unit = (pAsyncUnit) malloc(sizeof(AsyncUnit));
|
||||
/* TODO: check malloc failure */
|
||||
if (unit == NULL) {
|
||||
SICSLogWrite("ERROR: Out of memory in AsyncUnitCreateHost", eError);
|
||||
*handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
memset(unit, 0, sizeof(AsyncUnit));
|
||||
++self->unit_count;
|
||||
unit->queue = self;
|
||||
|
||||
Reference in New Issue
Block a user