Diff for /libaitrpc/src/blob.c between versions 1.6 and 1.13

version 1.6, 2012/03/29 01:34:16 version 1.13, 2013/05/30 09:22:01
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, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
         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 47  SUCH DAMAGE. Line 47  SUCH DAMAGE.
   
   
 /*  /*
 * rpc_srv_blobCreate() - Create map blob to memory region and return object * rpc_srv_blobCreate() - Create and map blob to memory region and return object
  *   *
  * @srv = RPC Server instance   * @srv = RPC Server instance
  * @len = BLOB length object   * @len = BLOB length object
  * return: NULL error or !=NULL allocated BLOB object   * return: NULL error or !=NULL allocated BLOB object
  */   */
inline rpc_blob_t *rpc_blob_t *
 rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len)  rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len)
 {  {
         rpc_blob_t *blob = NULL;          rpc_blob_t *blob = NULL;
Line 61  rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len Line 61  rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len
         int f;          int f;
         u_int rnd;          u_int rnd;
   
 #ifdef HAVE_SRANDOMDEV  
         srandomdev();  
 #else  
         time_t tim;  
   
         srandom((time(&tim) ^ getpid()));  
 #endif  
 again:  again:
         rnd = random() % UINT_MAX;          rnd = random() % UINT_MAX;
   
         memset(szFName, 0, sizeof szFName);          memset(szFName, 0, sizeof szFName);
        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), rnd);        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&srv->srv_blob.dir), rnd);
         f = open(szFName, O_CREAT | O_EXCL | O_RDWR, 0600);          f = open(szFName, O_CREAT | O_EXCL | O_RDWR, 0600);
         if (f == -1) {          if (f == -1) {
                 if (errno == EEXIST)                  if (errno == EEXIST)
Line 81  again: Line 74  again:
                 LOGERR;                  LOGERR;
                 return NULL;                  return NULL;
         }          }
        if (lseek(f, len - 1, SEEK_SET) == -1) {        if (ftruncate(f, len) == -1) {
                 LOGERR;                  LOGERR;
                 close(f);                  close(f);
                 unlink(szFName);                  unlink(szFName);
                 return NULL;                  return NULL;
        } else        }
                write(f, "", 1); 
   
        blob = malloc(sizeof(rpc_blob_t));        blob = e_malloc(sizeof(rpc_blob_t));
         if (!blob) {          if (!blob) {
                 LOGERR;                  LOGERR;
                 close(f);                  close(f);
Line 100  again: Line 92  again:
         blob->blob_data = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0);          blob->blob_data = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0);
         if (blob->blob_data == MAP_FAILED) {          if (blob->blob_data == MAP_FAILED) {
                 LOGERR;                  LOGERR;
                free(blob);                e_free(blob);
                 close(f);                  close(f);
                 unlink(szFName);                  unlink(szFName);
                 return NULL;                  return NULL;
Line 119  again: Line 111  again:
  * @blob = Map to this BLOB element   * @blob = Map to this BLOB element
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)  rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)
 {  {
         int f;          int f;
Line 135  rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t Line 127  rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t
         }          }
   
         memset(szFName, 0, sizeof szFName);          memset(szFName, 0, sizeof szFName);
        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), blob->blob_var);        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&srv->srv_blob.dir), blob->blob_var);
         f = open(szFName, O_RDWR);          f = open(szFName, O_RDWR);
         if (f == -1) {          if (f == -1) {
                 LOGERR;                  LOGERR;
Line 163  rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t Line 155  rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t
  * @blob = Mapped BLOB element   * @blob = Mapped BLOB element
  * return: none   * return: none
  */   */
inline voidvoid
 rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)  rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)
 {  {
        if (!blob || !blob->blob_data)        if (blob && blob->blob_data) {
                rpc_SetErr(EINVAL, "Invalid arguments"); 
        else { 
                 munmap(blob->blob_data, blob->blob_len);                  munmap(blob->blob_data, blob->blob_len);
                 blob->blob_data = NULL;                  blob->blob_data = NULL;
         }          }
Line 181  rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) Line 171  rpc_srv_blobUnmap(rpc_blob_t * __restrict blob)
  * @blob = Mapped BLOB element   * @blob = Mapped BLOB element
  * return: -1 error or 0 ok   * return: -1 error or 0 ok
  */   */
inline intint
 rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob)
 {  {
         char szFName[MAXPATHLEN];          char szFName[MAXPATHLEN];
Line 189  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ Line 179  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_
         if (!blob) {          if (!blob) {
                 rpc_SetErr(EINVAL, "Invalid argument BLOB");                  rpc_SetErr(EINVAL, "Invalid argument BLOB");
                 return -1;                  return -1;
        }        } else
 
        if (blob->blob_data) 
                 rpc_srv_blobUnmap(blob);                  rpc_srv_blobUnmap(blob);
   
         memset(szFName, 0, sizeof szFName);          memset(szFName, 0, sizeof szFName);
        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STR(&srv->srv_blob.dir), blob->blob_var);        snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&srv->srv_blob.dir), blob->blob_var);
         if (unlink(szFName) == -1) {          if (unlink(szFName) == -1) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
Line 204  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ Line 192  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_
         return 0;          return 0;
 }  }
   
// ------------------------------------------------------------/* ------------------------------------------------------------ */
   
 /*  /*
  * rpc_srv_sendBLOB() - Send mapped BLOB to client   * rpc_srv_sendBLOB() - Send mapped BLOB to client
Line 225  rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 213  rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_
         }          }
   
         for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) {          for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) {
                len = send(cli->cli_sock, pos, ret, 0);                len = send(cli->cli_sock, pos, ret, MSG_NOSIGNAL);
                 if (len == -1) {                  if (len == -1) {
                         LOGERR;                          LOGERR;
                         return -1;                          return -1;
Line 247  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 235  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
 {  {
         int ret, len;          int ret, len;
         uint8_t *pos;          uint8_t *pos;
        fd_set fds;        struct pollfd pfd;
        struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; 
   
         if (!cli || !blob || !blob->blob_data) {          if (!cli || !blob || !blob->blob_data) {
                 rpc_SetErr(EINVAL, "Invalid arguments");                  rpc_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
        } else        }
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; 
   
           pfd.fd = cli->cli_sock;
           pfd.events = POLLIN | POLLPRI;
         for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) {          for (ret = blob->blob_len, pos = blob->blob_data; ret > 0; ret -= len, pos += len) {
                FD_ZERO(&fds);                if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || 
                FD_SET(cli->cli_sock, &fds);                                pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                len = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv);                        if (len)
                if (len < 1) {                                LOGERR;
                        LOGERR;                        else
                                 rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond");
                         return -1;                          return -1;
                 }                  }
   
Line 275  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 264  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
         return ret;          return ret;
 }  }
   
// ------------------------------------------------------------/* ------------------------------------------------------------ */
   
 /*  /*
  * rpc_cli_sendBLOB() - Send BLOB to server   * rpc_cli_sendBLOB() - Send BLOB to server
Line 291  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 280  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
         int ret, len;          int ret, len;
         uint8_t *pos;          uint8_t *pos;
         struct tagBLOBHdr hdr;          struct tagBLOBHdr hdr;
        fd_set fds;        struct pollfd pfd;
        struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; 
   
         if (!cli || !var || !data) {          if (!cli || !var || !data) {
                 rpc_SetErr(EINVAL, "Invalid arguments");                  rpc_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
         } else          } else
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout;                memset(&hdr, 0, sizeof hdr);
   
         rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);          rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);
         hdr.hdr_cmd = set;          hdr.hdr_cmd = set;
         hdr.hdr_var = 0;          hdr.hdr_var = 0;
         hdr.hdr_ret = 0;          hdr.hdr_ret = 0;
         hdr.hdr_len = htonl(AIT_LEN(var));          hdr.hdr_len = htonl(AIT_LEN(var));
         /* calculate CRC */  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2));  
   
         /* send SET request */          /* send SET request */
        if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {        pfd.fd = cli->cli_sock;
         pfd.events = POLLOUT;
         if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || 
                         pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         }          }
           if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) {
                   LOGERR;
                   return -1;
           }
   
         /* send BLOB to server */          /* send BLOB to server */
         for (ret = AIT_LEN(var), pos = data; ret > 0; ret -= len, pos += len)          for (ret = AIT_LEN(var), pos = data; ret > 0; ret -= len, pos += len)
                if ((len = send(cli->cli_sock, pos, ret, 0)) == -1) {                if ((len = send(cli->cli_sock, pos, ret, MSG_NOSIGNAL)) == -1) {
                         LOGERR;                          LOGERR;
                         return -1;                          return -1;
                 }                  }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        pfd.events = POLLIN | POLLPRI;
        FD_SET(cli->cli_sock, &fds);        if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || 
        switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {                        pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                case -1:                if (ret)
                         LOGERR;                          LOGERR;
                        return 1;                else
                case 0:                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond");
                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde");                return -1;
                        return 1; 
         }          }
         if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {          if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {
                 LOGERR;                  LOGERR;
                 return 1;                  return 1;
         }          }
         /* check CRC */  
         ret = ntohs(hdr.hdr_crc);  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) {  
                 rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet");  
                 return 1;  
         }  
   
         if (hdr.hdr_cmd != error) {          if (hdr.hdr_cmd != error) {
                 if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {                  if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {
Line 351  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 335  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
                         return 1;                          return 1;
                 }                  }
   
                var->val.blob = ntohl(hdr.hdr_var);                AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len));
         }          }
   
         return hdr.hdr_cmd == error;          return hdr.hdr_cmd == error;
Line 362  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 346  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
  *   *
  * @cli = Client instance   * @cli = Client instance
  * @var = BLOB variable   * @var = BLOB variable
 * @data = BLOB data, must be free after use! * @data = BLOB data, must be e_free after use!
  * return: -1 error, 0 ok, 1 remote error   * return: -1 error, 0 ok, 1 remote error
  */   */
 int  int
Line 370  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 354  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
 {  {
         int ret, len;          int ret, len;
         uint8_t *pos;          uint8_t *pos;
        fd_set fds;        struct pollfd pfd;
        struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; 
         struct tagBLOBHdr hdr;          struct tagBLOBHdr hdr;
   
         if (!cli || !var || !data) {          if (!cli || !var || !data) {
                 rpc_SetErr(EINVAL, "Invalid arguments");                  rpc_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
        } else        }
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; 
   
        *data = malloc(AIT_LEN(var));        *data = e_malloc(AIT_LEN(var));
         if (!*data) {          if (!*data) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
        } else        } else {
                 memset(&hdr, 0, sizeof hdr);
                 memset(*data, 0, AIT_LEN(var));                  memset(*data, 0, AIT_LEN(var));
           }
   
         rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);          rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);
         hdr.hdr_cmd = get;          hdr.hdr_cmd = get;
         hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var));          hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var));
         hdr.hdr_ret = 0;          hdr.hdr_ret = 0;
         hdr.hdr_len = 0;          hdr.hdr_len = 0;
         /* calculate CRC */  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2));  
   
         /* send GET request */          /* send GET request */
           pfd.fd = cli->cli_sock;
           pfd.events = POLLOUT;
           if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || 
                           pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                   LOGERR;
                   e_free(*data);
                   *data = NULL;
                   return -1;
           }
         if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {          if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {
                 LOGERR;                  LOGERR;
                free(*data);                e_free(*data);
                 *data = NULL;                  *data = NULL;
                 return -1;                  return -1;
         }          }
   
         /* receive BLOB from server */          /* receive BLOB from server */
           pfd.events = POLLIN | POLLPRI;
         for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) {          for (ret = AIT_LEN(var), pos = *data; ret > 0; ret -= len, pos += len) {
                FD_ZERO(&fds);                if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || 
                FD_SET(cli->cli_sock, &fds);                                pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                len = select(cli->cli_sock + 1, &fds, NULL, NULL, &tv); 
                if (len < 1) { 
                         LOGERR;                          LOGERR;
                        free(*data);                        e_free(*data);
                         *data = NULL;                          *data = NULL;
                         return -1;                          return -1;
                 }                  }
   
                 if ((len = recv(cli->cli_sock, pos, ret, 0)) == -1) {                  if ((len = recv(cli->cli_sock, pos, ret, 0)) == -1) {
                         LOGERR;                          LOGERR;
                        free(*data);                        e_free(*data);
                         *data = NULL;                          *data = NULL;
                         return -1;                          return -1;
                 }                  }
         }          }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || 
        FD_SET(cli->cli_sock, &fds);                        pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
        switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {                if (len)
                case -1: 
                         LOGERR;                          LOGERR;
                        free(*data);                else
                        *data = NULL;                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond");
                        return 1;                e_free(*data);
                case 0:                *data = NULL;
                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde");                return 1;
                        free(*data); 
                        *data = NULL; 
                        return 1; 
         }          }
         if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {          if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {
                 LOGERR;                  LOGERR;
                free(*data);                e_free(*data);
                 *data = NULL;                  *data = NULL;
                 return 1;                  return 1;
         }          }
         /* check CRC */  
         ret = ntohs(hdr.hdr_crc);  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) {  
                 rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet");  
                 free(*data);  
                 *data = NULL;  
                 return 1;  
         }  
         if (hdr.hdr_cmd != error) {          if (hdr.hdr_cmd != error) {
                 if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {                  if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {
                         rpc_SetErr(ECANCELED, "Bad return length packet");                          rpc_SetErr(ECANCELED, "Bad return length packet");
                        free(*data);                        e_free(*data);
                         *data = NULL;                          *data = NULL;
                         return 1;                          return 1;
                 }                  }
Line 477  int Line 453  int
 rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var)  rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var)
 {  {
         struct tagBLOBHdr hdr;          struct tagBLOBHdr hdr;
        fd_set fds;        struct pollfd pfd;
        struct timeval tv = { DEF_RPC_TIMEOUT, 0 }; 
         int ret;          int ret;
   
         if (!cli || !var) {          if (!cli || !var) {
                 rpc_SetErr(EINVAL, "Invalid arguments");                  rpc_SetErr(EINVAL, "Invalid arguments");
                 return -1;                  return -1;
         } else          } else
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout;                memset(&hdr, 0, sizeof hdr);
   
         rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);          rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);
         hdr.hdr_cmd = unset;          hdr.hdr_cmd = unset;
         hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var));          hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var));
         hdr.hdr_ret = 0;          hdr.hdr_ret = 0;
         hdr.hdr_len = 0;          hdr.hdr_len = 0;
         /* calculate CRC */  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2));  
   
         /* send UNSET request */          /* send UNSET request */
        if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {        pfd.fd = cli->cli_sock;
         pfd.events = POLLOUT;
         if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || 
                         pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
         }          }
           if (send(cli->cli_sock, &hdr, sizeof hdr, MSG_NOSIGNAL) == -1) {
                   LOGERR;
                   return -1;
           }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        pfd.events = POLLIN | POLLPRI;
        FD_SET(cli->cli_sock, &fds);        if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || 
        switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {                        pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                case -1:                if (ret)
                         LOGERR;                          LOGERR;
                        return 1;                else
                case 0:                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond");
                        rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not responde");                return 1;
                        return 1; 
         }          }
         if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {          if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) {
                 LOGERR;                  LOGERR;
                 return 1;                  return 1;
         }          }
         /* check CRC */  
         ret = ntohs(hdr.hdr_crc);  
         hdr.hdr_crc ^= hdr.hdr_crc;  
         if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) {  
                 rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet");  
                 return 1;  
         }  
   
         return hdr.hdr_cmd == error;          return hdr.hdr_cmd == error;
 }  }
Line 533  rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t  Line 504  rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t 
  *   *
  * @cli = Client instance   * @cli = Client instance
  * @var = BLOB variable   * @var = BLOB variable
 * @data = BLOB data, must be free after use! * @data = BLOB data, must be e_free after use!
  * return: -1 error, 0 ok, 1 remote error   * return: -1 error, 0 ok, 1 remote error
  */   */
inline intint
 rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data)  rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data)
 {  {
         int ret;          int ret;

Removed from v.1.6  
changed lines
  Added in v.1.13


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