about summary refs log tree commit diff
path: root/src/libunixonacid/textclient_end.c
blob: a87a58f6e3cbd95e385131c09219ecbfee03f334 (plain) (blame)
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
/* ISC license. */

#include <errno.h>

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

void textclient_end (textclient *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 ;
}