selftest: tests for vfs_fruite file-id behavior
[Samba.git] / ctdb / common / pkt_write.h
blob19d8045343e061ef4d3990a69279f6c84dbacd81
1 /*
2 API for writing a packet
4 Copyright (C) Amitay Isaacs 2015
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.
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.
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/>.
20 #ifndef __CTDB_PKT_WRITE_H__
21 #define __CTDB_PKT_WRITE_H__
23 #include <talloc.h>
24 #include <tevent.h>
26 /**
27 * @file pkt_write.h
29 * @brief Write a packet.
31 * Write a complete packet with possibly multiple system calls.
34 /**
35 * @brief Start async computation to write a packet
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.
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
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);
52 /**
53 * @brief Function to actually write data to the socket
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.
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
65 void pkt_write_handler(struct tevent_context *ev, struct tevent_fd *fde,
66 uint16_t flags, struct tevent_req *req);
68 /**
69 * @brief Packet is sent
71 * This function returns the number of bytes written.
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
77 ssize_t pkt_write_recv(struct tevent_req *req, int *perrno);
79 #endif /* __CTDB_PKT_WRITE_H__ */