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