Diff for /libaitrpc/src/blob.c between versions 1.12.2.1 and 1.15.8.1

version 1.12.2.1, 2013/05/26 20:24:52 version 1.15.8.1, 2015/01/15 20:39:11
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, 2012, 2013Copyright 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 46  SUCH DAMAGE. Line 46  SUCH DAMAGE.
 #include "global.h"  #include "global.h"
   
   
   static void *
   toutBLOB(sched_task_t *task)
   {
           rpc_srv_unregisterBLOB(TASK_DATA(task), ((rpc_blob_t*) TASK_ARG(task))->blob_var);
   
           return NULL;
   }
   
   
 /*  /*
  * rpc_srv_blobCreate() - Create and 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
    * @tout = BLOB live timeout in seconds
  * return: NULL error or !=NULL allocated BLOB object   * return: NULL error or !=NULL allocated BLOB object
  */   */
 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, int tout)
 {  {
         rpc_blob_t *blob = NULL;          rpc_blob_t *blob = NULL;
         char szFName[MAXPATHLEN];          char szFName[MAXPATHLEN];
         int f;          int f;
         u_int rnd;          u_int rnd;
           struct timespec ts = { tout ? tout : RPC_BLOB_TIMEOUT, 0 };
   
 again:  again:
         rnd = random() % UINT_MAX;          rnd = random() % UINT_MAX;
Line 101  again: Line 112  again:
   
         blob->blob_len = len;          blob->blob_len = len;
         blob->blob_var = rnd;          blob->blob_var = rnd;
   
           schedTimer(srv->srv_blob.root, toutBLOB, blob, ts, srv, 0);
         return blob;          return blob;
 }  }
   
Line 182  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ Line 195  rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_
         } else          } else
                 rpc_srv_blobUnmap(blob);                  rpc_srv_blobUnmap(blob);
   
           schedCancelby(srv->srv_blob.root, taskTIMER, CRITERIA_ARG, blob, NULL);
   
         memset(szFName, 0, sizeof szFName);          memset(szFName, 0, sizeof szFName);
         snprintf(szFName, sizeof szFName, BLOB_FILE, AIT_GET_STRZ(&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) {
Line 272  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ Line 287  rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_
  * @cli = Client instance   * @cli = Client instance
  * @var = BLOB variable   * @var = BLOB variable
  * @data = BLOB data   * @data = BLOB data
    * @tout = BLOB live on server timeout in seconds, if =0 default timeout
  * return: -1 error, 0 ok, 1 remote error   * return: -1 error, 0 ok, 1 remote error
  */   */
 int  int
rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void * __restrict data)rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, 
                 void * __restrict data, int tout)
 {  {
         int ret, len;          int ret, len;
         uint8_t *pos;          uint8_t *pos;
Line 291  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 308  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
         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 = tout;
         hdr.hdr_len = htonl(AIT_LEN(var));          hdr.hdr_len = htonl(AIT_LEN(var));
   
         /* send SET request */          /* send SET request */
Line 330  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t Line 347  rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t
         }          }
   
         if (hdr.hdr_cmd != error) {          if (hdr.hdr_cmd != error) {
                   AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len));
   
                 if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {                  if (ntohl(hdr.hdr_len) != AIT_LEN(var)) {
                           rpc_cli_delBLOB(cli, var);
                           AIT_NEW_BLOB(var, ntohl(hdr.hdr_len));
   
                         rpc_SetErr(ECANCELED, "Bad return length packet");                          rpc_SetErr(ECANCELED, "Bad return length packet");
                         return 1;                          return 1;
                 }                  }
   
                 AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len));  
         }          }
   
         return hdr.hdr_cmd == error;          return hdr.hdr_cmd == error;

Removed from v.1.12.2.1  
changed lines
  Added in v.1.15.8.1


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