globus_xio 6.6
Loading...
Searching...
No Matches
globus_xio_system.h
1/*
2 * Copyright 1999-2006 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
21#ifndef GLOBUS_XIO_SYSTEM_INCLUDE
22#define GLOBUS_XIO_SYSTEM_INCLUDE
23
24#include "globus_common.h"
25#include "globus_xio_types.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#define GLOBUS_XIO_SYSTEM_MODULE (&globus_i_xio_system_module)
32extern globus_module_descriptor_t globus_i_xio_system_module;
33
34#ifdef WIN32
35
36#include <windows.h>
37#include <winsock2.h>
38#define GLOBUS_XIO_SYSTEM_INVALID_FILE INVALID_HANDLE_VALUE
39#define GLOBUS_XIO_SYSTEM_INVALID_SOCKET INVALID_SOCKET
40
41typedef struct globus_l_xio_win32_file_s * globus_xio_system_file_handle_t;
42typedef struct globus_l_xio_win32_socket_s * globus_xio_system_socket_handle_t;
43
44typedef SOCKET globus_xio_system_socket_t;
45typedef HANDLE globus_xio_system_file_t;
46
47#else
48
49#define GLOBUS_XIO_SYSTEM_INVALID_FILE -1
50#define GLOBUS_XIO_SYSTEM_INVALID_SOCKET -1
51
52/* these are handles to this interface */
53typedef struct globus_l_xio_system_s * globus_xio_system_file_handle_t;
54typedef struct globus_l_xio_system_s * globus_xio_system_socket_handle_t;
55
56/* these are the native descriptor types */
57typedef int globus_xio_system_socket_t;
58typedef int globus_xio_system_file_t;
59
60/* deprecated, do not use! */
61typedef int globus_xio_system_native_handle_t;
62#endif
63
64typedef enum
65{
66 GLOBUS_XIO_SYSTEM_ERROR_SYSTEM_ERROR = 1024,
67 GLOBUS_XIO_SYSTEM_ERROR_TOO_MANY_FDS,
68 GLOBUS_XIO_SYSTEM_ERROR_ALREADY_REGISTERED,
69 GLOBUS_XIO_SYSTEM_ERROR_OPERATION_CANCELED,
70 GLOBUS_XIO_SYSTEM_ERROR_NOT_REGISTERED
71} globus_xio_system_error_type_t;
72
73typedef enum
74{
75 GLOBUS_XIO_SYSTEM_FILE = 1,
76 GLOBUS_XIO_SYSTEM_TCP,
77 GLOBUS_XIO_SYSTEM_TCP_LISTENER,
78 GLOBUS_XIO_SYSTEM_UDP
79} globus_xio_system_type_t;
80
81typedef void
82(*globus_xio_system_callback_t)(
83 globus_result_t result,
84 void * user_arg);
85
86typedef void
87(*globus_xio_system_data_callback_t)(
88 globus_result_t result,
89 globus_size_t nbytes,
90 void * user_arg);
91
100globus_result_t
101globus_xio_system_file_init(
102 globus_xio_system_file_handle_t * handle,
103 globus_xio_system_file_t fd);
104
105/* this does *not* close the native handle.
106 * It should remove the non-blocking setting
107 *
108 * do not call this with outstanding operations. you can call it from with
109 * a callback
110 */
111void
112globus_xio_system_file_destroy(
113 globus_xio_system_file_handle_t handle);
114
115globus_result_t
116globus_xio_system_file_register_read(
117 globus_xio_operation_t op,
118 globus_xio_system_file_handle_t handle,
119 globus_off_t offset,
120 const globus_xio_iovec_t * iov,
121 int iovc,
122 globus_size_t waitforbytes,
123 globus_xio_system_data_callback_t callback,
124 void * user_arg);
125
126globus_result_t
127globus_xio_system_file_register_write(
128 globus_xio_operation_t op,
129 globus_xio_system_file_handle_t handle,
130 globus_off_t offset,
131 const globus_xio_iovec_t * iov,
132 int iovc,
133 globus_size_t waitforbytes,
134 globus_xio_system_data_callback_t callback,
135 void * user_arg);
136
137/* pass 0 for waitforbytes to not block */
138globus_result_t
139globus_xio_system_file_read(
140 globus_xio_system_file_handle_t handle,
141 globus_off_t offset,
142 const globus_xio_iovec_t * iov,
143 int iovc,
144 globus_size_t waitforbytes,
145 globus_size_t * nbytes);
146
147globus_result_t
148globus_xio_system_file_write(
149 globus_xio_system_file_handle_t handle,
150 globus_off_t offset,
151 const globus_xio_iovec_t * iov,
152 int iovc,
153 globus_size_t waitforbytes,
154 globus_size_t * nbytes);
155
156/* syscall abstractions */
157globus_off_t
158globus_xio_system_file_get_position(
159 globus_xio_system_file_t fd);
160
161globus_off_t
162globus_xio_system_file_get_size(
163 globus_xio_system_file_t fd);
164
165globus_xio_system_file_t
166globus_xio_system_convert_stdio(
167 const char * stdio);
168
169globus_result_t
170globus_xio_system_file_truncate(
171 globus_xio_system_file_t fd,
172 globus_off_t size);
173
174globus_result_t
175globus_xio_system_file_open(
176 globus_xio_system_file_t * fd,
177 const char * filename,
178 int flags,
179 unsigned long mode);
180
181globus_result_t
182globus_xio_system_file_close(
183 globus_xio_system_file_t fd);
184
190globus_result_t
191globus_xio_system_socket_init(
192 globus_xio_system_socket_handle_t * handle,
193 globus_xio_system_socket_t socket,
194 globus_xio_system_type_t type);
195
196/* this does *not* close the native handle.
197 * It should remove the non-blocking setting
198 *
199 * do not call this with outstanding operations. you can call it from with
200 * a callback
201 */
202void
203globus_xio_system_socket_destroy(
204 globus_xio_system_socket_handle_t handle);
205
206globus_result_t
207globus_xio_system_socket_register_connect(
208 globus_xio_operation_t op,
209 globus_xio_system_socket_handle_t handle,
210 globus_sockaddr_t * addr,
211 globus_xio_system_callback_t callback,
212 void * user_arg);
213
214globus_result_t
215globus_xio_system_socket_register_accept(
216 globus_xio_operation_t op,
217 globus_xio_system_socket_handle_t listener_handle,
218 globus_xio_system_socket_t * out_handle,
219 globus_xio_system_callback_t callback,
220 void * user_arg);
221
222/* if using from, probably want waitforbytes to be 1 */
223/* if waitforbytes == 0 and iov[0].iov_len == 0
224 * behave like select()... ie notify when data ready
225 */
226globus_result_t
227globus_xio_system_socket_register_read(
228 globus_xio_operation_t op,
229 globus_xio_system_socket_handle_t handle,
230 const globus_xio_iovec_t * iov,
231 int iovc,
232 globus_size_t waitforbytes,
233 int flags,
234 globus_sockaddr_t * out_from,
235 globus_xio_system_data_callback_t callback,
236 void * user_arg);
237
238/* if waitforbytes == 0 and iov[0].iov_len == 0
239 * behave like select()... ie notify when data ready
240 */
241globus_result_t
242globus_xio_system_socket_register_write(
243 globus_xio_operation_t op,
244 globus_xio_system_socket_handle_t handle,
245 const globus_xio_iovec_t * iov,
246 int iovc,
247 globus_size_t waitforbytes,
248 int flags,
249 globus_sockaddr_t * to,
250 globus_xio_system_data_callback_t callback,
251 void * user_arg);
252
253/* if waitforbytes == 0, do a non-blocking read */
254globus_result_t
255globus_xio_system_socket_read(
256 globus_xio_system_socket_handle_t handle,
257 const globus_xio_iovec_t * iov,
258 int iovc,
259 globus_size_t waitforbytes,
260 int flags,
261 globus_sockaddr_t * from,
262 globus_size_t * nbytes);
263
264/* if waitforbytes == 0, do a non-blocking write */
265globus_result_t
266globus_xio_system_socket_write(
267 globus_xio_system_socket_handle_t handle,
268 const globus_xio_iovec_t * iov,
269 int iovc,
270 globus_size_t waitforbytes,
271 int flags,
272 globus_sockaddr_t * to,
273 globus_size_t * nbytes);
274
275/* syscall abstractions */
276globus_result_t
277globus_xio_system_socket_create(
278 globus_xio_system_socket_t * socket,
279 int domain,
280 int type,
281 int protocol);
282
283globus_result_t
284globus_xio_system_socket_setsockopt(
285 globus_xio_system_socket_t socket,
286 int level,
287 int optname,
288 const void * optval,
289 globus_socklen_t optlen);
290
291globus_result_t
292globus_xio_system_socket_getsockopt(
293 globus_xio_system_socket_t socket,
294 int level,
295 int optname,
296 void * optval,
297 globus_socklen_t * optlen);
298
299globus_result_t
300globus_xio_system_socket_getsockname(
301 globus_xio_system_socket_t socket,
302 struct sockaddr * name,
303 globus_socklen_t * namelen);
304
305globus_result_t
306globus_xio_system_socket_getpeername(
307 globus_xio_system_socket_t socket,
308 struct sockaddr * name,
309 globus_socklen_t * namelen);
310
311globus_result_t
312globus_xio_system_socket_bind(
313 globus_xio_system_socket_t socket,
314 struct sockaddr * addr,
315 globus_socklen_t addrlen);
316
317globus_result_t
318globus_xio_system_socket_listen(
319 globus_xio_system_socket_t socket,
320 int backlog);
321
322globus_result_t
323globus_xio_system_socket_connect(
324 globus_xio_system_socket_t socket,
325 const struct sockaddr * addr,
326 globus_socklen_t addrlen);
327
328globus_result_t
329globus_xio_system_socket_close(
330 globus_xio_system_socket_t socket);
331
332#ifdef WIN32
333
340#undef S_IRWXU
341#define S_IRWXU 0
342#undef S_IRUSR
343#define S_IRUSR 0
344#undef S_IWUSR
345#define S_IWUSR 0
346#undef S_IXUSR
347#define S_IXUSR 0
348#undef S_IRWXO
349#define S_IRWXO 0
350#undef S_IROTH
351#define S_IROTH 0
352#undef S_IWOTH
353#define S_IWOTH 0
354#undef S_IXOTH
355#define S_IXOTH 0
356#undef S_IRWXG
357#define S_IRWXG 0
358#undef S_IRGRP
359#define S_IRGRP 0
360#undef S_IWGRP
361#define S_IWGRP 0
362#undef S_IXGRP
363#define S_IXGRP 0
364
365#endif
366
367#ifdef __cplusplus
368}
369#endif
370
371#endif