Diff for /libaitrpc/src/blob.c between versions 1.1.2.4 and 1.1.2.6

version 1.1.2.4, 2010/06/24 11:01:46 version 1.1.2.6, 2010/06/28 17:10:39
Line 209  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 209  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
   
         return ret;          return ret;
 }  }
   
   // ------------------------------------------------------------
   
   /*
    * rpc_cli_sendBLOB() Send BLOB to server
    * @cli = Client instance
    * @var = BLOB variable
    * @data = BLOB data
    * return: -1 error, 0 ok, 1 remote error
    */
   int
   rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void * __restrict data)
   {
           int ret, len;
           uint8_t *pos;
           struct tagBLOBHdr hdr;
           fd_set fds;
           struct timeval tv = { DEF_RPC_TIMEOUT, 0 };
   
           if (!cli || !var || !data) {
                   rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
                   return -1;
           }
   
           memcpy(&hdr.hdr_session, cli->cli_parent, sizeof(rpc_sess_t));
           hdr.hdr_cmd = set;
           hdr.hdr_var = (uint32_t) RPC_GET_BLOB(var);
           hdr.hdr_seq = 0;
           hdr.hdr_len = var->val_len;
           if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {
                   LOGERR;
                   return -1;
           }
   
           for (ret = var->val_len, pos = data; ret > 0; ret -= len, pos += len)
                   if ((len = send(cli->cli_sock, pos, ret > BLOBSIZ ? BLOBSIZ : ret, 0)) == -1) {
                           LOGERR;
                           return -1;
                   }
   
           FD_ZERO(&fds);
           FD_SET(cli->cli_sock, &fds);
           switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {
                   case -1:
                           LOGERR;
                           return -1;
                   case 0:
                           rpc_SetErr(ETIMEDOUT, "Error:: Timeout reached! Server not responde ...\n");
                           return -1;
           }
           if (read(cli->cli_sock, &hdr, sizeof hdr) == -1) {
                   LOGERR;
                   return -1;
           }
   
           return hdr.hdr_cmd == error;
   }
   
   /*
    * rpc_cli_recvBLOB() Receive BLOB from server
    * @cli = Client instance
    * @var = BLOB variable
    * @data = BLOB data, must be free after use!
    * return: -1 error, 0 ok, >0 unreceived data from server, may be error?
    */
   int
   rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data)
   {
           int ret, len;
           uint8_t *pos;
           fd_set fds;
           struct timeval tv = { DEF_RPC_TIMEOUT, 0 };
   
           if (!cli || !var || !data) {
                   rpc_SetErr(EINVAL, "Error:: invalid arguments ...\n");
                   return -1;
           }
   
           *data = malloc(var->val_len);
           if (!*data) {
                   LOGERR;
                   return -1;
           } else
                   memset(*data, 0, var->val_len);
   
           for (ret = var->val_len, pos = *data; ret > 0; ret -= len, pos += len) {
                   FD_ZERO(&fds);
                   FD_SET(cli->cli_sock, &fds);
                   len = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv);
                   if (len < 1) {
                           LOGERR;
                           free(*data);
                           *data = NULL;
                           return -1;
                   }
   
                   if ((len = recv(cli->cli_sock, pos, BLOBSIZ, 0)) == -1) {
                           LOGERR;
                           free(*data);
                           *data = NULL;
                           return -1;
                   }
           }
   
           return ret;
   }

Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.6


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