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);
61 int (*get_status)(const struct tsocket_context *sock);
62 int (*get_local_address)(const struct tsocket_context *sock,
64 struct tsocket_address **local_addr,
65 const char *location);
66 int (*get_remote_address)(const struct tsocket_context *sock,
68 struct tsocket_address **remote_addr,
69 const char *location);
72 int (*get_option)(const struct tsocket_context *sock,
76 int (*set_option)(const struct tsocket_context *sock,
81 /* close/disconnect */
82 void (*disconnect)(struct tsocket_context *sock);
85 struct tsocket_context {
87 const struct tsocket_context_ops *ops;
92 struct tevent_context *ctx;
94 tsocket_event_handler_t read_handler;
96 tsocket_event_handler_t write_handler;
100 struct tsocket_context *_tsocket_context_create(TALLOC_CTX *mem_ctx,
101 const struct tsocket_context_ops *ops,
105 const char *location);
106 #define tsocket_context_create(mem_ctx, ops, state, type, location) \
107 _tsocket_context_create(mem_ctx, ops, state, sizeof(type), \
110 struct tsocket_address_ops {
113 char *(*string)(const struct tsocket_address *addr,
114 TALLOC_CTX *mem_ctx);
116 struct tsocket_address *(*copy)(const struct tsocket_address *addr,
118 const char *location);
120 int (*create_socket)(const struct tsocket_address *addr,
123 struct tsocket_context **sock,
124 const char *location);
127 struct tsocket_address {
128 const char *location;
129 const struct tsocket_address_ops *ops;
134 struct tsocket_address *_tsocket_address_create(TALLOC_CTX *mem_ctx,
135 const struct tsocket_address_ops *ops,
139 const char *location);
140 #define tsocket_address_create(mem_ctx, ops, state, type, location) \
141 _tsocket_address_create(mem_ctx, ops, state, sizeof(type), \
144 struct tdgram_context_ops {
147 struct tevent_req *(*recvfrom_send)(TALLOC_CTX *mem_ctx,
148 struct tevent_context *ev,
149 struct tdgram_context *dgram);
150 ssize_t (*recvfrom_recv)(struct tevent_req *req,
154 struct tsocket_address **src);
156 struct tevent_req *(*sendto_send)(TALLOC_CTX *mem_ctx,
157 struct tevent_context *ev,
158 struct tdgram_context *dgram,
159 const uint8_t *buf, size_t len,
160 const struct tsocket_address *dst);
161 ssize_t (*sendto_recv)(struct tevent_req *req,
164 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
165 struct tevent_context *ev,
166 struct tdgram_context *dgram);
167 int (*disconnect_recv)(struct tevent_req *req,
171 struct tdgram_context *_tdgram_context_create(TALLOC_CTX *mem_ctx,
172 const struct tdgram_context_ops *ops,
176 const char *location);
177 #define tdgram_context_create(mem_ctx, ops, state, type, location) \
178 _tdgram_context_create(mem_ctx, ops, state, sizeof(type), \
181 void *_tdgram_context_data(struct tdgram_context *dgram);
182 #define tdgram_context_data(_req, _type) \
183 talloc_get_type_abort(_tdgram_context_data(_req), _type)
185 int tsocket_error_from_errno(int ret, int sys_errno, bool *retry);
186 int tsocket_simple_int_recv(struct tevent_req *req, int *perrno);
187 int tsocket_common_prepare_fd(int fd, bool high_fd);
189 #endif /* _TSOCKET_H */