提交 5da147a6 编写于 作者: 陶建辉(Jeff)'s avatar 陶建辉(Jeff)

add API rpcReallocCont

上级 f74ad86c
...@@ -299,17 +299,16 @@ void rpcClose(void *param) { ...@@ -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) { ...@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册