Added Sync message queue timeout
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 18 May 2017 16:13:51 +0200
changeset 1930d26e0a12324
parent 192 9e94360802b5
child 194 01e62c252585
Added Sync message queue timeout
pEpObjCAdapter/PEPObjCAdapter.m
pEpObjCAdapter/PEPQueue.h
pEpObjCAdapter/PEPQueue.m
     1.1 --- a/pEpObjCAdapter/PEPObjCAdapter.m	Thu May 18 14:51:37 2017 +0200
     1.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Thu May 18 16:13:51 2017 +0200
     1.3 @@ -90,8 +90,7 @@
     1.4      
     1.5      PEPQueue *q = [PEPObjCAdapter getSyncQueue];
     1.6  
     1.7 -    // TODO : implement timeout
     1.8 -    void* result = (void*)[[q dequeue] pointerValue];
     1.9 +    void* result = (void*)[[q timedDequeue:timeout] pointerValue];
    1.10  
    1.11      if ( syncDelegate && needs_fastpoll )
    1.12          [syncDelegate fastPolling:false];
    1.13 @@ -100,7 +99,6 @@
    1.14  
    1.15  }
    1.16  
    1.17 -
    1.18  ///////////////////////////////////////////////////////////////////////////////
    1.19  // DB and paths
    1.20  
     2.1 --- a/pEpObjCAdapter/PEPQueue.h	Thu May 18 14:51:37 2017 +0200
     2.2 +++ b/pEpObjCAdapter/PEPQueue.h	Thu May 18 16:13:51 2017 +0200
     2.3 @@ -12,6 +12,8 @@
     2.4  
     2.5  - (void)enqueue:(id)object;
     2.6  
     2.7 +- (id)timedDequeue:(time_t*)timeout;
     2.8 +
     2.9  - (id)dequeue;
    2.10  
    2.11  - (void)kill;
     3.1 --- a/pEpObjCAdapter/PEPQueue.m	Thu May 18 14:51:37 2017 +0200
     3.2 +++ b/pEpObjCAdapter/PEPQueue.m	Thu May 18 16:13:51 2017 +0200
     3.3 @@ -52,7 +52,7 @@
     3.4      return res;
     3.5  }
     3.6  
     3.7 -- (id)dequeue
     3.8 +- (id)timedDequeue:(time_t*)timeout
     3.9  {
    3.10      id tmp = nil;
    3.11      
    3.12 @@ -60,7 +60,23 @@
    3.13      
    3.14      while ([self condwait])
    3.15      {
    3.16 -        [_cond wait];
    3.17 +        if (*timeout == 0)
    3.18 +        {
    3.19 +            [_cond wait];
    3.20 +        }
    3.21 +        else
    3.22 +        {
    3.23 +            NSDate *end = [NSDate dateWithTimeIntervalSinceNow: *timeout];
    3.24 +            
    3.25 +            [_cond waitUntilDate:end];
    3.26 +            
    3.27 +            NSTimeInterval remaining = [end timeIntervalSinceNow];
    3.28 +            
    3.29 +            if (remaining > 0)
    3.30 +                *timeout = remaining;
    3.31 +            else
    3.32 +                *timeout = 0;
    3.33 +        }
    3.34      }
    3.35      
    3.36      @synchronized(self) {
    3.37 @@ -76,6 +92,12 @@
    3.38      return tmp;
    3.39  }
    3.40  
    3.41 +- (id)dequeue
    3.42 +{
    3.43 +    time_t zeroTimeout = 0;
    3.44 +    return [self timedDequeue:&zeroTimeout];
    3.45 +}
    3.46 +
    3.47  - (void)kill
    3.48  {
    3.49      _queue = nil;
    3.50 @@ -94,4 +116,4 @@
    3.51      self.cond = nil;
    3.52  }
    3.53  
    3.54 -@end
    3.55 \ No newline at end of file
    3.56 +@end