version 1.5, 2011/09/07 07:24:21
|
version 1.5.2.3, 2011/09/07 09:22:15
|
Line 314 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
Line 314 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
struct tagRPCRet *rrpc = NULL; |
struct tagRPCRet *rrpc = NULL; |
int ret = 0, Limit = 0; |
int ret = 0, Limit = 0; |
struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; |
struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; |
|
uint16_t tag; |
|
uint32_t hash; |
|
|
if (!cli || !csFunc) { |
if (!cli || !csFunc) { |
rpc_SetErr(EINVAL, "Error:: Can`t execute call because parameter is null or invalid!\n"); |
rpc_SetErr(EINVAL, "Error:: Can`t execute call because parameter is null or invalid!\n"); |
Line 338 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
Line 340 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
|
|
/* prepare RPC call */ |
/* prepare RPC call */ |
rpc = (struct tagRPCCall*) buf; |
rpc = (struct tagRPCCall*) buf; |
memcpy(&rpc->call_session, cli->cli_parent, sizeof rpc->call_session); | rpc_addPktSession(&rpc->call_session, cli->cli_parent); |
rpc->call_argc = in_vars ? io_arraySize(in_vars) : 0; | rpc->call_argc = htons(in_vars ? io_arraySize(in_vars) : 0); |
rpc->call_tag = crcFletcher16((u_short*) str, sizeof str / 2); | rpc->call_tag = tag = htons(crcFletcher16((u_short*) str, sizeof str / 2)); |
rpc->call_hash = hash_fnv((char*) str, sizeof str); | rpc->call_hash = hash = htonl(hash_fnv((char*) str, sizeof str)); |
Limit = sizeof(struct tagRPCCall); |
Limit = sizeof(struct tagRPCCall); |
|
|
if (in_vars && io_arraySize(in_vars)) { |
if (in_vars && io_arraySize(in_vars)) { |
Line 396 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
Line 398 rpc_cli_execCall(rpc_cli_t *cli, const char *csModule,
|
} else |
} else |
rrpc = (struct tagRPCRet*) buf; |
rrpc = (struct tagRPCRet*) buf; |
/* check RPC packet session info */ |
/* check RPC packet session info */ |
if (memcmp(&rrpc->ret_session, cli->cli_parent, sizeof rrpc->ret_session)) { | if (rpc_chkPktSession(&rrpc->ret_session, cli->cli_parent)) { |
rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n"); |
rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n"); |
free(buf); |
free(buf); |
return -5; |
return -5; |
} else |
} else |
Limit = sizeof(struct tagRPCRet); |
Limit = sizeof(struct tagRPCRet); |
if (rrpc->ret_retcode < 0 && rrpc->ret_errno) { | if (rrpc->ret_tag != tag || rrpc->ret_hash != hash) { |
rpc_SetErr(rrpc->ret_errno, "Error::Server side: retcode=%d #%d %s\n", | printf("tag=%x/%x hash=%x/%x\n", rrpc->ret_tag, tag, rrpc->ret_hash, hash); |
rrpc->ret_retcode, rrpc->ret_errno, strerror(rrpc->ret_errno)); | rpc_SetErr(ERPCMISMATCH, "Error:: get wrong RPC reply ...\n"); |
free(buf); |
free(buf); |
|
return -5; |
|
} |
|
if (ntohl(rrpc->ret_retcode) < 0 && ntohl(rrpc->ret_errno)) { |
|
rpc_SetErr(ntohl(rrpc->ret_errno), "Error::Server side: retcode=%d #%d %s\n", |
|
ntohl(rrpc->ret_retcode), ntohl(rrpc->ret_errno), |
|
strerror(ntohl(rrpc->ret_errno))); |
|
free(buf); |
return -6; |
return -6; |
} |
} |
if (rrpc->ret_argc * sizeof(ait_val_t) > cli->cli_netbuf - Limit) { | if (ntohs(rrpc->ret_argc) * sizeof(ait_val_t) > cli->cli_netbuf - Limit) { |
rpc_SetErr(EMSGSIZE, "Error:: reply RPC packet is too long ...\n"); |
rpc_SetErr(EMSGSIZE, "Error:: reply RPC packet is too long ...\n"); |
free(buf); |
free(buf); |
return -7; |
return -7; |
} |
} |
|
|
/* RPC is OK! Go de-marshaling variables ... */ |
/* RPC is OK! Go de-marshaling variables ... */ |
if (rrpc->ret_argc) { | if (ntohs(rrpc->ret_argc)) { |
*out_vars = io_buffer2vals(buf + Limit, cli->cli_netbuf - Limit, rrpc->ret_argc, 0); | *out_vars = io_buffer2vals(buf + Limit, cli->cli_netbuf - Limit, |
| ntohs(rrpc->ret_argc), 0); |
if (!*out_vars) { |
if (!*out_vars) { |
free(buf); |
free(buf); |
return -1; |
return -1; |
} |
} |
} |
} |
|
|
ret = rrpc->ret_retcode; | ret = ntohl(rrpc->ret_retcode); |
free(buf); |
free(buf); |
return ret; |
return ret; |
} |
} |