globus_xio
6.6
Toggle main menu visibility
Loading...
Searching...
No Matches
globus_xio_util.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
17
#ifndef GLOBUS_XIO_UTIL_INCLUDE
18
#define GLOBUS_XIO_UTIL_INCLUDE
19
20
#include "globus_xio.h"
21
22
#ifdef __cplusplus
23
extern
"C"
{
24
#endif
25
26
globus_bool_t
27
globus_xio_get_env_pair(
28
const
char
* env_name,
29
int
* min,
30
int
* max);
31
32
globus_bool_t
33
globus_xio_error_is_eof(
34
globus_result_t res);
35
36
globus_bool_t
37
globus_xio_error_is_canceled(
38
globus_result_t res);
39
40
globus_bool_t
41
globus_xio_driver_error_match(
42
globus_xio_driver_t driver,
43
globus_object_t * error,
44
int
type);
45
46
globus_bool_t
47
globus_xio_driver_error_match_with_cb(
48
globus_xio_driver_t driver,
49
globus_object_t * error,
50
globus_extension_error_match_cb_t callback,
51
void
* type);
52
53
globus_bool_t
54
globus_xio_error_match(
55
globus_result_t result,
56
int
type);
57
58
void
59
globus_xio_contact_destroy(
60
globus_xio_contact_t * contact_info);
61
62
globus_result_t
63
globus_xio_contact_parse(
64
globus_xio_contact_t * contact_info,
65
const
char
* contact_string);
66
67
globus_result_t
68
globus_xio_contact_info_to_string(
69
const
globus_xio_contact_t * contact_info,
70
char
** contact_string);
71
72
globus_result_t
73
globus_xio_contact_info_to_url(
74
const
globus_xio_contact_t * contact_info,
75
char
** contact_string);
76
77
globus_result_t
78
globus_xio_contact_info_to_encoded_string(
79
const
globus_xio_contact_t * contact_info,
80
const
globus_xio_contact_t * encode_chars,
81
char
** contact_string);
82
83
globus_result_t
84
globus_xio_contact_copy(
85
globus_xio_contact_t * dst,
86
const
globus_xio_contact_t * src);
87
88
/*
89
* Utility macros
90
*/
91
92
/* all macros in this file require each function to 'declare' their name with
93
* this
94
*/
95
#ifdef __GNUC__
96
#define GlobusXIOName(func) static const char * _xio_name __attribute__((__unused__)) = #func
97
#else
98
#define GlobusXIOName(func) static const char * _xio_name = #func
99
#endif
100
101
#define GlobusXIOErrorCanceled() \
102
globus_error_put(GlobusXIOErrorObjCanceled())
103
104
#define GlobusXIOErrorObjCanceled() \
105
globus_error_construct_error( \
106
GLOBUS_XIO_MODULE, \
107
GLOBUS_NULL, \
108
GLOBUS_XIO_ERROR_CANCELED, \
109
__FILE__, \
110
_xio_name, \
111
__LINE__, \
112
_XIOSL("Operation was canceled"))
113
#define GlobusXIOErrorTimeout() \
114
globus_error_put(GlobusXIOErrorObjTimeout())
115
116
#define GlobusXIOErrorObjTimeout() \
117
globus_error_construct_error( \
118
GLOBUS_XIO_MODULE, \
119
GlobusXIOErrorObjTimeoutOnly(), \
120
GLOBUS_XIO_ERROR_CANCELED, \
121
__FILE__, \
122
_xio_name, \
123
__LINE__, \
124
_XIOSL("Operation was canceled"))
125
126
#define GlobusXIOErrorObjTimeoutOnly() \
127
globus_error_construct_error( \
128
GLOBUS_XIO_MODULE, \
129
GLOBUS_NULL, \
130
GLOBUS_XIO_ERROR_TIMEOUT, \
131
__FILE__, \
132
_xio_name, \
133
__LINE__, \
134
_XIOSL("Operation timed out"))
135
136
#define GlobusXIOErrorObjEOF() \
137
globus_error_construct_error( \
138
GLOBUS_XIO_MODULE, \
139
GLOBUS_NULL, \
140
GLOBUS_XIO_ERROR_EOF, \
141
__FILE__, \
142
_xio_name, \
143
__LINE__, \
144
_XIOSL("An end of file occurred"))
145
146
#define GlobusXIOErrorEOF() \
147
globus_error_put( \
148
GlobusXIOErrorObjEOF()) \
149
150
#define GlobusXIOErrorInvalidCommand(cmd_number) \
151
globus_error_put( \
152
globus_error_construct_error( \
153
GLOBUS_XIO_MODULE, \
154
GLOBUS_NULL, \
155
GLOBUS_XIO_ERROR_COMMAND, \
156
__FILE__, \
157
_xio_name, \
158
__LINE__, \
159
_XIOSL("An invalid command (%d) was issued"), \
160
(cmd_number)))
161
162
#define GlobusXIOErrorContactString(reason) \
163
globus_error_put( \
164
globus_error_construct_error( \
165
GLOBUS_XIO_MODULE, \
166
GLOBUS_NULL, \
167
GLOBUS_XIO_ERROR_CONTACT_STRING, \
168
__FILE__, \
169
_xio_name, \
170
__LINE__, \
171
_XIOSL("Contact string invalid. %s"), \
172
(reason)))
173
174
#define GlobusXIOErrorObjParameter(param_name) \
175
globus_error_construct_error( \
176
GLOBUS_XIO_MODULE, \
177
GLOBUS_NULL, \
178
GLOBUS_XIO_ERROR_PARAMETER, \
179
__FILE__, \
180
_xio_name, \
181
__LINE__, \
182
_XIOSL("Bad parameter, %s"), \
183
(param_name))
184
185
#define GlobusXIOErrorParameter(param_name) \
186
globus_error_put( \
187
GlobusXIOErrorObjParameter(param_name))
188
189
#define GlobusXIOErrorObjMemory(mem_name) \
190
globus_error_construct_error( \
191
GLOBUS_XIO_MODULE, \
192
GLOBUS_NULL, \
193
GLOBUS_XIO_ERROR_MEMORY, \
194
__FILE__, \
195
_xio_name, \
196
__LINE__, \
197
_XIOSL("Memory allocation failed on %s"), \
198
(mem_name))
199
200
#define GlobusXIOErrorMemory(mem_name_obj) \
201
globus_error_put( \
202
GlobusXIOErrorObjMemory(mem_name_obj))
203
204
#define GlobusXIOErrorObjSystemError(system_func, _errno) \
205
globus_error_wrap_errno_error( \
206
GLOBUS_XIO_MODULE, \
207
(_errno), \
208
GLOBUS_XIO_ERROR_SYSTEM_ERROR, \
209
__FILE__, \
210
_xio_name, \
211
__LINE__, \
212
_XIOSL("System error in %s"), \
213
(system_func))
214
215
#define GlobusXIOErrorSystemError(system_func, _errno) \
216
globus_error_put( \
217
GlobusXIOErrorObjSystemError(system_func, _errno))
218
219
#define GlobusXIOErrorSystemResource(reason) \
220
globus_error_put( \
221
globus_error_construct_error( \
222
GLOBUS_XIO_MODULE, \
223
GLOBUS_NULL, \
224
GLOBUS_XIO_ERROR_SYSTEM_RESOURCE, \
225
__FILE__, \
226
_xio_name, \
227
__LINE__, \
228
_XIOSL("System resource error, %s"), \
229
(reason)))
230
231
#define GlobusXIOErrorInvalidStack(reason) \
232
globus_error_put( \
233
globus_error_construct_error( \
234
GLOBUS_XIO_MODULE, \
235
GLOBUS_NULL, \
236
GLOBUS_XIO_ERROR_STACK, \
237
__FILE__, \
238
_xio_name, \
239
__LINE__, \
240
_XIOSL("Invalid stack, %s"), \
241
(reason)))
242
243
#define GlobusXIOErrorInvalidDriver(reason) \
244
globus_error_put( \
245
globus_error_construct_error( \
246
GLOBUS_XIO_MODULE, \
247
GLOBUS_NULL, \
248
GLOBUS_XIO_ERROR_DRIVER, \
249
__FILE__, \
250
_xio_name, \
251
__LINE__, \
252
_XIOSL("Invalid Driver, %s"), \
253
(reason)))
254
255
#define GlobusXIOErrorPass() \
256
globus_error_put( \
257
globus_error_construct_error( \
258
GLOBUS_XIO_MODULE, \
259
GLOBUS_NULL, \
260
GLOBUS_XIO_ERROR_PASS, \
261
__FILE__, \
262
_xio_name, \
263
__LINE__, \
264
_XIOSL("Operation passed too far")))
265
266
#define GlobusXIOErrorAlreadyRegistered() \
267
globus_error_put( \
268
globus_error_construct_error( \
269
GLOBUS_XIO_MODULE, \
270
GLOBUS_NULL, \
271
GLOBUS_XIO_ERROR_ALREADY_REGISTERED, \
272
__FILE__, \
273
_xio_name, \
274
__LINE__, \
275
_XIOSL("Operation already registered")))
276
277
#define GlobusXIOErrorInvalidState(state) \
278
globus_error_put( \
279
globus_error_construct_error( \
280
GLOBUS_XIO_MODULE, \
281
GLOBUS_NULL, \
282
GLOBUS_XIO_ERROR_STATE, \
283
__FILE__, \
284
_xio_name, \
285
__LINE__, \
286
_XIOSL("Unexpected state, %d"), \
287
(state)))
288
289
#define GlobusXIOErrorWrapFailed(failed_func, result) \
290
globus_error_put( \
291
globus_error_construct_error( \
292
GLOBUS_XIO_MODULE, \
293
globus_error_get((result)), \
294
GLOBUS_XIO_ERROR_WRAPPED, \
295
__FILE__, \
296
_xio_name, \
297
__LINE__, \
298
_XIOSL("%s failed."), \
299
(failed_func)))
300
301
#define GlobusXIOErrorWrapFailedWithMessage(result, format, arg) \
302
globus_error_put( \
303
globus_error_construct_error( \
304
GLOBUS_XIO_MODULE, \
305
globus_error_get((result)), \
306
GLOBUS_XIO_ERROR_WRAPPED, \
307
__FILE__, \
308
_xio_name, \
309
__LINE__, \
310
(format), \
311
(arg)))
312
313
#define GlobusXIOErrorWrapFailedWithMessage2(result, format, arg1, arg2) \
314
globus_error_put( \
315
globus_error_construct_error( \
316
GLOBUS_XIO_MODULE, \
317
globus_error_get((result)), \
318
GLOBUS_XIO_ERROR_WRAPPED, \
319
__FILE__, \
320
_xio_name, \
321
__LINE__, \
322
(format), \
323
(arg1), (arg2)))
324
325
#define GlobusXIOErrorNotRegistered() \
326
globus_error_put( \
327
globus_error_construct_error( \
328
GLOBUS_XIO_MODULE, \
329
NULL, \
330
GLOBUS_XIO_ERROR_NOT_REGISTERED, \
331
__FILE__, \
332
_xio_name, \
333
__LINE__, \
334
_XIOSL("Not registered.")))
335
336
#define GlobusXIOErrorNotActivated() \
337
globus_error_put( \
338
globus_error_construct_error( \
339
GLOBUS_XIO_MODULE, \
340
NULL, \
341
GLOBUS_XIO_ERROR_NOT_ACTIVATED, \
342
__FILE__, \
343
_xio_name, \
344
__LINE__, \
345
_XIOSL("Module not activated.")))
346
347
#define GlobusXIOErrorUnloaded() \
348
globus_error_put( \
349
globus_error_construct_error( \
350
GLOBUS_XIO_MODULE, \
351
NULL, \
352
GLOBUS_XIO_ERROR_UNLOADED, \
353
__FILE__, \
354
_xio_name, \
355
__LINE__, \
356
_XIOSL("Driver in handle has been unloaded.")))
357
358
#define GlobusXIOErrorParse(arg) \
359
globus_error_put( \
360
globus_error_construct_error( \
361
GLOBUS_XIO_MODULE, \
362
NULL, \
363
GLOBUS_XIO_ERROR_PARSE, \
364
__FILE__, \
365
_xio_name, \
366
__LINE__, \
367
_XIOSL("An error occurred parsing the string: %s"), arg))
368
369
370
#define GlobusIXIOUtilCopyNIovec(iov, iovc, siov, siovc, bytes) \
371
do \
372
{ \
373
globus_size_t _i; \
374
globus_size_t _tb = 0; \
375
globus_size_t _bytes; \
376
const struct iovec * _siov; \
377
struct iovec * _iov; \
378
int _iovc; \
379
int _siovc; \
380
\
381
_siov = (siov); \
382
_siovc = (siovc); \
383
_iov = (iov); \
384
_iovc = (iovc); \
385
_bytes = (bytes); \
386
\
387
for(_i = 0; _i < _siovc && _tb < _bytes; _i++) \
388
{ \
389
if(_tb + _siov[_i].iov_len > _bytes) \
390
{ \
391
_iov[_i].iov_len = _bytes - _tb; \
392
} \
393
else \
394
{ \
395
_iov[_i].iov_len = _siov[_i].iov_len; \
396
} \
397
_tb += _siov[_i].iov_len; \
398
_iov[_i].iov_base = _siov[_i].iov_base; \
399
} \
400
_iovc = _i; \
401
} while(0)
402
403
404
405
#define GlobusIXIOUtilTransferIovec(iov, siov, iovc) \
406
do \
407
{ \
408
int _i; \
409
const struct iovec * _siov; \
410
struct iovec * _iov; \
411
int _iovc; \
412
\
413
_siov = (siov); \
414
_iov = (iov); \
415
_iovc = (iovc); \
416
\
417
for(_i = 0; _i < _iovc; _i++) \
418
{ \
419
_iov[_i].iov_base = _siov[_i].iov_base; \
420
_iov[_i].iov_len = _siov[_i].iov_len; \
421
} \
422
} while(0)
423
424
#define GlobusIXIOUtilAdjustIovec(iov, iovc, nbytes) \
425
do \
426
{ \
427
globus_size_t _n = (nbytes); \
428
\
429
if(_n > 0) \
430
{ \
431
struct iovec * _iov = (iov); \
432
int _iovc = (iovc); \
433
int _i; \
434
\
435
/* skip all completely filled iovecs */
\
436
for(_i = 0; \
437
_i < _iovc && _n >= _iov[_i].iov_len; \
438
_n -= _iov[_i].iov_len, _i++); \
439
\
440
if(_i < _iovc) \
441
{ \
442
_iov[_i].iov_base = (char *) _iov[_i].iov_base + _n; \
443
_iov[_i].iov_len -= _n; \
444
(iov) += _i; \
445
} \
446
\
447
(iovc) -= _i; \
448
} \
449
} while(0)
450
451
#define GlobusIXIOUtilTransferAdjustedIovec( \
452
new_iov, new_iovc, iov, iovc, nbytes) \
453
do \
454
{ \
455
globus_size_t _n; \
456
const struct iovec * _iov; \
457
int _iovc; \
458
struct iovec * _new_iov; \
459
int _i; \
460
int _j; \
461
\
462
_iov = (iov); \
463
_iovc = (iovc); \
464
_new_iov = (new_iov); \
465
\
466
/* skip all completely filled iovecs */
\
467
for(_i = 0, _n = (nbytes); \
468
_i < _iovc && _n >= _iov[_i].iov_len; \
469
_n -= _iov[_i].iov_len, _i++); \
470
\
471
(new_iovc) = _iovc - _i; \
472
if(_i < _iovc) \
473
{ \
474
_new_iov[0].iov_base = (char *) _iov[_i].iov_base + _n; \
475
_new_iov[0].iov_len = _iov[_i].iov_len - _n; \
476
\
477
/* copy remaining */
\
478
for(_j = 1, _i++; _i < _iovc; _j++, _i++) \
479
{ \
480
_new_iov[_j].iov_base = _iov[_i].iov_base; \
481
_new_iov[_j].iov_len = _iov[_i].iov_len; \
482
} \
483
} \
484
} while(0)
485
486
#define GlobusXIOUtilIovTotalLength( \
487
out_len, iov, iovc) \
488
do \
489
{ \
490
int _i; \
491
const struct iovec * _iov; \
492
int _iovc; \
493
globus_size_t _out_len; \
494
_iov = (iov); \
495
_iovc = (iovc); \
496
_out_len = 0; \
497
for(_i = 0; _i < _iovc; _i++) \
498
{ \
499
_out_len += _iov[_i].iov_len; \
500
} \
501
out_len = _out_len; \
502
} while(0)
503
504
#define GlobusXIOUtilIovSerialize( \
505
out_buf, iov, iovc) \
506
do \
507
{ \
508
int _i; \
509
int _ndx = 0; \
510
for(_i = 0; _i < iovc; _i++) \
511
{ \
512
memcpy(&(out_buf)[_ndx], (iov)[_i].iov_base, (iov)[_i].iov_len);\
513
_ndx += (iov)[_i].iov_len; \
514
} \
515
} while(0)
516
517
#ifdef __cplusplus
518
}
519
#endif
520
521
#endif
globus_xio_util.h
Generated by
1.17.0