File indexing completed on 2025-02-23 10:12:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef PMIX_PTL_BASE_HANDSHAKE_H_
0013 #define PMIX_PTL_BASE_HANDSHAKE_H_
0014
0015 #include "src/include/pmix_config.h"
0016
0017 #ifdef HAVE_STRING_H
0018 # include <string.h>
0019 #endif
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 BEGIN_C_DECLS
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 typedef uint8_t pmix_rnd_flag_t;
0049 #define PMIX_SIMPLE_CLIENT 0
0050 #define PMIX_LEGACY_TOOL 1
0051 #define PMIX_LEGACY_LAUNCHER 2
0052 #define PMIX_TOOL_NEEDS_ID 3
0053 #define PMIX_TOOL_GIVEN_ID 4
0054 #define PMIX_TOOL_CLIENT 5
0055 #define PMIX_LAUNCHER_NEEDS_ID 6
0056 #define PMIX_LAUNCHER_GIVEN_ID 7
0057 #define PMIX_LAUNCHER_CLIENT 8
0058 #define PMIX_SINGLETON_CLIENT 9
0059 #define PMIX_SCHEDULER_WITH_ID 10
0060
0061
0062
0063
0064 #define PMIX_PTL_GET_STRING(n) \
0065 do { \
0066 size_t _l; \
0067 PMIX_STRNLEN(_l, mg, cnt); \
0068 if (_l < cnt) { \
0069 (n) = strdup(mg); \
0070 mg += strlen((n)) + 1; \
0071 cnt -= strlen((n)) + 1; \
0072 } else { \
0073 PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); \
0074 goto error; \
0075 } \
0076 } while (0)
0077
0078
0079
0080
0081 #define PMIX_PTL_GET_U32_NOERROR(r, n) \
0082 do { \
0083 uint32_t _u; \
0084 if (sizeof(uint32_t) <= cnt) { \
0085 memcpy(&_u, mg, sizeof(uint32_t)); \
0086 (n) = ntohl(_u); \
0087 mg += sizeof(uint32_t); \
0088 cnt -= sizeof(uint32_t); \
0089 (r) = PMIX_SUCCESS; \
0090 } else { \
0091 (r) = PMIX_ERR_BAD_PARAM; \
0092 } \
0093 } while (0)
0094
0095 #define PMIX_PTL_GET_U32(n) \
0096 do { \
0097 uint32_t _u; \
0098 if (sizeof(uint32_t) <= cnt) { \
0099 memcpy(&_u, mg, sizeof(uint32_t)); \
0100 (n) = ntohl(_u); \
0101 mg += sizeof(uint32_t); \
0102 cnt -= sizeof(uint32_t); \
0103 } else { \
0104 PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); \
0105 goto error; \
0106 } \
0107 } while (0)
0108
0109 #define PMIX_PTL_GET_BLOB(b, l) \
0110 do { \
0111 if (0 < (l)) { \
0112 (b) = (char *) malloc((l)); \
0113 if (NULL == (b)) { \
0114 PMIX_ERROR_LOG(PMIX_ERR_NOMEM); \
0115 goto error; \
0116 } \
0117 memcpy((b), mg, (l)); \
0118 mg += (l); \
0119 cnt -= (l); \
0120 } \
0121 } while (0)
0122
0123 #define PMIX_PTL_GET_U8(n) \
0124 do { \
0125 if (sizeof(uint8_t) <= cnt) { \
0126 memcpy(&(n), mg, sizeof(uint8_t)); \
0127 mg += sizeof(uint8_t); \
0128 cnt -= sizeof(uint8_t); \
0129 } else { \
0130 PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); \
0131 goto error; \
0132 } \
0133 } while (0)
0134
0135 #define PMIX_PTL_GET_PROCID(p) \
0136 do { \
0137 char *n; \
0138 uint32_t _r; \
0139 pmix_status_t _rc; \
0140 PMIX_PTL_GET_STRING(n); \
0141 PMIX_PTL_GET_U32_NOERROR(_rc, _r); \
0142 if (PMIX_SUCCESS != _rc) { \
0143 PMIX_ERROR_LOG(_rc); \
0144 free(n); \
0145 goto error; \
0146 } \
0147 PMIX_LOAD_PROCID(&(p), n, _r); \
0148 free(n); \
0149 } while (0)
0150
0151
0152
0153 #define PMIX_PTL_PUT_STRING(n) \
0154 do { \
0155 memcpy(msg + csize, (n), strlen((n))); \
0156 csize += strlen((n)) + 1; \
0157 } while (0)
0158
0159
0160
0161
0162 #define PMIX_PTL_PUT_U32(n) \
0163 do { \
0164 uint32_t _u; \
0165 _u = htonl((uint32_t)(n)); \
0166 memcpy(msg + csize, &_u, sizeof(uint32_t)); \
0167 csize += sizeof(uint32_t); \
0168 } while (0)
0169
0170 #define PMIX_PTL_PUT_BLOB(b, l) \
0171 do { \
0172 if (0 < (l)) { \
0173 memcpy(msg + csize, (b), (l)); \
0174 csize += (l); \
0175 } \
0176 } while (0)
0177
0178 #define PMIX_PTL_PUT_U8(n) \
0179 do { \
0180 memcpy(msg + csize, &(n), sizeof(uint8_t)); \
0181 csize += sizeof(uint8_t); \
0182 } while (0)
0183
0184 #define PMIX_PTL_PUT_PROCID(p) \
0185 do { \
0186 PMIX_PTL_PUT_STRING((p).nspace); \
0187 PMIX_PTL_PUT_U32((p).rank); \
0188 } while (0)
0189
0190
0191
0192 #define PMIX_PTL_RECV_NSPACE(s, n) \
0193 do { \
0194 pmix_status_t r; \
0195 r = pmix_ptl_base_recv_blocking((s), (char *) (n), PMIX_MAX_NSLEN + 1); \
0196 (n)[PMIX_MAX_NSLEN] = '\0'; \
0197 if (PMIX_SUCCESS != r) { \
0198 return r; \
0199 } \
0200 } while (0)
0201
0202 #define PMIX_PTL_RECV_U32(s, n) \
0203 do { \
0204 pmix_status_t r; \
0205 uint32_t _u; \
0206 r = pmix_ptl_base_recv_blocking((s), (char *) &_u, sizeof(uint32_t)); \
0207 if (PMIX_SUCCESS != r) { \
0208 return r; \
0209 } \
0210 (n) = htonl(_u); \
0211 } while (0)
0212
0213 END_C_DECLS
0214
0215 #endif