Diff for /libaitrpc/src/srv.c between versions 1.5 and 1.5.2.5

version 1.5, 2011/09/07 07:24:21 version 1.5.2.5, 2011/09/07 10:46:54
Line 60  rpc_srv_dispatchCall(void *arg) Line 60  rpc_srv_dispatchCall(void *arg)
         u_char *buf;          u_char *buf;
         int ret, argc = 0, Limit = 0;          int ret, argc = 0, Limit = 0;
         register int i;          register int i;
           uint16_t tag = 0;
           uint32_t hash = 0;
   
         if (!arg) {          if (!arg) {
                 rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t procced RPC client ...\n");                  rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t procced RPC client ...\n");
Line 103  rpc_srv_dispatchCall(void *arg) Line 105  rpc_srv_dispatchCall(void *arg)
                 } else                  } else
                         rpc = (struct tagRPCCall*) buf;                          rpc = (struct tagRPCCall*) buf;
                 /* check RPC packet session info */                  /* check RPC packet session info */
                if (memcmp(&rpc->call_session, &s->srv_session, sizeof rpc->call_session)) {                if (rpc_chkPktSession(&rpc->call_session, &s->srv_session)) {
                         rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n");                          rpc_SetErr(ERPCMISMATCH, "Error:: get invalid RPC session ...\n");
                         ret = -5;                          ret = -5;
                         goto makeReply;                          goto makeReply;
                 } else                  } else
                         Limit = sizeof(struct tagRPCCall);                          Limit = sizeof(struct tagRPCCall);
   
                   tag = rpc->call_tag;
                   hash = rpc->call_hash;
   
                 /* RPC is OK! Go decapsulate variables ... */                  /* RPC is OK! Go decapsulate variables ... */
                if (rpc->call_argc) {                if (ntohs(rpc->call_argc)) {
                        arr = io_buffer2vals(buf + Limit, s->srv_netbuf - Limit, rpc->call_argc, 1);                        arr = io_buffer2vals(buf + Limit, s->srv_netbuf - Limit, 
                                         ntohs(rpc->call_argc), 1);
                         if (!arr) {                          if (!arr) {
                                 ret = -5;                                  ret = -5;
                                 goto makeReply;                                  goto makeReply;
Line 123  rpc_srv_dispatchCall(void *arg) Line 129  rpc_srv_dispatchCall(void *arg)
                 /* execute call */                  /* execute call */
                 argc = 0;                  argc = 0;
                 memcpy(&ses, &rpc->call_session, sizeof ses);                  memcpy(&ses, &rpc->call_session, sizeof ses);
                if (!(f = rpc_srv_getCall(s, rpc->call_tag, rpc->call_hash))) {                if (!(f = rpc_srv_getCall(s, ntohs(tag), ntohl(hash)))) {
                         rpc_SetErr(EPROGUNAVAIL, "Error:: call not found into RPC server ...\n");                          rpc_SetErr(EPROGUNAVAIL, "Error:: call not found into RPC server ...\n");
                         ret = -6;                          ret = -6;
                 } else                  } else
Line 146  makeReply: Line 152  makeReply:
                 Limit = sizeof(struct tagRPCRet);                  Limit = sizeof(struct tagRPCRet);
   
                 memcpy(&rrpc->ret_session, &ses, sizeof(rpc_sess_t));                  memcpy(&rrpc->ret_session, &ses, sizeof(rpc_sess_t));
                rrpc->ret_tag = rpc->call_tag;                rrpc->ret_tag = tag;
                rrpc->ret_hash = rpc->call_hash;                rrpc->ret_hash = hash;
                rrpc->ret_errno = rpc_Errno;                rrpc->ret_errno = htonl(rpc_Errno);
                rrpc->ret_retcode = ret;                rrpc->ret_retcode = htonl(ret);
                rrpc->ret_argc = argc;                rrpc->ret_argc = htons(argc);
   
                 if (argc && arr) {                  if (argc && arr) {
                         /* Go Encapsulate variables ... */                          /* Go Encapsulate variables ... */
Line 682  rpc_srv_initServer(u_int regProgID, u_int regProcID, i Line 688  rpc_srv_initServer(u_int regProgID, u_int regProcID, i
   
 /*  /*
  * rpc_srv_endServer() Destroy RPC server, close all opened sockets and free resources   * rpc_srv_endServer() Destroy RPC server, close all opened sockets and free resources
 * @srv = RPC Server instance * @psrv = RPC Server instance
  * return: none   * return: none
  */   */
 void  void
rpc_srv_endServer(rpc_srv_t * __restrict srv)rpc_srv_endServer(rpc_srv_t ** __restrict psrv)
 {  {
         rpc_cli_t *c;          rpc_cli_t *c;
         register int i;          register int i;
         rpc_func_t *f;          rpc_func_t *f;
   
        if (!srv) {        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");
                 return;                  return;
         }          }
   
        rpc_srv_endBLOBServer(srv);        rpc_srv_endBLOBServer(*psrv);
   
         /* close all clients connections & server socket */          /* close all clients connections & server socket */
        for (i = 0, c = srv->srv_clients; i < srv->srv_numcli && c; i++, c++)        for (i = 0, c = (*psrv)->srv_clients; i < (*psrv)->srv_numcli && c; i++, c++)
                 if (c->cli_sa.sa_family) {                  if (c->cli_sa.sa_family) {
                         shutdown(c->cli_sock, SHUT_RDWR);                          shutdown(c->cli_sock, SHUT_RDWR);
                         close(c->cli_sock);                          close(c->cli_sock);
                 }                  }
        close(srv->srv_server.cli_sock);        close((*psrv)->srv_server.cli_sock);
   
        if (srv->srv_clients) {        if ((*psrv)->srv_clients) {
                free(srv->srv_clients);                free((*psrv)->srv_clients);
                srv->srv_clients = NULL;                (*psrv)->srv_clients = NULL;
                srv->srv_numcli = 0;                (*psrv)->srv_numcli = 0;
         }          }
   
         /* detach exported calls */          /* detach exported calls */
        pthread_mutex_lock(&srv->srv_mtx);        pthread_mutex_lock(&(*psrv)->srv_mtx);
        while ((f = srv->srv_funcs)) {        while ((f = (*psrv)->srv_funcs)) {
                srv->srv_funcs = f->func_next;                (*psrv)->srv_funcs = f->func_next;
                 rpc_srv_destroyVars(f);
                 free(f);                  free(f);
         }          }
        pthread_mutex_unlock(&srv->srv_mtx);        pthread_mutex_unlock(&(*psrv)->srv_mtx);
   
        while (pthread_mutex_trylock(&srv->srv_mtx) == EBUSY);        while (pthread_mutex_trylock(&(*psrv)->srv_mtx) == EBUSY);
        pthread_mutex_destroy(&srv->srv_mtx);        pthread_mutex_destroy(&(*psrv)->srv_mtx);
   
        free(srv);        free(*psrv);
        srv = NULL;        *psrv = NULL;
 }  }
   
 /*  /*
Line 827  rpc_srv_execCall(rpc_func_t * __restrict call, struct  Line 834  rpc_srv_execCall(rpc_func_t * __restrict call, struct 
   
         func = dlsym(dl, (char*) call->func_name);          func = dlsym(dl, (char*) call->func_name);
         if (func)          if (func)
                ret = func(call, rpc->call_argc, args);                ret = func(call, ntohs(rpc->call_argc), args);
         else {          else {
                 rpc_SetErr(ENOEXEC, "Error:: Can`t find function %s!\n", dlerror());                  rpc_SetErr(ENOEXEC, "Error:: Can`t find function %s!\n", dlerror());
                 ret = -1;                  ret = -1;

Removed from v.1.5  
changed lines
  Added in v.1.5.2.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>