File: globus_xio_util.h

package info (click to toggle)
globus-xio 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,120 kB
  • sloc: ansic: 46,711; sh: 11,139; perl: 1,598; makefile: 355
file content (521 lines) | stat: -rw-r--r-- 32,583 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*
 * Copyright 1999-2006 University of Chicago
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GLOBUS_XIO_UTIL_INCLUDE
#define GLOBUS_XIO_UTIL_INCLUDE

#include "globus_xio.h"

#ifdef __cplusplus
extern "C" {
#endif

globus_bool_t
globus_xio_get_env_pair(
    const char *                        env_name,
    int *                               min,
    int *                               max);

globus_bool_t
globus_xio_error_is_eof(
    globus_result_t                     res);

globus_bool_t
globus_xio_error_is_canceled(
    globus_result_t                     res);

globus_bool_t
globus_xio_driver_error_match(
    globus_xio_driver_t                 driver,
    globus_object_t *                   error,
    int                                 type);

globus_bool_t
globus_xio_driver_error_match_with_cb(
    globus_xio_driver_t                 driver,
    globus_object_t *                   error,
    globus_extension_error_match_cb_t   callback,
    void *                              type);

globus_bool_t
globus_xio_error_match(
    globus_result_t                     result,
    int                                 type);
    
void
globus_xio_contact_destroy(
    globus_xio_contact_t *              contact_info);

globus_result_t
globus_xio_contact_parse(
    globus_xio_contact_t *              contact_info,
    const char *                        contact_string);

globus_result_t
globus_xio_contact_info_to_string(
    const globus_xio_contact_t *        contact_info,
    char **                             contact_string);

globus_result_t
globus_xio_contact_info_to_url(
    const globus_xio_contact_t *        contact_info,
    char **                             contact_string);

globus_result_t
globus_xio_contact_info_to_encoded_string(
    const globus_xio_contact_t *        contact_info,
    const globus_xio_contact_t *        encode_chars,
    char **                             contact_string);

globus_result_t
globus_xio_contact_copy(
    globus_xio_contact_t *              dst,
    const globus_xio_contact_t *        src);

/*
 * Utility macros
 */

/* all macros in this file require each function to 'declare' their name with
 * this
 */
#ifdef __GNUC__
#define GlobusXIOName(func) static const char * _xio_name __attribute__((__unused__)) = #func
#else
#define GlobusXIOName(func) static const char * _xio_name = #func
#endif

#define GlobusXIOErrorCanceled()                                            \
    globus_error_put(GlobusXIOErrorObjCanceled())

#define GlobusXIOErrorObjCanceled()                                         \
    globus_error_construct_error(                                           \
        GLOBUS_XIO_MODULE,                                                  \
        GLOBUS_NULL,                                                        \
        GLOBUS_XIO_ERROR_CANCELED,                                          \
        __FILE__,                                                           \
        _xio_name,                                                          \
        __LINE__,							    \
        _XIOSL("Operation was canceled"))                                          
#define GlobusXIOErrorTimeout()                                             \
    globus_error_put(GlobusXIOErrorObjTimeout())                               

#define GlobusXIOErrorObjTimeout()                                          \
    globus_error_construct_error(                                           \
        GLOBUS_XIO_MODULE,                                                  \
        GlobusXIOErrorObjTimeoutOnly(),                                     \
        GLOBUS_XIO_ERROR_CANCELED,                                          \
        __FILE__,                                                           \
        _xio_name,                                                          \
        __LINE__,                                                           \
        _XIOSL("Operation was canceled"))

#define GlobusXIOErrorObjTimeoutOnly()                                      \
    globus_error_construct_error(                                           \
        GLOBUS_XIO_MODULE,                                                  \
        GLOBUS_NULL,                                                        \
        GLOBUS_XIO_ERROR_TIMEOUT,                                           \
        __FILE__,                                                           \
        _xio_name,                                                          \
        __LINE__,                                                           \
        _XIOSL("Operation timed out"))

#define GlobusXIOErrorObjEOF()                                              \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_EOF,                                           \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("An end of file occurred"))                                
                                                                            
#define GlobusXIOErrorEOF()                                                 \
    globus_error_put(                                                       \
        GlobusXIOErrorObjEOF())                                             \
                                                                            
#define GlobusXIOErrorInvalidCommand(cmd_number)                            \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_COMMAND,                                       \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("An invalid command (%d) was issued"),                   \
            (cmd_number)))                             
                                                                            
#define GlobusXIOErrorContactString(reason)                                 \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_CONTACT_STRING,                                \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Contact string invalid. %s"),                           \
            (reason)))                                 
                                                                            
#define GlobusXIOErrorObjParameter(param_name)                              \
    globus_error_construct_error(                                           \
        GLOBUS_XIO_MODULE,                                                  \
        GLOBUS_NULL,                                                        \
        GLOBUS_XIO_ERROR_PARAMETER,                                         \
        __FILE__,                                                           \
        _xio_name,                                                          \
        __LINE__,                                                           \
        _XIOSL("Bad parameter, %s"),                                        \
        (param_name))

#define GlobusXIOErrorParameter(param_name)                                 \
    globus_error_put(                                                       \
        GlobusXIOErrorObjParameter(param_name))
                                                                            
#define GlobusXIOErrorObjMemory(mem_name)                                   \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_MEMORY,                                        \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Memory allocation failed on %s"),                       \
            (mem_name))                               
                                                                            
#define GlobusXIOErrorMemory(mem_name_obj)                                  \
    globus_error_put(                                                       \
        GlobusXIOErrorObjMemory(mem_name_obj))
                                                                            
#define GlobusXIOErrorObjSystemError(system_func, _errno)                   \
        globus_error_wrap_errno_error(                                      \
            GLOBUS_XIO_MODULE,                                              \
            (_errno),                                                       \
            GLOBUS_XIO_ERROR_SYSTEM_ERROR,                                  \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("System error in %s"),                                   \
            (system_func))                           

#define GlobusXIOErrorSystemError(system_func, _errno)                      \
    globus_error_put(                                                       \
        GlobusXIOErrorObjSystemError(system_func, _errno))

#define GlobusXIOErrorSystemResource(reason)                                \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_SYSTEM_RESOURCE,                               \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("System resource error, %s"),                            \
            (reason)))                                 
                                                                            
#define GlobusXIOErrorInvalidStack(reason)                                  \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_STACK,                                         \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Invalid stack, %s"),                                    \
            (reason)))                                 
                                                                            
#define GlobusXIOErrorInvalidDriver(reason)                                 \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_DRIVER,                                        \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Invalid Driver, %s"),                                   \
            (reason)))                                 
                                                                            
#define GlobusXIOErrorPass()                                                \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_PASS,                                          \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Operation passed too far")))                                   
                                                                            
#define GlobusXIOErrorAlreadyRegistered()                                   \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_ALREADY_REGISTERED,                            \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Operation already registered")))                                    
                                                                            
#define GlobusXIOErrorInvalidState(state)                                   \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            GLOBUS_NULL,                                                    \
            GLOBUS_XIO_ERROR_STATE,                                         \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Unexpected state, %d"),                                 \
            (state)))                                  
                                                                            
#define GlobusXIOErrorWrapFailed(failed_func, result)                       \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            globus_error_get((result)),                                     \
            GLOBUS_XIO_ERROR_WRAPPED,                                       \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("%s failed."),                                           \
            (failed_func)))

#define GlobusXIOErrorWrapFailedWithMessage(result, format, arg)            \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            globus_error_get((result)),                                     \
            GLOBUS_XIO_ERROR_WRAPPED,                                       \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            (format),                                                       \
            (arg)))

#define GlobusXIOErrorWrapFailedWithMessage2(result, format, arg1, arg2)    \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            globus_error_get((result)),                                     \
            GLOBUS_XIO_ERROR_WRAPPED,                                       \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            (format),                                                       \
            (arg1), (arg2)))

#define GlobusXIOErrorNotRegistered()                                       \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            NULL,                                                           \
            GLOBUS_XIO_ERROR_NOT_REGISTERED,                                \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Not registered.")))                            

#define GlobusXIOErrorNotActivated()                                        \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            NULL,                                                           \
            GLOBUS_XIO_ERROR_NOT_ACTIVATED,                                 \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Module not activated.")))
                                                                            
#define GlobusXIOErrorUnloaded()                                            \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            NULL,                                                           \
            GLOBUS_XIO_ERROR_UNLOADED,                                      \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("Driver in handle has been unloaded.")))

#define GlobusXIOErrorParse(arg)                                            \
    globus_error_put(                                                       \
        globus_error_construct_error(                                       \
            GLOBUS_XIO_MODULE,                                              \
            NULL,                                                           \
            GLOBUS_XIO_ERROR_PARSE,                                         \
            __FILE__,                                                       \
            _xio_name,                                                      \
            __LINE__,                                                       \
            _XIOSL("An error occured parsing the string: %s"), arg))


#define GlobusIXIOUtilCopyNIovec(iov, iovc, siov, siovc, bytes)             \
    do                                                                      \
    {                                                                       \
        globus_size_t                   _i;                                 \
        globus_size_t                   _tb = 0;                            \
        globus_size_t                   _bytes;                             \
        const struct iovec *            _siov;                              \
        struct iovec *                  _iov;                               \
        int                             _iovc;                              \
        int                             _siovc;                             \
                                                                            \
        _siov = (siov);                                                     \
        _siovc = (siovc);                                                   \
        _iov = (iov);                                                       \
        _iovc = (iovc);                                                     \
        _bytes = (bytes);                                                   \
                                                                            \
        for(_i = 0; _i < _siovc && _tb < _bytes; _i++)                      \
        {                                                                   \
            if(_tb + _siov[_i].iov_len > _bytes)                            \
            {                                                               \
                _iov[_i].iov_len = _bytes - _tb;                            \
            }                                                               \
            else                                                            \
            {                                                               \
                _iov[_i].iov_len = _siov[_i].iov_len;                       \
            }                                                               \
            _tb += _siov[_i].iov_len;                                       \
            _iov[_i].iov_base = _siov[_i].iov_base;                         \
        }                                                                   \
        _iovc = _i;                                                         \
    } while(0)


                                                                            
#define GlobusIXIOUtilTransferIovec(iov, siov, iovc)                        \
    do                                                                      \
    {                                                                       \
        int                             _i;                                 \
        const struct iovec *            _siov;                              \
        struct iovec *                  _iov;                               \
        int                             _iovc;                              \
                                                                            \
        _siov = (siov);                                                     \
        _iov = (iov);                                                       \
        _iovc = (iovc);                                                     \
                                                                            \
        for(_i = 0; _i < _iovc; _i++)                                       \
        {                                                                   \
            _iov[_i].iov_base = _siov[_i].iov_base;                         \
            _iov[_i].iov_len = _siov[_i].iov_len;                           \
        }                                                                   \
    } while(0)

#define GlobusIXIOUtilAdjustIovec(iov, iovc, nbytes)                        \
    do                                                                      \
    {                                                                       \
        globus_size_t                   _n = (nbytes);                      \
                                                                            \
        if(_n > 0)                                                          \
        {                                                                   \
            struct iovec *              _iov = (iov);                       \
            int                         _iovc = (iovc);                     \
            int                         _i;                                 \
                                                                            \
            /* skip all completely filled iovecs */                         \
            for(_i = 0;                                                     \
                _i < _iovc &&  _n >= _iov[_i].iov_len;                      \
                _n -= _iov[_i].iov_len, _i++);                              \
                                                                            \
            if(_i < _iovc)                                                  \
            {                                                               \
                _iov[_i].iov_base = (char *) _iov[_i].iov_base + _n;        \
                _iov[_i].iov_len -= _n;                                     \
                (iov) += _i;                                                \
            }                                                               \
                                                                            \
            (iovc) -= _i;                                                   \
        }                                                                   \
    } while(0)

#define GlobusIXIOUtilTransferAdjustedIovec(                                \
    new_iov, new_iovc, iov, iovc, nbytes)                                   \
    do                                                                      \
    {                                                                       \
        globus_size_t                   _n;                                 \
        const struct iovec *            _iov;                               \
        int                             _iovc;                              \
        struct iovec *                  _new_iov;                           \
        int                             _i;                                 \
        int                             _j;                                 \
                                                                            \
        _iov = (iov);                                                       \
        _iovc = (iovc);                                                     \
        _new_iov = (new_iov);                                               \
                                                                            \
        /* skip all completely filled iovecs */                             \
        for(_i = 0, _n = (nbytes);                                          \
            _i < _iovc &&  _n >= _iov[_i].iov_len;                          \
            _n -= _iov[_i].iov_len, _i++);                                  \
                                                                            \
        (new_iovc) = _iovc - _i;                                            \
        if(_i < _iovc)                                                      \
        {                                                                   \
            _new_iov[0].iov_base = (char *) _iov[_i].iov_base + _n;         \
            _new_iov[0].iov_len = _iov[_i].iov_len - _n;                    \
                                                                            \
            /* copy remaining */                                            \
            for(_j = 1, _i++; _i < _iovc; _j++, _i++)                       \
            {                                                               \
                _new_iov[_j].iov_base = _iov[_i].iov_base;                  \
                _new_iov[_j].iov_len = _iov[_i].iov_len;                    \
            }                                                               \
        }                                                                   \
    } while(0)

#define GlobusXIOUtilIovTotalLength(                                        \
    out_len, iov, iovc)                                                     \
    do                                                                      \
    {                                                                       \
        int                             _i;                                 \
        const struct iovec *            _iov;                               \
        int                             _iovc;                              \
        globus_size_t                   _out_len;                           \
        _iov = (iov);							    \
        _iovc = (iovc);							    \
        _out_len = 0;                                                       \
        for(_i = 0; _i < _iovc; _i++)                                       \
        {                                                                   \
            _out_len += _iov[_i].iov_len;                                   \
        }                                                                   \
        out_len = _out_len;						    \
    } while(0)

#define GlobusXIOUtilIovSerialize(                                          \
    out_buf, iov, iovc)                                                     \
    do                                                                      \
    {                                                                       \
        int                             _i;                                 \
        int                             _ndx = 0;                           \
        for(_i = 0; _i < iovc; _i++)                                        \
        {                                                                   \
            memcpy(&(out_buf)[_ndx], (iov)[_i].iov_base, (iov)[_i].iov_len);\
            _ndx += (iov)[_i].iov_len;                                      \
        }                                                                   \
    } while(0)

#ifdef __cplusplus
}
#endif

#endif