2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2009
6 ** NOTE! The following LGPL license applies to the tevent
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 struct tsocket_context;
31 struct tsocket_address;
32 struct tdgram_context;
36 TSOCKET_TYPE_STREAM = 1,
41 typedef void (*tsocket_event_handler_t)(struct tsocket_context *, void *);
42 int tsocket_set_event_context(struct tsocket_context *sock,
43 struct tevent_context *ev);
44 int tsocket_set_readable_handler(struct tsocket_context *sock,
45 tsocket_event_handler_t handler,
47 int tsocket_set_writeable_handler(struct tsocket_context *sock,
48 tsocket_event_handler_t handler,
51 int tsocket_connect(struct tsocket_context *sock,
52 const struct tsocket_address *remote_addr);
54 int tsocket_listen(struct tsocket_context *sock,
57 int _tsocket_accept(struct tsocket_context *sock,
59 struct tsocket_context **new_sock,
60 const char *location);
61 #define tsocket_accept(sock, mem_ctx, new_sock) \
62 _tsocket_accept(sock, mem_ctx, new_sock, __location__)
64 ssize_t tsocket_pending(struct tsocket_context *sock);
66 int tsocket_readv(struct tsocket_context *sock,
67 const struct iovec *vector, size_t count);
68 int tsocket_writev(struct tsocket_context *sock,
69 const struct iovec *vector, size_t count);
71 ssize_t tsocket_recvfrom(struct tsocket_context *sock,
72 uint8_t *data, size_t len,
74 struct tsocket_address **src_addr);
75 ssize_t tsocket_sendto(struct tsocket_context *sock,
76 const uint8_t *data, size_t len,
77 const struct tsocket_address *dest_addr);
79 int tsocket_get_status(const struct tsocket_context *sock);
81 int _tsocket_get_local_address(const struct tsocket_context *sock,
83 struct tsocket_address **local_addr,
84 const char *location);
85 #define tsocket_get_local_address(sock, mem_ctx, local_addr) \
86 _tsocket_get_local_address(sock, mem_ctx, local_addr, __location__)
87 int _tsocket_get_remote_address(const struct tsocket_context *sock,
89 struct tsocket_address **remote_addr,
90 const char *location);
91 #define tsocket_get_remote_address(sock, mem_ctx, remote_addr) \
92 _tsocket_get_remote_address(sock, mem_ctx, remote_addr, __location__)
94 int tsocket_get_option(const struct tsocket_context *sock,
98 int tsocket_set_option(const struct tsocket_context *sock,
103 void tsocket_disconnect(struct tsocket_context *sock);
105 char *tsocket_address_string(const struct tsocket_address *addr,
106 TALLOC_CTX *mem_ctx);
108 struct tsocket_address *_tsocket_address_copy(const struct tsocket_address *addr,
110 const char *location);
112 #define tsocket_address_copy(addr, mem_ctx) \
113 _tsocket_address_copy(addr, mem_ctx, __location__)
115 int _tsocket_address_create_socket(const struct tsocket_address *addr,
116 enum tsocket_type type,
118 struct tsocket_context **sock,
119 const char *location);
120 #define tsocket_address_create_socket(addr, type, mem_ctx, sock) \
121 _tsocket_address_create_socket(addr, type, mem_ctx, sock,\
125 * tdgram_context related functions
127 struct tevent_req *tdgram_recvfrom_send(TALLOC_CTX *mem_ctx,
128 struct tevent_context *ev,
129 struct tdgram_context *dgram);
130 ssize_t tdgram_recvfrom_recv(struct tevent_req *req,
134 struct tsocket_address **src);
136 struct tevent_req *tdgram_sendto_send(TALLOC_CTX *mem_ctx,
137 struct tevent_context *ev,
138 struct tdgram_context *dgram,
139 const uint8_t *buf, size_t len,
140 const struct tsocket_address *dst);
141 ssize_t tdgram_sendto_recv(struct tevent_req *req,
144 struct tevent_req *tdgram_disconnect_send(TALLOC_CTX *mem_ctx,
145 struct tevent_context *ev,
146 struct tdgram_context *dgram);
147 int tdgram_disconnect_recv(struct tevent_req *req,
151 * BSD sockets: inet, inet6 and unix
154 int _tsocket_address_inet_from_strings(TALLOC_CTX *mem_ctx,
158 struct tsocket_address **_addr,
159 const char *location);
160 #define tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr) \
161 _tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr, \
164 char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
165 TALLOC_CTX *mem_ctx);
166 uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
167 int tsocket_address_inet_set_port(struct tsocket_address *addr,
169 void tsocket_address_inet_set_broadcast(struct tsocket_address *addr,
172 int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
174 struct tsocket_address **_addr,
175 const char *location);
176 #define tsocket_address_unix_from_path(mem_ctx, path, _addr) \
177 _tsocket_address_unix_from_path(mem_ctx, path, _addr, \
179 char *tsocket_address_unix_path(const struct tsocket_address *addr,
180 TALLOC_CTX *mem_ctx);
182 int _tsocket_context_bsd_wrap_existing(TALLOC_CTX *mem_ctx,
183 int fd, bool close_on_disconnect,
184 struct tsocket_context **_sock,
185 const char *location);
186 #define tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock) \
187 _tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock, \
190 int _tdgram_inet_udp_socket(const struct tsocket_address *local,
191 const struct tsocket_address *remote,
193 struct tdgram_context **dgram,
194 const char *location);
195 #define tdgram_inet_udp_socket(local, remote, mem_ctx, dgram) \
196 _tdgram_inet_udp_socket(local, remote, mem_ctx, dgram, __location__)
198 int _tdgram_unix_dgram_socket(const struct tsocket_address *local,
199 const struct tsocket_address *remote,
201 struct tdgram_context **dgram,
202 const char *location);
203 #define tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram) \
204 _tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram, __location__)
210 struct tevent_req *tsocket_recvfrom_send(struct tsocket_context *sock,
211 TALLOC_CTX *mem_ctx);
212 ssize_t tsocket_recvfrom_recv(struct tevent_req *req,
216 struct tsocket_address **src);
218 struct tevent_req *tsocket_sendto_send(struct tsocket_context *sock,
222 const struct tsocket_address *dst);
223 ssize_t tsocket_sendto_recv(struct tevent_req *req, int *perrno);
225 struct tevent_req *tsocket_sendto_queue_send(TALLOC_CTX *mem_ctx,
226 struct tsocket_context *sock,
227 struct tevent_queue *queue,
230 struct tsocket_address *dst);
231 ssize_t tsocket_sendto_queue_recv(struct tevent_req *req, int *perrno);
233 struct tevent_req *tsocket_connect_send(struct tsocket_context *sock,
235 const struct tsocket_address *dst);
236 int tsocket_connect_recv(struct tevent_req *req, int *perrno);
238 struct tevent_req *tsocket_writev_send(struct tsocket_context *sock,
240 const struct iovec *vector,
242 int tsocket_writev_recv(struct tevent_req *req, int *perrno);
244 struct tevent_req *tsocket_writev_queue_send(TALLOC_CTX *mem_ctx,
245 struct tsocket_context *sock,
246 struct tevent_queue *queue,
247 const struct iovec *vector,
249 int tsocket_writev_queue_recv(struct tevent_req *req, int *perrno);
251 typedef int (*tsocket_readv_next_iovec_t)(struct tsocket_context *sock,
254 struct iovec **vector,
256 struct tevent_req *tsocket_readv_send(struct tsocket_context *sock,
258 tsocket_readv_next_iovec_t next_iovec_fn,
260 int tsocket_readv_recv(struct tevent_req *req, int *perrno);
262 #endif /* _TSOCKET_H */