s3/libsmb: Fix debug message.
[Samba/gebeck_regimport.git] / lib / tsocket / tsocket.h
blob8b0c80becf025ac8e4d071394df2ca383909bed0
1 /*
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
8 ** under the LGPL
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/>.
24 #ifndef _TSOCKET_H
25 #define _TSOCKET_H
27 #include <talloc.h>
28 #include <tevent.h>
30 struct tsocket_address;
31 struct tdgram_context;
32 struct tstream_context;
33 struct iovec;
36 * tsocket_address related functions
38 char *tsocket_address_string(const struct tsocket_address *addr,
39 TALLOC_CTX *mem_ctx);
41 struct tsocket_address *_tsocket_address_copy(const struct tsocket_address *addr,
42 TALLOC_CTX *mem_ctx,
43 const char *location);
45 #define tsocket_address_copy(addr, mem_ctx) \
46 _tsocket_address_copy(addr, mem_ctx, __location__)
49 * tdgram_context related functions
51 struct tevent_req *tdgram_recvfrom_send(TALLOC_CTX *mem_ctx,
52 struct tevent_context *ev,
53 struct tdgram_context *dgram);
54 ssize_t tdgram_recvfrom_recv(struct tevent_req *req,
55 int *perrno,
56 TALLOC_CTX *mem_ctx,
57 uint8_t **buf,
58 struct tsocket_address **src);
60 struct tevent_req *tdgram_sendto_send(TALLOC_CTX *mem_ctx,
61 struct tevent_context *ev,
62 struct tdgram_context *dgram,
63 const uint8_t *buf, size_t len,
64 const struct tsocket_address *dst);
65 ssize_t tdgram_sendto_recv(struct tevent_req *req,
66 int *perrno);
68 struct tevent_req *tdgram_disconnect_send(TALLOC_CTX *mem_ctx,
69 struct tevent_context *ev,
70 struct tdgram_context *dgram);
71 int tdgram_disconnect_recv(struct tevent_req *req,
72 int *perrno);
75 * tstream_context related functions
77 ssize_t tstream_pending_bytes(struct tstream_context *stream);
79 struct tevent_req *tstream_readv_send(TALLOC_CTX *mem_ctx,
80 struct tevent_context *ev,
81 struct tstream_context *stream,
82 struct iovec *vector,
83 size_t count);
84 int tstream_readv_recv(struct tevent_req *req,
85 int *perrno);
87 struct tevent_req *tstream_writev_send(TALLOC_CTX *mem_ctx,
88 struct tevent_context *ev,
89 struct tstream_context *stream,
90 const struct iovec *vector,
91 size_t count);
92 int tstream_writev_recv(struct tevent_req *req,
93 int *perrno);
95 struct tevent_req *tstream_disconnect_send(TALLOC_CTX *mem_ctx,
96 struct tevent_context *ev,
97 struct tstream_context *stream);
98 int tstream_disconnect_recv(struct tevent_req *req,
99 int *perrno);
102 * BSD sockets: inet, inet6 and unix
105 int _tsocket_address_inet_from_strings(TALLOC_CTX *mem_ctx,
106 const char *fam,
107 const char *addr,
108 uint16_t port,
109 struct tsocket_address **_addr,
110 const char *location);
111 #define tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr) \
112 _tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr, \
113 __location__)
115 char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
116 TALLOC_CTX *mem_ctx);
117 uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
118 int tsocket_address_inet_set_port(struct tsocket_address *addr,
119 uint16_t port);
120 void tsocket_address_inet_set_broadcast(struct tsocket_address *addr,
121 bool broadcast);
123 int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
124 const char *path,
125 struct tsocket_address **_addr,
126 const char *location);
127 #define tsocket_address_unix_from_path(mem_ctx, path, _addr) \
128 _tsocket_address_unix_from_path(mem_ctx, path, _addr, \
129 __location__)
130 char *tsocket_address_unix_path(const struct tsocket_address *addr,
131 TALLOC_CTX *mem_ctx);
133 int _tdgram_inet_udp_socket(const struct tsocket_address *local,
134 const struct tsocket_address *remote,
135 TALLOC_CTX *mem_ctx,
136 struct tdgram_context **dgram,
137 const char *location);
138 #define tdgram_inet_udp_socket(local, remote, mem_ctx, dgram) \
139 _tdgram_inet_udp_socket(local, remote, mem_ctx, dgram, __location__)
141 int _tdgram_unix_socket(const struct tsocket_address *local,
142 const struct tsocket_address *remote,
143 TALLOC_CTX *mem_ctx,
144 struct tdgram_context **dgram,
145 const char *location);
146 #define tdgram_unix_socket(local, remote, mem_ctx, dgram) \
147 _tdgram_unix_socket(local, remote, mem_ctx, dgram, __location__)
149 struct tevent_req * tstream_inet_tcp_connect_send(TALLOC_CTX *mem_ctx,
150 struct tevent_context *ev,
151 const struct tsocket_address *local,
152 const struct tsocket_address *remote);
153 int _tstream_inet_tcp_connect_recv(struct tevent_req *req,
154 int *perrno,
155 TALLOC_CTX *mem_ctx,
156 struct tstream_context **stream,
157 const char *location);
158 #define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream) \
159 _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, \
160 __location__)
162 struct tevent_req * tstream_unix_connect_send(TALLOC_CTX *mem_ctx,
163 struct tevent_context *ev,
164 const struct tsocket_address *local,
165 const struct tsocket_address *remote);
166 int _tstream_unix_connect_recv(struct tevent_req *req,
167 int *perrno,
168 TALLOC_CTX *mem_ctx,
169 struct tstream_context **stream,
170 const char *location);
171 #define tstream_unix_connect_recv(req, perrno, mem_ctx, stream) \
172 _tstream_unix_connect_recv(req, perrno, mem_ctx, stream, \
173 __location__)
175 int _tstream_unix_socketpair(TALLOC_CTX *mem_ctx1,
176 struct tstream_context **_stream1,
177 TALLOC_CTX *mem_ctx2,
178 struct tstream_context **_stream2,
179 const char *location);
180 #define tstream_unix_socketpair(mem_ctx1, stream1, mem_ctx2, stream2) \
181 _tstream_unix_socketpair(mem_ctx1, stream1, mem_ctx2, stream2, \
182 __location__)
184 int _tstream_bsd_existing_socket(TALLOC_CTX *mem_ctx,
185 int fd,
186 struct tstream_context **_stream,
187 const char *location);
188 #define tstream_bsd_existing_socket(mem_ctx, fd, stream) \
189 _tstream_bsd_existing_socket(mem_ctx, fd, stream, \
190 __location__)
193 * Queue and PDU helpers
196 struct tevent_req *tdgram_sendto_queue_send(TALLOC_CTX *mem_ctx,
197 struct tevent_context *ev,
198 struct tdgram_context *dgram,
199 struct tevent_queue *queue,
200 const uint8_t *buf,
201 size_t len,
202 struct tsocket_address *dst);
203 ssize_t tdgram_sendto_queue_recv(struct tevent_req *req, int *perrno);
205 typedef int (*tstream_readv_pdu_next_vector_t)(struct tstream_context *stream,
206 void *private_data,
207 TALLOC_CTX *mem_ctx,
208 struct iovec **vector,
209 size_t *count);
210 struct tevent_req *tstream_readv_pdu_send(TALLOC_CTX *mem_ctx,
211 struct tevent_context *ev,
212 struct tstream_context *stream,
213 tstream_readv_pdu_next_vector_t next_vector_fn,
214 void *next_vector_private);
215 int tstream_readv_pdu_recv(struct tevent_req *req, int *perrno);
217 struct tevent_req *tstream_readv_pdu_queue_send(TALLOC_CTX *mem_ctx,
218 struct tevent_context *ev,
219 struct tstream_context *stream,
220 struct tevent_queue *queue,
221 tstream_readv_pdu_next_vector_t next_vector_fn,
222 void *next_vector_private);
223 int tstream_readv_pdu_queue_recv(struct tevent_req *req, int *perrno);
225 struct tevent_req *tstream_writev_queue_send(TALLOC_CTX *mem_ctx,
226 struct tevent_context *ev,
227 struct tstream_context *stream,
228 struct tevent_queue *queue,
229 const struct iovec *vector,
230 size_t count);
231 int tstream_writev_queue_recv(struct tevent_req *req, int *perrno);
233 #endif /* _TSOCKET_H */