OpenDNSSEC-signer 2.1.13
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 <stdint.h>
37
40
41#include "status.h"
42#include "wire/buffer.h"
43#include "wire/xfrd.h"
44
45#define TCPSET_MAX 50
46
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 */
71 size_t tcp_count;
72};
73
80extern tcp_conn_type* tcp_conn_create(void);
81
88extern tcp_set_type* tcp_set_create(void);
89
95extern void tcp_conn_ready(tcp_conn_type* tcp);
96
97/*
98 * Read from a tcp connection.
99 * On first call, make sure total_bytes = 0, msglen=0, buffer clear,
100 * and the packet and fd need to be set.
101 * \param[in] tcp tcp connection
102 * \return int -1 on error,
103 * 0 on short read,
104 * 1 on completed read.
105 *
106 */
107extern int tcp_conn_read(tcp_conn_type* tcp);
108
109/*
110 * Write to a tcp connection.
111 * On first call, make sure total_bytes=0, msglen=limit, buffer filled,
112 * and the packet and fd need to be set.
113 * \param[in] tcp tcp connection
114 * \return int -1 on error,
115 * 0 on short write,
116 * 1 on completed write.
117 *
118 */
119extern int tcp_conn_write(tcp_conn_type* tcp);
120
127extern void tcp_set_cleanup(tcp_set_type* set);
128
129#endif /* WIRE_TCPSET_H */
unsigned is_reading
Definition: tcpset.h:60
uint16_t msglen
Definition: tcpset.h:56
buffer_type * packet
Definition: tcpset.h:58
uint32_t total_bytes
Definition: tcpset.h:54
xfrd_type * tcp_waiting_first
Definition: tcpset.h:69
xfrd_type * tcp_waiting_last
Definition: tcpset.h:70
tcp_conn_type * tcp_conn[TCPSET_MAX]
Definition: tcpset.h:68
size_t tcp_count
Definition: tcpset.h:71
#define TCPSET_MAX
Definition: tcpset.h:45
void tcp_conn_ready(tcp_conn_type *tcp)
Definition: tcpset.c:89
void tcp_set_cleanup(tcp_set_type *set)
Definition: tcpset.c:242
int tcp_conn_read(tcp_conn_type *tcp)
Definition: tcpset.c:103
int tcp_conn_write(tcp_conn_type *tcp)
Definition: tcpset.c:177
tcp_set_type * tcp_set_create(void)
Definition: tcpset.c:67
tcp_conn_type * tcp_conn_create(void)
Definition: tcpset.c:45