]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_close.c
47aa9abbc2db28c988fd9a7f47599153415890cc
[netatalk.git] / libatalk / atp / atp_close.c
1 /*
2  * Copyright (c) 1990,1997 Regents of The University of Michigan.
3  * All Rights Reserved. See COPYRIGHT.
4  */
5
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/time.h>
9 #include <netatalk/at.h>
10 #include <atalk/netddp.h>
11 #include <atalk/atp.h>
12 #include "atp_internals.h"
13 #ifdef EBUG
14 #include <stdio.h>
15 #endif EBUG
16
17 int atp_close( ah )
18     ATP         ah;
19 {
20     struct atpbuf       *cq;
21     int                 i;
22
23     /* remove from list of open atp sockets & discard queued data
24     */
25 #ifdef EBUG
26     print_bufuse( ah, "atp_close");
27 #endif EBUG
28
29     while ( ah->atph_queue != NULL ) {
30         cq = ah->atph_queue;
31         ah->atph_queue = cq->atpbuf_next;
32         atp_free_buf( cq );
33     }
34
35     while ( ah->atph_sent != NULL ) {
36         cq = ah->atph_sent;
37         for ( i = 0; i < 8; ++i ) {
38             if ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) {
39                 atp_free_buf( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
40             }
41         }
42         ah->atph_sent = cq->atpbuf_next;
43         atp_free_buf( cq );
44     }
45
46     if ( ah->atph_reqpkt != NULL ) {
47         atp_free_buf( ah->atph_reqpkt );
48         ah->atph_reqpkt = NULL;
49     }
50
51     for ( i = 0; i < 8; ++i ) {
52         if ( ah->atph_resppkt[ i ] != NULL ) {
53             atp_free_buf( ah->atph_resppkt[ i ] );
54             ah->atph_resppkt[ i ] = NULL;
55         }
56     }
57
58 #ifdef EBUG
59     print_bufuse( ah, "atp_close end");
60 #endif EBUG
61
62     i = ah->atph_socket;
63     atp_free_buf( (struct atpbuf *) ah );
64
65     if (netddp_close(i) < 0)
66       return -1;
67
68     return 0;
69 }