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;
35 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 ssize_t tsocket_recvfrom(struct tsocket_context *sock,
71 uint8_t *data, size_t len,
73 struct tsocket_address **src_addr);
74 ssize_t tsocket_sendto(struct tsocket_context *sock,
75 const uint8_t *data, size_t len,
76 const struct tsocket_address *dest_addr);
78 int tsocket_get_status(const struct tsocket_context *sock);
80 int _tsocket_get_local_address(const struct tsocket_context *sock,
82 struct tsocket_address **local_addr,
83 const char *location);
84 #define tsocket_get_local_address(sock, mem_ctx, local_addr) \
85 _tsocket_get_local_address(sock, mem_ctx, local_addr, __location__)
86 int _tsocket_get_remote_address(const struct tsocket_context *sock,
88 struct tsocket_address **remote_addr,
89 const char *location);
90 #define tsocket_get_remote_address(sock, mem_ctx, remote_addr) \
91 _tsocket_get_remote_address(sock, mem_ctx, remote_addr, __location__)
93 int tsocket_get_option(const struct tsocket_context *sock,
97 int tsocket_set_option(const struct tsocket_context *sock,
102 void tsocket_disconnect(struct tsocket_context *sock);
104 char *tsocket_address_string(const struct tsocket_address *addr,
105 TALLOC_CTX *mem_ctx);
107 struct tsocket_address *_tsocket_address_copy(const struct tsocket_address *addr,
109 const char *location);
111 #define tsocket_address_copy(addr, mem_ctx) \
112 _tsocket_address_copy(addr, mem_ctx, __location__)
114 int _tsocket_address_create_socket(const struct tsocket_address *addr,
115 enum tsocket_type type,
117 struct tsocket_context **sock,
118 const char *location);
119 #define tsocket_address_create_socket(addr, type, mem_ctx, sock) \
120 _tsocket_address_create_socket(addr, type, mem_ctx, sock,\
124 * BSD sockets: inet, inet6 and unix
127 int _tsocket_address_inet_from_strings(TALLOC_CTX *mem_ctx,
131 struct tsocket_address **_addr,
132 const char *location);
133 #define tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr) \
134 _tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr, \
137 char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
138 TALLOC_CTX *mem_ctx);
139 uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
140 int tsocket_address_inet_set_port(struct tsocket_address *addr,
142 void tsocket_address_inet_set_broadcast(struct tsocket_address *addr,
145 int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
147 struct tsocket_address **_addr,
148 const char *location);
149 #define tsocket_address_unix_from_path(mem_ctx, path, _addr) \
150 _tsocket_address_unix_from_path(mem_ctx, path, _addr, \
152 char *tsocket_address_unix_path(const struct tsocket_address *addr,
153 TALLOC_CTX *mem_ctx);
155 int _tsocket_context_bsd_wrap_existing(TALLOC_CTX *mem_ctx,
156 int fd, bool close_on_disconnect,
157 struct tsocket_context **_sock,
158 const char *location);
159 #define tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock) \
160 _tsocket_context_bsd_wrap_existing(mem_ctx, fd, cod, _sock, \
167 struct tevent_req *tsocket_recvfrom_send(struct tsocket_context *sock,
168 TALLOC_CTX *mem_ctx);
169 ssize_t tsocket_recvfrom_recv(struct tevent_req *req,
173 struct tsocket_address **src);
175 struct tevent_req *tsocket_sendto_send(struct tsocket_context *sock,
179 const struct tsocket_address *dst);
180 ssize_t tsocket_sendto_recv(struct tevent_req *req, int *perrno);
182 struct tevent_req *tsocket_sendto_queue_send(TALLOC_CTX *mem_ctx,
183 struct tsocket_context *sock,
184 struct tevent_queue *queue,
187 struct tsocket_address *dst);
188 ssize_t tsocket_sendto_queue_recv(struct tevent_req *req, int *perrno);
190 struct tevent_req *tsocket_connect_send(struct tsocket_context *sock,
192 const struct tsocket_address *dst);
193 int tsocket_connect_recv(struct tevent_req *req, int *perrno);
195 struct tevent_req *tsocket_writev_send(struct tsocket_context *sock,
197 const struct iovec *vector,
199 int tsocket_writev_recv(struct tevent_req *req, int *perrno);
201 struct tevent_req *tsocket_writev_queue_send(TALLOC_CTX *mem_ctx,
202 struct tsocket_context *sock,
203 struct tevent_queue *queue,
204 const struct iovec *vector,
206 int tsocket_writev_queue_recv(struct tevent_req *req, int *perrno);
208 #endif /* _TSOCKET_H */