|
|
| version 1.6.2.8, 2012/03/14 15:08:03 | version 1.7.2.1, 2012/03/28 01:17:09 |
|---|---|
| Line 60 txPacket(sched_task_t *task) | Line 60 txPacket(sched_task_t *task) |
| int ret, wlen = sizeof(struct tagRPCCall); | int ret, wlen = sizeof(struct tagRPCCall); |
| array_t *arr = NULL; | array_t *arr = NULL; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (rpc->call_argc) { | if (rpc->call_argc) { |
| f = rpc_srv_getCall(s, ntohs(rpc->call_tag), ntohl(rpc->call_hash)); | f = rpc_srv_getCall(s, ntohs(rpc->call_tag), ntohl(rpc->call_hash)); |
| Line 85 txPacket(sched_task_t *task) | Line 85 txPacket(sched_task_t *task) |
| /* calculate CRC */ | /* calculate CRC */ |
| rpc->call_crc ^= rpc->call_crc; | rpc->call_crc ^= rpc->call_crc; |
| rpc->call_crc = htons(crcFletcher16((u_short*) buf, ((wlen + 1) & ~1) / 2)); | rpc->call_crc = htons(crcFletcher16((u_short*) buf, io_align(wlen, 1) / 2)); |
| /* send reply */ | /* send reply */ |
| ret = send(TASK_FD(task), buf, wlen, 0); | ret = send(TASK_FD(task), buf, wlen, 0); |
| Line 95 txPacket(sched_task_t *task) | Line 95 txPacket(sched_task_t *task) |
| rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " | rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " |
| "really sended %d bytes", wlen, ret); | "really sended %d bytes", wlen, ret); |
| else | else |
| LOGGER("Sended %d bytes", ret); | ioDEBUG(RPC_DEBUG_LEVEL, "Sended %d bytes", ret); |
| return NULL; | return NULL; |
| } | } |
| Line 111 execCall(sched_task_t *task) | Line 111 execCall(sched_task_t *task) |
| struct tagRPCCall *rpc = (struct tagRPCCall*) buf; | struct tagRPCCall *rpc = (struct tagRPCCall*) buf; |
| int argc = ntohs(rpc->call_argc); | int argc = ntohs(rpc->call_argc); |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| /* Go decapsulate variables ... */ | /* Go decapsulate variables ... */ |
| if (!(rpc->call_req.flags & RPC_NOREPLY) && argc) { | if (argc) { |
| arr = io_buffer2vars(buf + sizeof(struct tagRPCCall), | arr = io_buffer2vars(buf + sizeof(struct tagRPCCall), |
| TASK_DATLEN(task) - sizeof(struct tagRPCCall), argc, 1); | TASK_DATLEN(task) - sizeof(struct tagRPCCall), argc, 1); |
| if (!arr) { | if (!arr) { |
| Line 132 execCall(sched_task_t *task) | Line 132 execCall(sched_task_t *task) |
| rpc->call_rep.ret = RPC_ERROR(-1); | rpc->call_rep.ret = RPC_ERROR(-1); |
| rpc->call_rep.eno = RPC_ERROR(rpc_Errno); | rpc->call_rep.eno = RPC_ERROR(rpc_Errno); |
| } else { | } else { |
| LOGGER("RPC function %s from module %s", AIT_GET_STR(&f->func_name), | ioDEBUG(RPC_DEBUG_LEVEL, "RPC function %s from module %s", |
| AIT_GET_LIKE(&f->func_file, char*)); | AIT_GET_STR(&f->func_name), AIT_GET_LIKE(&f->func_file, char*)); |
| /* if client doesn't want reply */ | |
| argc = rpc->call_req.flags & RPC_NOREPLY; | |
| rpc->call_rep.ret = RPC_ERROR(rpc_srv_execCall(f, rpc, arr)); | rpc->call_rep.ret = RPC_ERROR(rpc_srv_execCall(f, rpc, arr)); |
| if (rpc->call_rep.ret == htonl(-1)) { | if (rpc->call_rep.ret == htonl(-1)) { |
| rpc->call_rep.eno = RPC_ERROR(errno); | rpc->call_rep.eno = RPC_ERROR(errno); |
| rpc->call_argc ^= rpc->call_argc; | rpc->call_argc ^= rpc->call_argc; |
| } else { | } else { |
| rpc->call_rep.eno ^= rpc->call_rep.eno; | rpc->call_rep.eno ^= rpc->call_rep.eno; |
| rpc->call_argc = htons(rpc_srv_getVars(f, NULL)); | if (argc) { |
| /* without reply */ | |
| io_clrVars(f->func_vars); | |
| rpc->call_argc ^= rpc->call_argc; | |
| } else | |
| rpc->call_argc = htons(rpc_srv_getVars(f, NULL)); | |
| } | } |
| } | } |
| Line 161 rxPacket(sched_task_t *task) | Line 168 rxPacket(sched_task_t *task) |
| struct tagRPCCall *rpc; | struct tagRPCCall *rpc; |
| struct timespec ts; | struct timespec ts; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| memset(buf, 0, TASK_DATLEN(task)); | memset(buf, 0, TASK_DATLEN(task)); |
| rlen = recv(TASK_FD(task), buf, TASK_DATLEN(task), 0); | rlen = recv(TASK_FD(task), buf, TASK_DATLEN(task), 0); |
| Line 173 rxPacket(sched_task_t *task) | Line 180 rxPacket(sched_task_t *task) |
| s->srv_kill = s->srv_blob.state = kill; | s->srv_kill = s->srv_blob.state = kill; |
| return NULL; | return NULL; |
| } else | } else |
| LOGGER("Readed %d bytes", rlen); | ioDEBUG(RPC_DEBUG_LEVEL, "Readed %d bytes", rlen); |
| if (rlen < sizeof(struct tagRPCCall)) { | if (rlen < sizeof(struct tagRPCCall)) { |
| rpc_SetErr(ERPCMISMATCH, "Too short RPC packet"); | rpc_SetErr(ERPCMISMATCH, "Too short RPC packet"); |
| Line 187 rxPacket(sched_task_t *task) | Line 194 rxPacket(sched_task_t *task) |
| /* check integrity of packet */ | /* check integrity of packet */ |
| crc = ntohs(rpc->call_crc); | crc = ntohs(rpc->call_crc); |
| rpc->call_crc ^= rpc->call_crc; | rpc->call_crc ^= rpc->call_crc; |
| if (crc != crcFletcher16((u_short*) buf, ((rlen + 1) & ~1) / 2)) { | if (crc != crcFletcher16((u_short*) buf, io_align(rlen, 1) / 2)) { |
| rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); | rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); |
| schedRead(TASK_ROOT(task), rxPacket, TASK_ARG(task), TASK_FD(task), | schedRead(TASK_ROOT(task), rxPacket, TASK_ARG(task), TASK_FD(task), |
| Line 233 rpc_srv_dispatchCall(void *arg) | Line 240 rpc_srv_dispatchCall(void *arg) |
| sched_root_task_t *root; | sched_root_task_t *root; |
| struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; | struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!arg) { | if (!arg) { |
| rpc_SetErr(EINVAL, "Invalid parameter can`t procced RPC client"); | rpc_SetErr(EINVAL, "Invalid parameter can`t procced RPC client"); |
| Line 274 rpc_srv_dispatchCall(void *arg) | Line 281 rpc_srv_dispatchCall(void *arg) |
| static void * | static void * |
| txBLOB(sched_task_t *task) | txBLOB(sched_task_t *task) |
| { | { |
| rpc_cli_t *c = TASK_ARG(task); | |
| u_char *buf = TASK_DATA(task); | u_char *buf = TASK_DATA(task); |
| struct tagBLOBHdr *blob = (struct tagBLOBHdr *) buf; | struct tagBLOBHdr *blob = (struct tagBLOBHdr *) buf; |
| int wlen = sizeof(struct tagBLOBHdr); | int wlen = sizeof(struct tagBLOBHdr); |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| /* calculate CRC */ | /* calculate CRC */ |
| blob->hdr_crc ^= blob->hdr_crc; | blob->hdr_crc ^= blob->hdr_crc; |
| blob->hdr_crc = htons(crcFletcher16((u_short*) buf, ((wlen + 1) & ~1) / 2)); | blob->hdr_crc = htons(crcFletcher16((u_short*) buf, io_align(wlen, 1) / 2)); |
| /* send reply */ | /* send reply */ |
| wlen = send(TASK_FD(task), buf, wlen, 0); | wlen = send(TASK_FD(task), buf, wlen, 0); |
| Line 293 txBLOB(sched_task_t *task) | Line 299 txBLOB(sched_task_t *task) |
| rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " | rpc_SetErr(EPROCUNAVAIL, "RPC reply, should be send %d bytes, " |
| "really sended %d bytes", sizeof(struct tagBLOBHdr), wlen); | "really sended %d bytes", sizeof(struct tagBLOBHdr), wlen); |
| else | else |
| LOGGER("Sended %d bytes", wlen); | ioDEBUG(RPC_DEBUG_LEVEL, "Sended %d bytes", wlen); |
| return NULL; | return NULL; |
| } | } |
| Line 310 rxBLOB(sched_task_t *task) | Line 316 rxBLOB(sched_task_t *task) |
| u_short crc; | u_short crc; |
| struct timespec ts; | struct timespec ts; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| /* check for disable service at this moment? */ | /* check for disable service at this moment? */ |
| if (s->srv_blob.state == disable) { | if (!s || s->srv_blob.state == disable) { |
| usleep(100000); | usleep(100000); |
| #ifdef HAVE_PTHREAD_YIELD | #ifdef HAVE_PTHREAD_YIELD |
| pthread_yield(); | pthread_yield(); |
| Line 333 rxBLOB(sched_task_t *task) | Line 339 rxBLOB(sched_task_t *task) |
| s->srv_blob.state = kill; | s->srv_blob.state = kill; |
| return NULL; | return NULL; |
| } else | } else |
| LOGGER("Readed %d bytes", rlen); | ioDEBUG(RPC_DEBUG_LEVEL, "Readed %d bytes", rlen); |
| if (rlen < sizeof(struct tagBLOBHdr)) { | if (rlen < sizeof(struct tagBLOBHdr)) { |
| rpc_SetErr(ERPCMISMATCH, "Too short BLOB packet"); | rpc_SetErr(ERPCMISMATCH, "Too short BLOB packet"); |
| Line 345 rxBLOB(sched_task_t *task) | Line 351 rxBLOB(sched_task_t *task) |
| /* check integrity of packet */ | /* check integrity of packet */ |
| crc = ntohs(blob->hdr_crc); | crc = ntohs(blob->hdr_crc); |
| blob->hdr_crc ^= blob->hdr_crc; | blob->hdr_crc ^= blob->hdr_crc; |
| if (crc != crcFletcher16((u_short*) buf, ((rlen + 1) & ~1) / 2)) { | if (crc != crcFletcher16((u_short*) buf, io_align(rlen, 1) / 2)) { |
| rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); | rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); |
| schedRead(TASK_ROOT(task), rxBLOB, TASK_ARG(task), TASK_FD(task), | schedRead(TASK_ROOT(task), rxBLOB, TASK_ARG(task), TASK_FD(task), |
| TASK_DATA(task), TASK_DATLEN(task)); | TASK_DATA(task), TASK_DATLEN(task)); |
| Line 353 rxBLOB(sched_task_t *task) | Line 359 rxBLOB(sched_task_t *task) |
| } | } |
| /* check RPC packet session info */ | /* check RPC packet session info */ |
| if (rpc_chkPktSession(&blob->hdr_session, &s->srv_session)) { | if ((crc = rpc_chkPktSession(&blob->hdr_session, &s->srv_session))) { |
| rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); | rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); |
| blob->hdr_cmd = error; | blob->hdr_cmd = error; |
| goto end; | goto end; |
| Line 426 rpc_srv_dispatchVars(void *arg) | Line 432 rpc_srv_dispatchVars(void *arg) |
| u_char *buf; | u_char *buf; |
| struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; | struct timespec ts = { DEF_RPC_TIMEOUT, 0 }; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!arg) { | if (!arg) { |
| rpc_SetErr(EINVAL, "Invalid parameter can`t procced BLOB"); | rpc_SetErr(EINVAL, "Invalid parameter can`t procced BLOB"); |
| Line 461 rpc_srv_dispatchVars(void *arg) | Line 467 rpc_srv_dispatchVars(void *arg) |
| memset(c, 0, sizeof(rpc_cli_t)); | memset(c, 0, sizeof(rpc_cli_t)); |
| free(buf); | free(buf); |
| return NULL; | return NULL; |
| #if 0 | |
| makeReply: | |
| /* Replay to client! */ | |
| ret = send(c->cli_sock, buf, sizeof buf, 0); | |
| if (ret == -1) { | |
| LOGERR; | |
| ret = -8; | |
| break; | |
| } | |
| if (ret != sizeof buf) { | |
| rpc_SetErr(EPROCUNAVAIL, "Error:: in send BLOB reply, should be send %d bytes, " | |
| "really is %d\n", sizeof buf, ret); | |
| ret = -9; | |
| if (s->srv_kill != kill && s->srv_blob.state != kill) | |
| continue; | |
| else | |
| break; | |
| } | |
| #endif | |
| } | } |
| // ------------------------------------------------- | // ------------------------------------------------- |
| Line 499 rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_s | Line 485 rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_s |
| int n = 1; | int n = 1; |
| io_sockaddr_t sa; | io_sockaddr_t sa; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!srv) { | if (!srv) { |
| rpc_SetErr(EINVAL, "Invalid parameters can`t init BLOB server"); | rpc_SetErr(EINVAL, "Invalid parameters can`t init BLOB server"); |
| Line 605 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) | Line 591 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) |
| register int i; | register int i; |
| rpc_blob_t *f; | rpc_blob_t *f; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!srv) { | if (!srv) { |
| rpc_SetErr(EINVAL, "Can`t destroy server because parameter is null!"); | rpc_SetErr(EINVAL, "Can`t destroy server because parameter is null!"); |
| Line 618 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) | Line 604 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) |
| rpc_srv_unregisterCall(srv, NULL, CALL_BLOBVARS); | rpc_srv_unregisterCall(srv, NULL, CALL_BLOBVARS); |
| rpc_srv_unregisterCall(srv, NULL, CALL_BLOBSTATE); | rpc_srv_unregisterCall(srv, NULL, CALL_BLOBSTATE); |
| AIT_FREE_VAL(&srv->srv_blob.dir); | |
| /* close all clients connections & server socket */ | /* close all clients connections & server socket */ |
| for (i = 0, c = srv->srv_blob.clients; i < srv->srv_numcli && c; i++, c++) | for (i = 0, c = srv->srv_blob.clients; i < srv->srv_numcli && c; i++, c++) |
| if (c->cli_sa.sa.sa_family) | if (c->cli_sa.sa.sa_family) |
| Line 640 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) | Line 624 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) |
| } | } |
| pthread_mutex_unlock(&srv->srv_blob.mtx); | pthread_mutex_unlock(&srv->srv_blob.mtx); |
| AIT_FREE_VAL(&srv->srv_blob.dir); | |
| while (pthread_mutex_trylock(&srv->srv_blob.mtx) == EBUSY); | while (pthread_mutex_trylock(&srv->srv_blob.mtx) == EBUSY); |
| pthread_mutex_destroy(&srv->srv_blob.mtx); | pthread_mutex_destroy(&srv->srv_blob.mtx); |
| } | } |
| Line 661 rpc_srv_loopBLOB(rpc_srv_t * __restrict srv) | Line 647 rpc_srv_loopBLOB(rpc_srv_t * __restrict srv) |
| struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; | struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; |
| pthread_attr_t attr; | pthread_attr_t attr; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!srv || srv->srv_blob.state == kill) { | if (!srv || srv->srv_blob.state == kill) { |
| rpc_SetErr(EINVAL, "Invalid parameter can`t start BLOB server"); | rpc_SetErr(EINVAL, "Invalid parameter can`t start BLOB server"); |
| Line 745 rpc_srv_initServer(u_int regProgID, u_int regProcID, i | Line 731 rpc_srv_initServer(u_int regProgID, u_int regProcID, i |
| struct hostent *host = NULL; | struct hostent *host = NULL; |
| io_sockaddr_t sa; | io_sockaddr_t sa; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!concurentClients || !regProgID || | if (!concurentClients || !regProgID || |
| (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { | (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { |
| Line 756 rpc_srv_initServer(u_int regProgID, u_int regProcID, i | Line 742 rpc_srv_initServer(u_int regProgID, u_int regProcID, i |
| Port = RPC_DEFPORT; | Port = RPC_DEFPORT; |
| if (!netBuf) | if (!netBuf) |
| netBuf = BUFSIZ; | netBuf = BUFSIZ; |
| else | |
| netBuf = io_align(netBuf, 1); /* align netBuf length */ | |
| if (csHost && family != AF_LOCAL) { | if (csHost && family != AF_LOCAL) { |
| host = gethostbyname2(csHost, family); | host = gethostbyname2(csHost, family); |
| if (!host) { | if (!host) { |
| Line 873 rpc_srv_endServer(rpc_srv_t ** __restrict psrv) | Line 861 rpc_srv_endServer(rpc_srv_t ** __restrict psrv) |
| register int i; | register int i; |
| rpc_func_t *f; | rpc_func_t *f; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!psrv || !*psrv) { | if (!psrv || !*psrv) { |
| rpc_SetErr(EINVAL, "Error:: Can`t destroy server because parameter is null!\n"); | rpc_SetErr(EINVAL, "Error:: Can`t destroy server because parameter is null!\n"); |
| Line 931 rpc_srv_loopServer(rpc_srv_t * __restrict srv) | Line 919 rpc_srv_loopServer(rpc_srv_t * __restrict srv) |
| struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; | struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; |
| pthread_attr_t attr; | pthread_attr_t attr; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!srv) { | if (!srv) { |
| rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start RPC server ...\n"); | rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t start RPC server ...\n"); |
| Line 1012 rpc_srv_execCall(rpc_func_t * __restrict call, struct | Line 1000 rpc_srv_execCall(rpc_func_t * __restrict call, struct |
| rpc_callback_t func; | rpc_callback_t func; |
| int ret; | int ret; |
| FTRACE(); | ioTRACE(RPC_TRACE_LEVEL); |
| if (!call || !rpc || !call->func_parent) { | if (!call || !rpc || !call->func_parent) { |
| rpc_SetErr(EINVAL, "Invalid parameter can`t exec function"); | rpc_SetErr(EINVAL, "Invalid parameter can`t exec function"); |