aboutsummaryrefslogtreecommitdiffstats
path: root/src/libunixonacid/sassclient_cancel.c
blob: bc4273e7e19b9340729514ee6f5f84cf1c35b9a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ISC license. */

#include <stdint.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>

#include <skalibs/uint32.h>
#include <skalibs/tai.h>
#include <skalibs/textclient.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/sassclient.h>
#include "sassclient-internal.h"

int sassclient_cancel (sassclient *a, uint32_t id, tain const *deadline, tain *stamp)
{
  int e ;

  {
    struct timespec ts ;
    tain diff ;
    tain_sub(&diff, deadline, stamp) ;
    if (!timespec_from_tain_relative(&ts, &diff)) return 0 ;
    e = pthread_mutex_timedlock(&a->connection_mutex, &ts) ;
//    e = pthread_mutex_clocklock(&a->connection_mutex, CLOCK_MONOTONIC, &ts) ;
    if (e) return (errno = e, 0) ;
  }

  e = sassclient_cancel_internal(a, id, deadline, stamp) ;
  if (e) goto err ;
  gensetdyn_delete(&a->store, id) ;
  pthread_mutex_unlock(&a->connection_mutex) ;
  return 1 ;

 err:
  pthread_mutex_unlock(&a->connection_mutex) ;
  errno = e ;
  return 0 ;
}