merge from Peter
[sahlberg/ctdb.git] / tcp / ctdb_tcp.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21
22 /* ctdb_tcp main state */
23 struct ctdb_tcp {
24         int listen_fd;
25 };
26
27 /*
28   incoming packet structure - only used when we get a partial packet
29   on read
30 */
31 struct ctdb_tcp_partial {
32         uint8_t *data;
33         uint32_t length;
34 };
35
36
37 /*
38   state associated with an incoming connection
39 */
40 struct ctdb_incoming {
41         struct ctdb_context *ctdb;
42         int fd;
43         struct ctdb_tcp_partial partial;
44 };
45
46 /*
47   outgoing packet structure - only allocated when we can't write immediately
48   to the socket
49 */
50 struct ctdb_tcp_packet {
51         struct ctdb_tcp_packet *next, *prev;
52         uint8_t *data;
53         uint32_t length;
54 };
55
56 /*
57   state associated with one tcp node
58 */
59 struct ctdb_tcp_node {
60         int fd;
61         struct fd_event *fde;
62         struct ctdb_tcp_packet *queue;
63 };
64
65
66 /* prototypes internal to tcp transport */
67 void ctdb_tcp_node_write(struct event_context *ev, struct fd_event *fde, 
68                          uint16_t flags, void *private);
69 void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde, 
70                             uint16_t flags, void *private);
71 int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length);
72 int ctdb_tcp_listen(struct ctdb_context *ctdb);
73 void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te, 
74                            struct timeval t, void *private);
75
76 #define CTDB_TCP_ALIGNMENT 8