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/>.
24 #ifndef _TSOCKET_INTERNAL_H
25 #define _TSOCKET_INTERNAL_H
27 struct tsocket_context_ops {
31 int (*set_event_context)(struct tsocket_context *sock,
32 struct tevent_context *ev);
33 int (*set_read_handler)(struct tsocket_context *sock,
34 tsocket_event_handler_t handler,
36 int (*set_write_handler)(struct tsocket_context *sock,
37 tsocket_event_handler_t handler,
41 int (*connect_to)(struct tsocket_context *sock,
42 const struct tsocket_address *remote_addr);
45 int (*listen_on)(struct tsocket_context *sock,
47 int (*accept_new)(struct tsocket_context *sock,
49 struct tsocket_context **new_sock,
50 const char *location);
53 ssize_t (*pending_data)(struct tsocket_context *sock);
55 int (*readv_data)(struct tsocket_context *sock,
56 const struct iovec *vector, size_t count);
57 int (*writev_data)(struct tsocket_context *sock,
58 const struct iovec *vector, size_t count);
60 ssize_t (*recvfrom_data)(struct tsocket_context *sock,
61 uint8_t *data, size_t len,
63 struct tsocket_address **remote_addr);
64 ssize_t (*sendto_data)(struct tsocket_context *sock,
65 const uint8_t *data, size_t len,
66 const struct tsocket_address *remote_addr);
69 int (*get_status)(const struct tsocket_context *sock);
70 int (*get_local_address)(const struct tsocket_context *sock,
72 struct tsocket_address **local_addr,
73 const char *location);
74 int (*get_remote_address)(const struct tsocket_context *sock,
76 struct tsocket_address **remote_addr,
77 const char *location);
80 int (*get_option)(const struct tsocket_context *sock,
84 int (*set_option)(const struct tsocket_context *sock,
89 /* close/disconnect */
90 void (*disconnect)(struct tsocket_context *sock);
93 struct tsocket_context {
95 const struct tsocket_context_ops *ops;
100 struct tevent_context *ctx;
102 tsocket_event_handler_t read_handler;
104 tsocket_event_handler_t write_handler;
108 struct tsocket_context *_tsocket_context_create(TALLOC_CTX *mem_ctx,
109 const struct tsocket_context_ops *ops,
113 const char *location);
114 #define tsocket_context_create(mem_ctx, ops, state, type, location) \
115 _tsocket_context_create(mem_ctx, ops, state, sizeof(type), \
118 struct tsocket_address_ops {
121 char *(*string)(const struct tsocket_address *addr,
122 TALLOC_CTX *mem_ctx);
124 struct tsocket_address *(*copy)(const struct tsocket_address *addr,
126 const char *location);
128 int (*create_socket)(const struct tsocket_address *addr,
131 struct tsocket_context **sock,
132 const char *location);
135 struct tsocket_address {
136 const char *location;
137 const struct tsocket_address_ops *ops;
142 struct tsocket_address *_tsocket_address_create(TALLOC_CTX *mem_ctx,
143 const struct tsocket_address_ops *ops,
147 const char *location);
148 #define tsocket_address_create(mem_ctx, ops, state, type, location) \
149 _tsocket_address_create(mem_ctx, ops, state, sizeof(type), \
152 struct tdgram_context_ops {
155 struct tevent_req *(*recvfrom_send)(TALLOC_CTX *mem_ctx,
156 struct tevent_context *ev,
157 struct tdgram_context *dgram);
158 ssize_t (*recvfrom_recv)(struct tevent_req *req,
162 struct tsocket_address **src);
164 struct tevent_req *(*sendto_send)(TALLOC_CTX *mem_ctx,
165 struct tevent_context *ev,
166 struct tdgram_context *dgram,
167 const uint8_t *buf, size_t len,
168 const struct tsocket_address *dst);
169 ssize_t (*sendto_recv)(struct tevent_req *req,
172 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
173 struct tevent_context *ev,
174 struct tdgram_context *dgram);
175 int (*disconnect_recv)(struct tevent_req *req,
179 struct tdgram_context *_tdgram_context_create(TALLOC_CTX *mem_ctx,
180 const struct tdgram_context_ops *ops,
184 const char *location);
185 #define tdgram_context_create(mem_ctx, ops, state, type, location) \
186 _tdgram_context_create(mem_ctx, ops, state, sizeof(type), \
189 void *_tdgram_context_data(struct tdgram_context *dgram);
190 #define tdgram_context_data(_req, _type) \
191 talloc_get_type_abort(_tdgram_context_data(_req), _type)
193 int tsocket_error_from_errno(int ret, int sys_errno, bool *retry);
194 int tsocket_simple_int_recv(struct tevent_req *req, int *perrno);
195 int tsocket_common_prepare_fd(int fd, bool high_fd);
197 #endif /* _TSOCKET_H */