LibCTDB
[sahlberg/ctdb.git] / libctdb / io_elem.h
1 #ifndef _LIBCTDB_IO_ELEM_H
2 #define _LIBCTDB_IO_ELEM_H
3 #include <stdbool.h>
4
5 /* Packets are of form: <u32 length><data>. */
6
7 /* Create a new queue element of at least len bytes (for reading or writing).
8  * Len may be rounded up for alignment. */
9 struct io_elem *new_io_elem(size_t len);
10
11 /* Free a queue element. */
12 void free_io_elem(struct io_elem *io);
13
14 /* If finished, this returns the request header, otherwise NULL. */
15 bool io_elem_finished(const struct io_elem *io);
16
17 /* Reset an io_elem to the start. */
18 void io_elem_reset(struct io_elem *io);
19
20 /* Access to raw data: if len is non-NULL it is filled in. */
21 void *io_elem_data(const struct io_elem *io, size_t *len);
22
23 /* Initialise the struct ctdb_req_header at the front of the I/O. */
24 void io_elem_init_req_header(struct io_elem *io,
25                              uint32_t operation,
26                              uint32_t destnode,
27                              uint32_t reqid);
28
29 /* Returns -1 if we hit an error.  Otherwise bytes read. */
30 int read_io_elem(int fd, struct io_elem *io);
31
32 /* Returns -1 if we hit an error.  Otherwise bytes written. */
33 int write_io_elem(int fd, struct io_elem *io);
34
35 /* Queues a received io element for later processing */
36 void io_elem_queue(struct ctdb_connection *ctdb, struct io_elem *io);
37
38 /* Removes an element from the queue */
39 void io_elem_dequeue(struct ctdb_connection *ctdb, struct io_elem *io);
40
41 #endif /* _LIBCTDB_IO_ELEM_H */