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

version 1.6, 2012/03/29 01:34:16 version 1.7, 2012/05/14 08:39:05
Line 247  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 247  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, ((rpc_sess_t*) cli->cli_parent)->sess_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;
                         return -1;                          return -1;
                 }                  }
Line 291  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 289  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        }
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; 
   
         rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);          rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);
         hdr.hdr_cmd = set;          hdr.hdr_cmd = set;
Line 323  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 319  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
                 }                  }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        pfd.fd = cli->cli_sock;
        FD_SET(cli->cli_sock, &fds);        pfd.events = POLLIN | POLLPRI;
        switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {        if ((ret = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || 
                case -1:                        pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                 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;
Line 370  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 366  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 = malloc(AIT_LEN(var));
         if (!*data) {          if (!*data) {
Line 405  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 399  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
         }          }
   
         /* receive BLOB from server */          /* receive BLOB from server */
           pfd.fd = cli->cli_sock;
           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, ((rpc_sess_t*) cli->cli_parent)->sess_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);                          free(*data);
                         *data = NULL;                          *data = NULL;
Line 425  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 419  rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t
         }          }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        if ((len = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_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;                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;
Line 477  int Line 467  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        }
                tv.tv_sec = ((rpc_sess_t*) cli->cli_parent)->sess_timeout; 
   
         rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);          rpc_addPktSession(&hdr.hdr_session, cli->cli_parent);
         hdr.hdr_cmd = unset;          hdr.hdr_cmd = unset;
Line 503  rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t  Line 491  rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t 
         }          }
   
         /* wait for reply */          /* wait for reply */
        FD_ZERO(&fds);        pfd.fd = cli->cli_sock;
        FD_SET(cli->cli_sock, &fds);        pfd.events = POLLIN | POLLPRI;
        switch (select(cli->cli_sock + 1, &fds, NULL, NULL, &tv)) {        if ((ret = poll(&pfd, 1, ((rpc_sess_t*) cli->cli_parent)->sess_timeout * 1000)) < 1 || 
                case -1:                        pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
                 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;

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


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