skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

skaclient_server_ack.c (891B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <string.h>
      5 
      6 #include <skalibs/djbunix.h>
      7 #include <skalibs/skaclient.h>
      8 #include <skalibs/unixmessage.h>
      9 #include <skalibs/socket.h>
     10 #include <skalibs/posixishard.h>
     11 
     12 int skaclient_server_ack (unixmessage const *clientmsg, unixmessage_sender *out, unixmessage_sender *asyncout, char const *before, size_t beforelen, char const *after, size_t afterlen)
     13 {
     14   int fd[2] ;
     15   unixmessage m = { .s = (char *)after, .len = afterlen, .fds = fd, .nfds = 1 } ;
     16   static unsigned char const bits = 0xff ;
     17   if (clientmsg->nfds
     18    || clientmsg->len != beforelen
     19    || memcmp(clientmsg->s, before, beforelen)) return (errno = EPROTO, 0) ;
     20   if (ipc_pair_nbcoe(fd) < 0) return 0 ;
     21   unixmessage_sender_init(asyncout, fd[1]) ;
     22   if (!unixmessage_put_and_close(out, &m, &bits))
     23   {
     24     fd_close(fd[1]) ;
     25     fd_close(fd[0]) ;
     26     return 0 ;
     27   }
     28   return 1 ;
     29 }