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