summaryrefslogtreecommitdiff
path: root/src/libunixonacid/textclient_end.c
blob: 1ddf93f1e09bc221f6ec1eb27a4439be4932e1e4 (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
/* ISC license. */

#include <errno.h>
#include <skalibs/djbunix.h>
#include <skalibs/textmessage.h>
#include <skalibs/textclient.h>

void textclient_end (textclient_t *a)
{
  fd_close(textmessage_sender_fd(&a->syncout)) ;
  if (textmessage_receiver_fd(&a->syncin) != textmessage_sender_fd(&a->syncout))
    fd_close(textmessage_receiver_fd(&a->syncin)) ;
  fd_close(textmessage_receiver_fd(&a->asyncin)) ;
  textmessage_sender_free(&a->syncout) ;
  textmessage_receiver_free(&a->syncin) ;
  textmessage_receiver_free(&a->asyncin) ;
  if (a->pid && a->options & TEXTCLIENT_OPTION_WAITPID)
  {
    int e = errno ;
    int wstat ;
    waitpid_nointr(a->pid, &wstat, 0) ;
    errno = e ;
  }
  *a = textclient_zero ;
}