diff options
Diffstat (limited to 'src/libnsss/nsss_switch_set_timeout.c')
-rw-r--r-- | src/libnsss/nsss_switch_set_timeout.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libnsss/nsss_switch_set_timeout.c b/src/libnsss/nsss_switch_set_timeout.c new file mode 100644 index 0000000..ce037db --- /dev/null +++ b/src/libnsss/nsss_switch_set_timeout.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <stdint.h> +#include <errno.h> + +#include <skalibs/uint32.h> +#include <skalibs/unix-timed.h> + +#include <nsss/nsss-switch.h> +#include "nsss-switch-internal.h" + +int nsss_switch_set_timeout (nsss_switch_t *a, unsigned int t, tain const *deadline, tain *stamp) +{ + char buf[5] = { NSSS_SWITCH_SET_TIMEOUT } ; + uint32_pack_big(buf + 1, (uint32_t)t) ; + if (!nsss_switch_send(a, buf, 5, deadline, stamp)) return 0 ; + if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ; + if ((unsigned char)buf[0] == 255) return 0 ; + if (buf[0]) return (errno = (unsigned char)buf[0], 0) ; + return 1 ; +} |