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,
40 typedef void (*tsocket_event_handler_t
)(struct tsocket_context
*, void *);
41 int tsocket_set_event_context(struct tsocket_context
*sock
,
42 struct tevent_context
*ev
);
43 int tsocket_set_readable_handler(struct tsocket_context
*sock
,
44 tsocket_event_handler_t handler
,
46 int tsocket_set_writeable_handler(struct tsocket_context
*sock
,
47 tsocket_event_handler_t handler
,
50 int tsocket_connect(struct tsocket_context
*sock
,
51 const struct tsocket_address
*remote_addr
);
53 int tsocket_listen(struct tsocket_context
*sock
,
56 int _tsocket_accept(struct tsocket_context
*sock
,
58 struct tsocket_context
**new_sock
,
59 const char *location
);
60 #define tsocket_accept(sock, mem_ctx, new_sock) \
61 _tsocket_accept(sock, mem_ctx, new_sock, __location__)
63 ssize_t
tsocket_pending(struct tsocket_context
*sock
);
65 int tsocket_readv(struct tsocket_context
*sock
,
66 const struct iovec
*vector
, size_t count
);
67 int tsocket_writev(struct tsocket_context
*sock
,
68 const struct iovec
*vector
, size_t count
);
70 int tsocket_get_status(const struct tsocket_context
*sock
);
72 int _tsocket_get_local_address(const struct tsocket_context
*sock
,
74 struct tsocket_address
**local_addr
,
75 const char *location
);
76 #define tsocket_get_local_address(sock, mem_ctx, local_addr) \
77 _tsocket_get_local_address(sock, mem_ctx, local_addr, __location__)
78 int _tsocket_get_remote_address(const struct tsocket_context
*sock
,
80 struct tsocket_address
**remote_addr
,
81 const char *location
);
82 #define tsocket_get_remote_address(sock, mem_ctx, remote_addr) \
83 _tsocket_get_remote_address(sock, mem_ctx, remote_addr, __location__)
85 int tsocket_get_option(const struct tsocket_context
*sock
,
89 int tsocket_set_option(const struct tsocket_context
*sock
,
94 void tsocket_disconnect(struct tsocket_context
*sock
);
96 char *tsocket_address_string(const struct tsocket_address
*addr
,
99 struct tsocket_address
*_tsocket_address_copy(const struct tsocket_address
*addr
,
101 const char *location
);
103 #define tsocket_address_copy(addr, mem_ctx) \
104 _tsocket_address_copy(addr, mem_ctx, __location__)
106 int _tsocket_address_create_socket(const struct tsocket_address
*addr
,
107 enum tsocket_type type
,
109 struct tsocket_context
**sock
,
110 const char *location
);
111 #define tsocket_address_create_socket(addr, type, mem_ctx, sock) \
112 _tsocket_address_create_socket(addr, type, mem_ctx, sock,\
116 * tdgram_context related functions
118 struct tevent_req
*tdgram_recvfrom_send(TALLOC_CTX
*mem_ctx
,
119 struct tevent_context
*ev
,
120 struct tdgram_context
*dgram
);
121 ssize_t
tdgram_recvfrom_recv(struct tevent_req
*req
,
125 struct tsocket_address
**src
);
127 struct tevent_req
*tdgram_sendto_send(TALLOC_CTX
*mem_ctx
,
128 struct tevent_context
*ev
,
129 struct tdgram_context
*dgram
,
130 const uint8_t *buf
, size_t len
,
131 const struct tsocket_address
*dst
);
132 ssize_t
tdgram_sendto_recv(struct tevent_req
*req
,
135 struct tevent_req
*tdgram_disconnect_send(TALLOC_CTX
*mem_ctx
,
136 struct tevent_context
*ev
,
137 struct tdgram_context
*dgram
);
138 int tdgram_disconnect_recv(struct tevent_req
*req
,
142 * BSD sockets: inet, inet6 and unix
145 int _tsocket_address_inet_from_strings(TALLOC_CTX
*mem_ctx
,
149 struct tsocket_address
**_addr
,
150 const char *location
);
151 #define tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr) \
152 _tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr, \
155 char *tsocket_address_inet_addr_string(const struct tsocket_address
*addr
,
156 TALLOC_CTX
*mem_ctx
);
157 uint16_t tsocket_address_inet_port(const struct tsocket_address
*addr
);
158 int tsocket_address_inet_set_port(struct tsocket_address
*addr
,
160 void tsocket_address_inet_set_broadcast(struct tsocket_address
*addr
,
163 int _tsocket_address_unix_from_path(TALLOC_CTX
*mem_ctx
,
165 struct tsocket_address
**_addr
,
166 const char *location
);
167 #define tsocket_address_unix_from_path(mem_ctx, path, _addr) \
168 _tsocket_address_unix_from_path(mem_ctx, path, _addr, \
170 char *tsocket_address_unix_path(const struct tsocket_address
*addr
,
171 TALLOC_CTX
*mem_ctx
);
173 int _tsocket_context_bsd_wrap_existing(TALLOC_CTX
*mem_ctx
,
174 int fd
, bool close_on_disconnect
,
175 struct tsocket_context
**_sock
,
176 const char *location
);
177 #define tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock) \
178 _tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock, \
181 int _tdgram_inet_udp_socket(const struct tsocket_address
*local
,
182 const struct tsocket_address
*remote
,
184 struct tdgram_context
**dgram
,
185 const char *location
);
186 #define tdgram_inet_udp_socket(local, remote, mem_ctx, dgram) \
187 _tdgram_inet_udp_socket(local, remote, mem_ctx, dgram, __location__)
189 int _tdgram_unix_dgram_socket(const struct tsocket_address
*local
,
190 const struct tsocket_address
*remote
,
192 struct tdgram_context
**dgram
,
193 const char *location
);
194 #define tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram) \
195 _tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram, __location__)
201 struct tevent_req
*tsocket_connect_send(struct tsocket_context
*sock
,
203 const struct tsocket_address
*dst
);
204 int tsocket_connect_recv(struct tevent_req
*req
, int *perrno
);
206 struct tevent_req
*tsocket_writev_send(struct tsocket_context
*sock
,
208 const struct iovec
*vector
,
210 int tsocket_writev_recv(struct tevent_req
*req
, int *perrno
);
212 struct tevent_req
*tsocket_writev_queue_send(TALLOC_CTX
*mem_ctx
,
213 struct tsocket_context
*sock
,
214 struct tevent_queue
*queue
,
215 const struct iovec
*vector
,
217 int tsocket_writev_queue_recv(struct tevent_req
*req
, int *perrno
);
219 typedef int (*tsocket_readv_next_iovec_t
)(struct tsocket_context
*sock
,
222 struct iovec
**vector
,
224 struct tevent_req
*tsocket_readv_send(struct tsocket_context
*sock
,
226 tsocket_readv_next_iovec_t next_iovec_fn
,
228 int tsocket_readv_recv(struct tevent_req
*req
, int *perrno
);
234 struct tevent_req
*tdgram_sendto_queue_send(TALLOC_CTX
*mem_ctx
,
235 struct tevent_context
*ev
,
236 struct tdgram_context
*dgram
,
237 struct tevent_queue
*queue
,
240 struct tsocket_address
*dst
);
241 ssize_t
tdgram_sendto_queue_recv(struct tevent_req
*req
, int *perrno
);
243 #endif /* _TSOCKET_H */