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