]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_close.c
remove pre ansi declarations
[netatalk.git] / libatalk / atp / atp_close.c
1 /*
2  * $Id: atp_close.c,v 1.5 2009-10-13 22:55:37 didg 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(ATP ah)
26 {
27     struct atpbuf       *cq;
28     int                 i;
29
30     /* remove from list of open atp sockets & discard queued data
31     */
32 #ifdef EBUG
33     print_bufuse( ah, "atp_close");
34 #endif /* EBUG */
35
36     while ( ah->atph_queue != NULL ) {
37         cq = ah->atph_queue;
38         ah->atph_queue = cq->atpbuf_next;
39         atp_free_buf( cq );
40     }
41
42     while ( ah->atph_sent != NULL ) {
43         cq = ah->atph_sent;
44         for ( i = 0; i < 8; ++i ) {
45             if ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) {
46                 atp_free_buf( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
47             }
48         }
49         ah->atph_sent = cq->atpbuf_next;
50         atp_free_buf( cq );
51     }
52
53     if ( ah->atph_reqpkt != NULL ) {
54         atp_free_buf( ah->atph_reqpkt );
55         ah->atph_reqpkt = NULL;
56     }
57
58     for ( i = 0; i < 8; ++i ) {
59         if ( ah->atph_resppkt[ i ] != NULL ) {
60             atp_free_buf( ah->atph_resppkt[ i ] );
61             ah->atph_resppkt[ i ] = NULL;
62         }
63     }
64
65 #ifdef EBUG
66     print_bufuse( ah, "atp_close end");
67 #endif /* EBUG */
68
69     i = ah->atph_socket;
70     atp_free_buf( (struct atpbuf *) ah );
71
72     if (netddp_close(i) < 0)
73       return -1;
74
75     return 0;
76 }