add API rpcReallocCont

This commit is contained in:
Jeff Tao 2020-02-22 20:13:30 +08:00
parent f74ad86c54
commit 5da147a691
1 changed files with 23 additions and 6 deletions

View File

@ -299,17 +299,16 @@ void rpcClose(void *param) {
tfree(pRpc); tfree(pRpc);
} }
void *rpcMallocCont(int size) { void *rpcMallocCont(int contLen) {
char *pMsg = NULL; int size = contLen + RPC_MSG_OVERHEAD;
size += RPC_MSG_OVERHEAD; char *start = (char *)calloc(1, (size_t)size);
pMsg = (char *)calloc(1, (size_t)size); if (start == NULL) {
if (pMsg == NULL) {
tError("failed to malloc msg, size:%d", size); tError("failed to malloc msg, size:%d", size);
return NULL; return NULL;
} }
return pMsg + sizeof(SRpcReqContext) + sizeof(SRpcHead); return start + sizeof(SRpcReqContext) + sizeof(SRpcHead);
} }
void rpcFreeCont(void *cont) { void rpcFreeCont(void *cont) {
@ -319,6 +318,24 @@ void rpcFreeCont(void *cont) {
} }
} }
void *rpcReallocCont(void *ptr, int contLen) {
if (ptr == NULL) return rpcMallocCont(contLen);
char *start = ((char *)ptr) - sizeof(SRpcReqContext) - sizeof(SRpcHead);
if (contLen == 0 ) {
free(start);
}
int size = contLen + RPC_MSG_OVERHEAD;
start = realloc(start, size);
if (start == NULL) {
tError("failed to realloc cont, size:%d", size);
return NULL;
}
return start + sizeof(SRpcReqContext) + sizeof(SRpcHead);
}
void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, char type, void *pCont, int contLen, void *ahandle) { void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, char type, void *pCont, int contLen, void *ahandle) {
SRpcInfo *pRpc = (SRpcInfo *)shandle; SRpcInfo *pRpc = (SRpcInfo *)shandle;
SRpcReqContext *pContext; SRpcReqContext *pContext;