ldb-samba: ldif_read_objectSid avoids VLA
[samba.git] / ctdb / common / pkt_write.h
1 /*
2    API for writing a packet
3
4    Copyright (C) Amitay Isaacs 2015
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program 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
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __CTDB_PKT_WRITE_H__
21 #define __CTDB_PKT_WRITE_H__
22
23 #include <talloc.h>
24 #include <tevent.h>
25
26 /**
27  * @file pkt_write.h
28  *
29  * @brief Write a packet.
30  *
31  * Write a complete packet with possibly multiple system calls.
32  */
33
34 /**
35  * @brief Start async computation to write a packet
36  *
37  * This returns a tevent request to write a packet to given fd.  The fd
38  * should be nonblocking. Freeing this request will free all the memory
39  * associated with the request.
40  *
41  * @param[in] mem_ctx Talloc memory context
42  * @param[in] ev Tevent context
43  * @param[in] fd The non-blocking file/socket descriptor to write to
44  * @param[in] buf The data
45  * @param[in] buflen The size of the data
46  * @return new tevent request or NULL on failure
47  */
48 struct tevent_req *pkt_write_send(TALLOC_CTX *mem_ctx,
49                                   struct tevent_context *ev,
50                                   int fd, uint8_t *buf, size_t buflen);
51
52 /**
53  * @brief Function to actually write data to the socket
54  *
55  * This function should be called, when tevent fd event is triggered
56  * for TEVENT_FD_WRITE event.  This function has the syntax of
57  * tevent_fd_handler_t.  The private_data for this function is the tevent
58  * request created by pkt_write_send function.
59  *
60  * @param[in] ev Tevent context
61  * @param[in] fde Tevent fd context
62  * @param[in] flags Tevent fd flags
63  * @param[in] req The active tevent request
64  */
65 void pkt_write_handler(struct tevent_context *ev, struct tevent_fd *fde,
66                        uint16_t flags, struct tevent_req *req);
67
68 /**
69  * @brief Packet is sent
70  *
71  * This function returns the number of bytes written.
72  *
73  * @param[in] req Tevent request
74  * @param[out] perrno errno in case of failure
75  * @return the number of bytes written, or -1 on failure
76  */
77 ssize_t pkt_write_recv(struct tevent_req *req, int *perrno);
78
79 #endif /* __CTDB_PKT_WRITE_H__ */