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