summaryrefslogtreecommitdiff
path: root/src/libskabus/skabus_rpc_release.c
blob: 80ad13e6804fdc7e7169772dc33c10bb0b11ec45 (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
/* ISC license. */

#include <stdint.h>
#include <errno.h>
#include <skalibs/uint64.h>
#include <skalibs/alloc.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/avltree.h>
#include <skabus/rpc.h>

int skabus_rpc_release (skabus_rpc_t *a, uint64_t serial)
{
  uint32_t id ;
  skabus_rpc_qinfo_t *p ;
  if (!avltree_search(&a->qmap, &serial, &id))
  {
    if (errno == ESRCH) errno = EINVAL ;
    return 0 ;
  }
  p = GENSETDYN_P(skabus_rpc_qinfo_t, &a->q, id) ;
  if (p->status) return (errno = p->status, 0) ;
  alloc_free(p->message.s) ;
  alloc_free(p->message.fds) ;
 /* fds are purposefully left open for the client. */
  p->status = EINVAL ;
  avltree_delete(&a->qmap, &serial) ;
  gensetdyn_delete(&a->q, id) ;
  return 1 ;
}