Diff for /libaitrpc/src/cli.c between versions 1.23 and 1.23.2.6

version 1.23, 2015/01/15 01:42:37 version 1.23.2.6, 2015/01/21 20:58:07
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004 - 2014Copyright 2004 - 2015
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 350  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res Line 350  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
         do {          do {
                 if (type == SOCK_STREAM)                  if (type == SOCK_STREAM)
                         ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen);                          ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen);
                else if (type == SOCK_BPF) {                else if (type == SOCK_EXT) {
                         ret = rpc_Read(sock, type, 0, NULL, buf, blen);
                         if (estlen)     /* hack for skip sanity checks */
                                 ret += sizeof(struct tagRPCCall);
                 } else if (type == SOCK_BPF) {
                         ret = rpc_Read(sock, type, 0, sa, AIT_GET_BUF(pkt), AIT_LEN(pkt));                          ret = rpc_Read(sock, type, 0, sa, AIT_GET_BUF(pkt), AIT_LEN(pkt));
                         if (ret > 0)                          if (ret > 0)
                                 estlen = ret;                                  estlen = ret;
Line 359  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res Line 363  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
                 if (ret < 1)                  if (ret < 1)
                         return ret;                          return ret;
   
                   /* 1st read for RPC header */
                   if (ret < sizeof(struct tagRPCCall)) {
                           rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret);
                           return -1;
                   }
   
                   /* check for loop request */
                   if (!estlen && !(rpc->call_io & RPC_ACK))
                           continue;
   
                 /* check for response from known address */                  /* check for response from known address */
                 if (!estlen) {                  if (!estlen) {
                         /* 1st read for RPC header */  
                         if (ret < sizeof(struct tagRPCCall)) {  
                                 rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret);  
                                 return -1;  
                         }  
   
                         /* calc estimated length */                          /* calc estimated length */
                         estlen = ntohl(rpc->call_len);                          estlen = ntohl(rpc->call_len);
                         if (estlen > AIT_LEN(pkt))                          if (estlen > AIT_LEN(pkt))
                                 AIT_RE_BUF(pkt, estlen);                                  AIT_RE_BUF(pkt, estlen);
                           blen = estlen;
                         buf = AIT_GET_BUF(pkt);                          buf = AIT_GET_BUF(pkt);
   
                           if (type == SOCK_EXT) {
                                   blen -= sizeof(struct tagRPCCall);
                                   buf += sizeof(struct tagRPCCall);
                           }
   
                         rpc = (struct tagRPCCall*) buf;                          rpc = (struct tagRPCCall*) buf;
                         blen = estlen;  
                         continue;                          continue;
                 }                  }
   
Line 381  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res Line 395  rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
                 break;                  break;
         } while (42);          } while (42);
   
        if (ret < sizeof(struct tagRPCCall) || estlen != ret) {        if (estlen != ret) {
                 rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n",                   rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n", 
                                 estlen, ret);                                  estlen, ret);
                 return -1;                  return -1;
Line 427  rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t Line 441  rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
         if (!vars)          if (!vars)
                 rpc->call_argc = 0;                  rpc->call_argc = 0;
         else          else
                rpc->call_argc = htons(array_Size(vars));                rpc->call_argc = (u_char) array_Size(vars);
   
         /* set reply */          /* set reply */
         rpc->call_req.flags = (uint64_t) htonl(noreply ? RPC_NOREPLY : RPC_REPLY);          rpc->call_req.flags = (uint64_t) htonl(noreply ? RPC_NOREPLY : RPC_REPLY);
Line 444  rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t Line 458  rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
   
         /* total packet length */          /* total packet length */
         rpc->call_len = htonl(len);          rpc->call_len = htonl(len);
           rpc->call_io = RPC_REQ;
   
         if (!nocrc) {          if (!nocrc) {
                 /* calculate CRC */                  /* calculate CRC */
Line 505  rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t  Line 520  rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t 
                                 strerror(ntohl(rpc->call_rep.eno)));                                  strerror(ntohl(rpc->call_rep.eno)));
                 return -1;                  return -1;
         }          }
        len = ntohs(rpc->call_argc) * sizeof(ait_val_t);        len = rpc->call_argc * sizeof(ait_val_t);
         if (len > AIT_LEN(pkt) - sizeof(struct tagRPCCall)) {          if (len > AIT_LEN(pkt) - sizeof(struct tagRPCCall)) {
                 rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ...");                  rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ...");
                 return -1;                  return -1;
Line 516  rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t  Line 531  rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t 
         }          }
   
         /* RPC is OK! Go de-marshaling variables ... */          /* RPC is OK! Go de-marshaling variables ... */
        if (vars && ntohs(rpc->call_argc)) {        if (vars && rpc->call_argc) {
 #ifdef CLI_RES_ZCOPY  #ifdef CLI_RES_ZCOPY
                 *vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len,                   *vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, 
                                ntohs(rpc->call_argc), 42);                                rpc->call_argc, 42);
 #else  #else
                 *vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len,                   *vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, 
                                ntohs(rpc->call_argc), 0);                                rpc->call_argc, 0);
 #endif  #endif
                 if (!*vars) {                  if (!*vars) {
                         rpc_SetErr(elwix_GetErrno(), "%s", elwix_GetError());                          rpc_SetErr(elwix_GetErrno(), "%s", elwix_GetError());
Line 554  rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short  Line 569  rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short 
                 rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!");                  rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!");
                 return -1;                  return -1;
         } else {          } else {
                if (cli->cli_id == SOCK_STREAM)                if (cli->cli_id == SOCK_STREAM || cli->cli_id == SOCK_EXT)
                         type = cli->cli_id;                          type = cli->cli_id;
                 buf = AIT_GET_BUF(&cli->cli_buf);                  buf = AIT_GET_BUF(&cli->cli_buf);
         }          }
Line 746  rpc_cli_closeClient2(rpc_cli_t ** __restrict cli) Line 761  rpc_cli_closeClient2(rpc_cli_t ** __restrict cli)
                 return;                  return;
   
         close((*cli)->cli_sock);          close((*cli)->cli_sock);
   
           AIT_FREE_VAL(&(*cli)->cli_buf);
   
           if ((*cli)->cli_parent)
                   e_free((*cli)->cli_parent);
   
           e_free(*cli);
           *cli = NULL;
   }
   
   /*
    * rpc_cli_openClientExt() - Connect to pipe RPC Server
    *
    * @InstID = InstID for RPC session request
    * @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet)
    * @fd = File descriptor
    * return: NULL == error or !=NULL connection to RPC server established
    */
   rpc_cli_t *
   rpc_cli_openClientExt(u_char InstID, int netBuf, int fd)
   {
           rpc_cli_t *cli = NULL;
           int n;
   
           cli = e_malloc(sizeof(rpc_cli_t));
           if (!cli) {
                   LOGERR;
                   return NULL;
           } else
                   memset(cli, 0, sizeof(rpc_cli_t));
   
           /* build session */
           cli->cli_parent = e_malloc(sizeof(rpc_sess_t));
           if (!cli->cli_parent) {
                   LOGERR;
                   e_free(cli);
                   return NULL;
           } else {
                   ((rpc_sess_t*) cli->cli_parent)->sess_version = RPC_VERSION;
                   ((rpc_sess_t*) cli->cli_parent)->sess_instance = InstID;
           }
   
           cli->cli_id = SOCK_EXT;
           cli->cli_sock = fd;
   
           n = (netBuf < RPC_MIN_BUFSIZ) ? getpagesize() : E_ALIGN(netBuf, 2);
           AIT_SET_BUFSIZ(&cli->cli_buf, 0, n);
   
           fcntl(cli->cli_sock, F_SETFL, 
                           fcntl(cli->cli_sock, F_GETFL) | O_NONBLOCK);
   
           return cli;
   }
   
   /*
    * rpc_cli_closeClientExt() - Close pipe connection to RPC server and free resources
    *
    * @cli = RPC Client session
    * return: none
    */
   void
   rpc_cli_closeClientExt(rpc_cli_t ** __restrict cli)
   {
           if (!cli || !*cli || (*cli)->cli_id != SOCK_EXT)
                   return;
   
         AIT_FREE_VAL(&(*cli)->cli_buf);          AIT_FREE_VAL(&(*cli)->cli_buf);
   

Removed from v.1.23  
changed lines
  Added in v.1.23.2.6


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