tcpset.h
Go to the documentation of this file.
/*
* Copyright (c) 2011 NLNet Labs. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WIRE_TCPSET_H
#define WIRE_TCPSET_H
#include "config.h"
#include <stdint.h>
typedef struct tcp_conn_struct tcp_conn_type;
typedef struct tcp_set_struct tcp_set_type;
#include "status.h"
#include "wire/buffer.h"
#include "wire/xfrd.h"
#define TCPSET_MAX 50
struct tcp_conn_struct {
int fd;
/* how many bytes have been read/written - total, incl. tcp length bytes */
uint32_t total_bytes;
/* msg len bytes */
uint16_t msglen;
/* packet buffer of connection */
buffer_type* packet;
/* state: reading or writing */
unsigned is_reading : 1;
};
/*
* Set of tcp connections.
*
*/
struct tcp_set_struct {
tcp_conn_type* tcp_conn[TCPSET_MAX];
xfrd_type* tcp_waiting_first;
xfrd_type* tcp_waiting_last;
size_t tcp_count;
};
tcp_conn_type* tcp_conn_create(void);
tcp_set_type* tcp_set_create(void);
void tcp_conn_ready(tcp_conn_type* tcp);
/*
* Read from a tcp connection.
* On first call, make sure total_bytes = 0, msglen=0, buffer clear,
* and the packet and fd need to be set.
* \param[in] tcp tcp connection
* \return int -1 on error,
* 0 on short read,
* 1 on completed read.
*
*/
int tcp_conn_read(tcp_conn_type* tcp);
/*
* Write to a tcp connection.
* On first call, make sure total_bytes=0, msglen=limit, buffer filled,
* and the packet and fd need to be set.
* \param[in] tcp tcp connection
* \return int -1 on error,
* 0 on short write,
* 1 on completed write.
*
*/
int tcp_conn_write(tcp_conn_type* tcp);
void tcp_set_cleanup(tcp_set_type* set);
#endif /* WIRE_TCPSET_H */
tcp_set_struct::tcp_waiting_last
xfrd_type * tcp_waiting_last
Definition: tcpset.h:70
tcp_set_struct::tcp_count
size_t tcp_count
Definition: tcpset.h:71
tcp_set_struct::tcp_waiting_first
xfrd_type * tcp_waiting_first
Definition: tcpset.h:69
tcp_conn_struct::packet
buffer_type * packet
Definition: tcpset.h:58
xfrd.h
tcp_conn_read
int tcp_conn_read(tcp_conn_type *tcp)
Definition: tcpset.c:103
tcp_conn_create
tcp_conn_type * tcp_conn_create(void)
Definition: tcpset.c:45
tcp_set_cleanup
void tcp_set_cleanup(tcp_set_type *set)
Definition: tcpset.c:242
tcp_set_create
tcp_set_type * tcp_set_create(void)
Definition: tcpset.c:67
buffer_struct
Definition: buffer.h:112
tcp_set_struct
Definition: tcpset.h:67
tcp_conn_struct::msglen
uint16_t msglen
Definition: tcpset.h:56
tcp_conn_ready
void tcp_conn_ready(tcp_conn_type *tcp)
Definition: tcpset.c:89
tcp_conn_struct::total_bytes
uint32_t total_bytes
Definition: tcpset.h:54
tcp_conn_struct::is_reading
unsigned is_reading
Definition: tcpset.h:60
buffer.h
tcp_conn_struct::fd
int fd
Definition: tcpset.h:52
TCPSET_MAX
#define TCPSET_MAX
Definition: tcpset.h:45
xfrd_struct
Definition: xfrd.h:93
tcp_conn_struct
Definition: tcpset.h:51
tcp_conn_write
int tcp_conn_write(tcp_conn_type *tcp)
Definition: tcpset.c:177