OpenDNSSEC-signer  1.4.1
tcpset.h
Go to the documentation of this file.
1 /*
2  * $Id: tcpset.h 4958 2011-04-18 07:11:09Z matthijs $
3  *
4  * Copyright (c) 2011 NLNet Labs. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
34 #ifndef WIRE_TCPSET_H
35 #define WIRE_TCPSET_H
36 
37 #include "config.h"
38 #include "shared/allocator.h"
39 #include "wire/buffer.h"
40 #include "wire/xfrd.h"
41 
42 #include <stdint.h>
43 
44 #define TCPSET_MAX 50
45 
52  int fd;
53  /* how many bytes have been read/written - total, incl. tcp length bytes */
54  uint32_t total_bytes;
55  /* msg len bytes */
56  uint16_t msglen;
57  /* packet buffer of connection */
59  /* state: reading or writing */
60  unsigned is_reading : 1;
61 };
62 
63 /*
64  * Set of tcp connections.
65  *
66  */
72  size_t tcp_count;
73 };
74 
82 
90 
96 void tcp_conn_ready(tcp_conn_type* tcp);
97 
98 /*
99  * Read from a tcp connection.
100  * On first call, make sure total_bytes = 0, msglen=0, buffer clear,
101  * and the packet and fd need to be set.
102  * \param[in] tcp tcp connection
103  * \return int -1 on error,
104  * 0 on short read,
105  * 1 on completed read.
106  *
107  */
108 int tcp_conn_read(tcp_conn_type* tcp);
109 
110 /*
111  * Write to a tcp connection.
112  * On first call, make sure total_bytes=0, msglen=limit, buffer filled,
113  * and the packet and fd need to be set.
114  * \param[in] tcp tcp connection
115  * \return int -1 on error,
116  * 0 on short write,
117  * 1 on completed write.
118  *
119  */
120 int tcp_conn_write(tcp_conn_type* tcp);
121 
128 void tcp_set_cleanup(tcp_set_type* set, allocator_type* allocator);
129 
130 #endif /* WIRE_TCPSET_H */