E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3 | .. This work is licensed under a Creative Commons Attribution 4.0 International License. |
| 4 | .. SPDX-License-Identifier: CC-BY-4.0 |
| 5 | .. CAUTION: this document is generated from source in doc/src/rtd. |
| 6 | .. To make changes edit the source and recompile the document. |
| 7 | .. Do NOT make changes directly to .rst or .md files. |
| 8 | |
| 9 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 10 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 11 | RMR User's Guide |
| 12 | ============================================================================================ |
| 13 | |
Lott, Christopher (cl778h) | fe6a856 | 2020-04-06 15:05:22 -0400 | [diff] [blame] | 14 | The RIC Message Router (RMR) is a library for peer-to-peer |
| 15 | communication. Applications use the library to send and |
| 16 | receive messages where the message routing and endpoint |
| 17 | selection is based on the message type rather than DNS host |
| 18 | name-IP port combinations. |
| 19 | |
| 20 | This document contains information that developers need to |
| 21 | know to use the RMR library. Because the primary |
| 22 | documentation for the RMR library is a collection of UNIX |
| 23 | manpages (included in the development package, and available |
| 24 | via the man command when installed), there is no separate |
| 25 | "User's Guide." To provide something for the document |
| 26 | scrapers to find, this is a collection of the RMR manual |
| 27 | pages formatted directly from their source, which might be a |
| 28 | bit ragged when combined into a single markup document. Read |
| 29 | the manual pages :) |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 30 | |
| 31 | |
| 32 | |
| 33 | NAME |
| 34 | -------------------------------------------------------------------------------------------- |
| 35 | |
| 36 | rmr_alloc_msg |
| 37 | |
| 38 | SYNOPSIS |
| 39 | -------------------------------------------------------------------------------------------- |
| 40 | |
| 41 | |
| 42 | :: |
| 43 | |
| 44 | #include <rmr/rmr.h> |
| 45 | rmr_mbuf_t* rmr_alloc_msg( void* ctx, int size ); |
| 46 | |
| 47 | |
| 48 | |
| 49 | DESCRIPTION |
| 50 | -------------------------------------------------------------------------------------------- |
| 51 | |
| 52 | The rmr_alloc_msg function is used to allocate a buffer which |
| 53 | the user programme can write into and then send through the |
| 54 | RMR library. The buffer is allocated such that sending it |
| 55 | requires no additional copying out of the buffer. If the |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 56 | value passed in size is less than or equal to 0, then the |
| 57 | *normal maximum size* supplied on the *rmr_init* call will be |
| 58 | used. When *size* is greater than zero, the message allocated |
| 59 | will have at least the indicated number of bytes in the |
| 60 | payload. There is no maximum size imposed by RMR, however the |
| 61 | underlying system memory managerment (e.g. malloc) functions |
| 62 | may impose a limit. |
| 63 | |
| 64 | The *ctx* parameter is the void context pointer that was |
| 65 | returned by the *rmr_init* function. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 66 | |
| 67 | The pointer to the message buffer returned is a structure |
| 68 | which has some user application visible fields; the structure |
| 69 | is described in rmr.h, and is illustrated below. |
| 70 | |
| 71 | |
| 72 | :: |
| 73 | |
| 74 | typedef struct { |
| 75 | int state; |
| 76 | int mtype; |
| 77 | int len; |
| 78 | unsigned char* payload; |
| 79 | unsigned char* xaction; |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 80 | int sub_id; |
| 81 | int tp_state; |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 82 | } rmr_mbuf_t; |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | state |
| 89 | |
| 90 | Is the current buffer state. Following a call to |
| 91 | rmr_send_msg the state indicates whether the buffer was |
| 92 | successfully sent which determines exactly what the |
| 93 | payload points to. If the send failed, the payload |
| 94 | referenced by the buffer is the message that failed to |
| 95 | send (allowing the application to attempt a |
| 96 | retransmission). When the state is RMR_OK the buffer |
| 97 | represents an empty buffer that the application may fill |
| 98 | in in preparation to send. |
| 99 | |
| 100 | |
| 101 | mtype |
| 102 | |
| 103 | When sending a message, the application is expected to set |
| 104 | this field to the appropriate message type value (as |
| 105 | determined by the user programme). Upon send this value |
| 106 | determines how the RMR library will route the message. For |
| 107 | a buffer which has been received, this field will contain |
| 108 | the message type that was set by the sending application. |
| 109 | |
| 110 | |
| 111 | len |
| 112 | |
| 113 | The application using a buffer to send a message is |
| 114 | expected to set the length value to the actual number of |
| 115 | bytes that it placed into the message. This is likely less |
| 116 | than the total number of bytes that the message can carry. |
| 117 | For a message buffer that is passed to the application as |
| 118 | the result of a receive call, this will be the value that |
| 119 | the sending application supplied and should indicate the |
| 120 | number of bytes in the payload which are valid. |
| 121 | |
| 122 | |
| 123 | payload |
| 124 | |
| 125 | The payload is a pointer to the actual received data. The |
| 126 | user programme may read and write from/to the memory |
| 127 | referenced by the payload up until the point in time that |
| 128 | the buffer is used on a rmr_send, rmr_call or rmr_reply |
| 129 | function call. Once the buffer has been passed back to a |
| 130 | RMR library function the user programme should **NOT** |
| 131 | make use of the payload pointer. |
| 132 | |
| 133 | |
| 134 | xaction |
| 135 | |
| 136 | The *xaction* field is a pointer to a fixed sized area in |
| 137 | the message into which the user may write a transaction |
| 138 | ID. The ID is optional with the exception of when the user |
| 139 | application uses the rmr_call function to send a message |
| 140 | and wait for the reply; the underlying RMR processing |
| 141 | expects that the matching reply message will also contain |
| 142 | the same data in the *xaction* field. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 143 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 144 | |
| 145 | sub_id |
| 146 | |
| 147 | This value is the subscription ID. It, in combination with |
| 148 | the message type is used by rmr to determine the target |
| 149 | endpoint when sending a message. If the application to |
| 150 | application protocol does not warrant the use of a |
| 151 | subscription ID, the RMR constant RMR_VOID_SUBID should be |
| 152 | placed in this field. When an application is forwarding or |
| 153 | returning a buffer to the sender, it is the application's |
| 154 | responsibility to set/reset this value. |
| 155 | |
| 156 | |
| 157 | tp_state |
| 158 | |
| 159 | For C applications making use of RMR, the state of a |
| 160 | transport based failure will often be available via errno. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 161 | However, some wrapper environments may not have direct |
| 162 | access to the C-lib errno value. RMR send and receive |
| 163 | operations will place the current value of errno into this |
| 164 | field which should make it available to wrapper functions. |
| 165 | User applications are strongly cautioned against relying |
| 166 | on the value of errno as some transport mechanisms may not |
| 167 | set this value on all calls. This value should also be |
| 168 | ignored any time the message status is RMR_OK. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 169 | |
| 170 | |
| 171 | RETURN VALUE |
| 172 | -------------------------------------------------------------------------------------------- |
| 173 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 174 | The function returns a pointer to a rmr_mbuf structure, or |
| 175 | NULL on error. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 176 | |
| 177 | ERRORS |
| 178 | -------------------------------------------------------------------------------------------- |
| 179 | |
| 180 | |
| 181 | |
| 182 | ENOMEM |
| 183 | |
| 184 | Unable to allocate memory. |
| 185 | |
| 186 | |
| 187 | SEE ALSO |
| 188 | -------------------------------------------------------------------------------------------- |
| 189 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 190 | rmr_tralloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 191 | rmr_init(3), rmr_init_trace(3), rmr_get_trace(3), |
| 192 | rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3), |
| 193 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 194 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 195 | rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3) |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 196 | |
| 197 | |
| 198 | NAME |
| 199 | -------------------------------------------------------------------------------------------- |
| 200 | |
| 201 | rmr_bytes2meid |
| 202 | |
| 203 | SYNOPSIS |
| 204 | -------------------------------------------------------------------------------------------- |
| 205 | |
| 206 | |
| 207 | :: |
| 208 | |
| 209 | #include <rmr/rmr.h> |
| 210 | int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len ) |
| 211 | |
| 212 | |
| 213 | |
| 214 | DESCRIPTION |
| 215 | -------------------------------------------------------------------------------------------- |
| 216 | |
| 217 | The rmr_bytes2meid function will copy up to *len* butes from |
E. Scott Daniels | 190665f | 2019-12-09 09:05:22 -0500 | [diff] [blame] | 218 | *src* to the managed entity ID (meid) field in the message. |
| 219 | The field is a fixed length, gated by the constant |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 220 | RMR_MAX_MEID and if len is larger than this value, only |
| 221 | RMR_MAX_MEID bytes will actually be copied. |
| 222 | |
| 223 | RETURN VALUE |
| 224 | -------------------------------------------------------------------------------------------- |
| 225 | |
| 226 | On success, the actual number of bytes copied is returned, or |
| 227 | -1 to indicate a hard error. If the length is less than 0, or |
| 228 | not the same as length passed in, errno is set to one of the |
| 229 | errors described in the *Errors* section. |
| 230 | |
| 231 | ERRORS |
| 232 | -------------------------------------------------------------------------------------------- |
| 233 | |
| 234 | If the returned length does not match the length passed in, |
| 235 | errno will be set to one of the following constants with the |
| 236 | meaning listed below. |
| 237 | |
| 238 | |
| 239 | |
| 240 | EINVAL |
| 241 | |
| 242 | The message, or an internal portion of the message, was |
| 243 | corrupted or the pointer was invalid. |
| 244 | |
| 245 | |
| 246 | EOVERFLOW |
| 247 | |
| 248 | The length passed in was larger than the maximum length of |
| 249 | the field; only a portion of the source bytes were copied. |
| 250 | |
| 251 | |
| 252 | EXAMPLE |
| 253 | -------------------------------------------------------------------------------------------- |
| 254 | |
| 255 | |
| 256 | SEE ALSO |
| 257 | -------------------------------------------------------------------------------------------- |
| 258 | |
| 259 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_call(3), |
| 260 | rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_meid(3), |
| 261 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 262 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 263 | rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 264 | rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3), |
| 265 | rmr_wh_open(3), rmr_wh_send_msg(3) |
| 266 | |
| 267 | |
| 268 | NAME |
| 269 | -------------------------------------------------------------------------------------------- |
| 270 | |
| 271 | rmr_bytes2payload |
| 272 | |
| 273 | SYNOPSIS |
| 274 | -------------------------------------------------------------------------------------------- |
| 275 | |
| 276 | |
| 277 | :: |
| 278 | |
| 279 | #include <rmr/rmr.h> |
| 280 | void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char* src, int len ) |
| 281 | |
| 282 | |
| 283 | |
| 284 | DESCRIPTION |
| 285 | -------------------------------------------------------------------------------------------- |
| 286 | |
| 287 | This is a convenience function as some wrapper languages |
| 288 | might not have the ability to directly copy into the payload |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 289 | buffer. The bytes from *src* for the length given are copied |
| 290 | to the payload. It is the caller's responsibility to ensure |
| 291 | that the payload is large enough. Upon successfully copy, the |
| 292 | len field in the message buffer is updated to reflect the |
| 293 | number of bytes copied. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 294 | |
| 295 | There is little error checking, and no error reporting. |
| 296 | |
| 297 | RETURN VALUE |
| 298 | -------------------------------------------------------------------------------------------- |
| 299 | |
| 300 | None. |
| 301 | |
| 302 | EXAMPLE |
| 303 | -------------------------------------------------------------------------------------------- |
| 304 | |
| 305 | |
| 306 | SEE ALSO |
| 307 | -------------------------------------------------------------------------------------------- |
| 308 | |
| 309 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2payload(3), |
| 310 | rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3), |
| 311 | rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3), |
| 312 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 313 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 314 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 315 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 316 | |
| 317 | |
| 318 | NAME |
| 319 | -------------------------------------------------------------------------------------------- |
| 320 | |
| 321 | rmr_bytes2xact |
| 322 | |
| 323 | SYNOPSIS |
| 324 | -------------------------------------------------------------------------------------------- |
| 325 | |
| 326 | |
| 327 | :: |
| 328 | |
| 329 | #include <rmr/rmr.h> |
| 330 | int rmr_bytes2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len ) |
| 331 | |
| 332 | |
| 333 | |
| 334 | DESCRIPTION |
| 335 | -------------------------------------------------------------------------------------------- |
| 336 | |
| 337 | The rmr_bytes2xact function will copy up to *len* butes from |
| 338 | *src* to the transaction ID (xaction) field in the message. |
| 339 | The field is a fixed length, gated by the constant |
| 340 | RMR_MAX_XID and if len is larger than this value, only |
| 341 | RMR_MAX_XID bytes will actually be copied. |
| 342 | |
| 343 | |
| 344 | RETURN VALUE |
| 345 | -------------------------------------------------------------------------------------------- |
| 346 | |
| 347 | On success, the actual number of bytes copied is returned, |
| 348 | or -1 to indicate a hard error. If the length is less than |
| 349 | 0, or not the same as length passed in, errno is set to |
| 350 | one of the errors described in the *Errors* section. |
| 351 | |
| 352 | ERRORS |
| 353 | -------------------------------------------------------------------------------------------- |
| 354 | |
| 355 | If the returned length does not match the length passed |
| 356 | in, errno will be set to one of the following constants |
| 357 | with the meaning listed below. |
| 358 | |
| 359 | |
| 360 | EINVAL |
| 361 | |
| 362 | The message, or an internal portion of the message, was |
| 363 | corrupted or the pointer was invalid. |
| 364 | |
| 365 | |
| 366 | EOVERFLOW |
| 367 | |
| 368 | The length passed in was larger than the maximum length of |
| 369 | the field; only a portion of the source bytes were copied. |
| 370 | |
| 371 | |
| 372 | EXAMPLE |
| 373 | -------------------------------------------------------------------------------------------- |
| 374 | |
| 375 | |
| 376 | SEE ALSO |
| 377 | -------------------------------------------------------------------------------------------- |
| 378 | |
| 379 | rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_call(3), |
| 380 | rmr_free_msg(3), rmr_get_meid(3), rmr_get_rcvfd(3), |
| 381 | rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3), |
| 382 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 383 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 384 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 385 | rmr_wh_open(3), rmr_wh_send_msg(3) |
| 386 | |
| 387 | |
| 388 | NAME |
| 389 | -------------------------------------------------------------------------------------------- |
| 390 | |
| 391 | rmr_call |
| 392 | |
| 393 | SYNOPSIS |
| 394 | -------------------------------------------------------------------------------------------- |
| 395 | |
| 396 | |
| 397 | :: |
| 398 | |
| 399 | #include <rmr/rmr.h> |
| 400 | extern rmr_mbuf_t* rmr_call( void* vctx, rmr_mbuf_t* msg ); |
| 401 | |
| 402 | |
| 403 | |
| 404 | DESCRIPTION |
| 405 | -------------------------------------------------------------------------------------------- |
| 406 | |
| 407 | The rmr_call function sends the user application message to a |
| 408 | remote endpoint, and waits for a corresponding response |
| 409 | message before returning control to the user application. The |
| 410 | user application supplies a completed message buffer, as it |
| 411 | would for a rmr_send call, but unlike with the send, the |
| 412 | buffer returned will have the response from the application |
| 413 | that received the message. |
| 414 | |
| 415 | Messages which are received while waiting for the response |
| 416 | are queued internally by RMR, and are returned to the user |
| 417 | application when rmr_rcv_msg is invoked. These messages are |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 418 | returned in the order received, one per call to rmr_rcv_msg. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 419 | |
| 420 | Call Timeout |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 421 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 422 | |
| 423 | The rmr_call function implements a timeout failsafe to |
| 424 | prevent, in most cases, the function from blocking forever. |
| 425 | The timeout period is **not** based on time (calls to clock |
| 426 | are deemed too expensive for a low latency system level |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 427 | library), but instead the period is based on the number of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 428 | received messages which are not the response. Using a |
| 429 | non-time mechanism for *timeout* prevents the async queue |
| 430 | from filling (which would lead to message drops) in an |
| 431 | environment where there is heavy message traffic. |
| 432 | |
| 433 | When the threshold number of messages have been queued |
| 434 | without receiving a response message, control is returned to |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 435 | the user application and a nil pointer is returned to |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 436 | indicate that no message was received to process. Currently |
| 437 | the threshold is fixed at 20 messages, though in future |
| 438 | versions of the library this might be extended to be a |
| 439 | parameter which the user application may set. |
| 440 | |
| 441 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 442 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 443 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 444 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 445 | until one of three conditions occurs: |
| 446 | |
| 447 | |
| 448 | |
| 449 | 1. |
| 450 | |
| 451 | The message is sent without error |
| 452 | |
| 453 | |
| 454 | 2. |
| 455 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 456 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 457 | |
| 458 | |
| 459 | 3. |
| 460 | |
| 461 | The maximum number of retry loops has been attempted |
| 462 | |
| 463 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 464 | A retry loop consists of approximately 1000 send attempts |
| 465 | **without** any intervening calls to *sleep()* or *usleep().* |
| 466 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 467 | 1000 send attempts is performed before returning to the user |
| 468 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 469 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 470 | allowing the user application to completely disable retires |
| 471 | (set to 0), or to increase the number of retry loops. |
| 472 | |
| 473 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 474 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 475 | |
| 476 | The underlying transport mechanism used to send messages is |
| 477 | configured in *non-blocking* mode. This means that if a |
| 478 | message cannot be sent immediately the transport mechanism |
| 479 | will **not** pause with the assumption that the inability to |
| 480 | send will clear quickly (within a few milliseconds). This |
| 481 | means that when the retry loop is completely disabled (set to |
| 482 | 0), that the failure to accept a message for sending by the |
| 483 | underlying mechanisms (software or hardware) will be reported |
| 484 | immediately to the user application. |
| 485 | |
| 486 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 487 | mechanism being used, it is extremely likely that retry |
| 488 | conditions will happen during normal operations. These are |
| 489 | completely out of RMR's control, and there is nothing that |
| 490 | RMR can do to avoid or mitigate these other than by allowing |
| 491 | RMR to retry the send operation, and even then it is possible |
| 492 | (e.g., during connection reattempts), that a single retry |
| 493 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 494 | |
| 495 | RETURN VALUE |
| 496 | -------------------------------------------------------------------------------------------- |
| 497 | |
| 498 | The rmr_call function returns a pointer to a message buffer |
| 499 | with the state set to reflect the overall state of call |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 500 | processing (see Errors below). In some cases a nil pointer |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 501 | will be returned; when this is the case only *errno* will be |
| 502 | available to describe the reason for failure. |
| 503 | |
| 504 | ERRORS |
| 505 | -------------------------------------------------------------------------------------------- |
| 506 | |
| 507 | These values are reflected in the state field of the returned |
| 508 | message. |
| 509 | |
| 510 | |
| 511 | |
| 512 | RMR_OK |
| 513 | |
| 514 | The call was successful and the message buffer references |
| 515 | the response message. |
| 516 | |
| 517 | |
| 518 | RMR_ERR_CALLFAILED |
| 519 | |
| 520 | The call failed and the value of *errno,* as described |
| 521 | below, should be checked for the specific reason. |
| 522 | |
| 523 | |
| 524 | The global "variable" *errno* will be set to one of the |
| 525 | following values if the overall call processing was not |
| 526 | successful. |
| 527 | |
| 528 | |
| 529 | |
| 530 | ETIMEDOUT |
| 531 | |
| 532 | Too many messages were queued before receiving the |
| 533 | expected response |
| 534 | |
| 535 | |
| 536 | ENOBUFS |
| 537 | |
| 538 | The queued message ring is full, messages were dropped |
| 539 | |
| 540 | |
| 541 | EINVAL |
| 542 | |
| 543 | A parameter was not valid |
| 544 | |
| 545 | |
| 546 | EAGAIN |
| 547 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 548 | The underlying message system was interrupted or the |
| 549 | device was busy; the message was **not** sent, and the |
| 550 | user application should call this function with the |
| 551 | message again. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 552 | |
| 553 | |
| 554 | EXAMPLE |
| 555 | -------------------------------------------------------------------------------------------- |
| 556 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 557 | The following code snippet shows one way of using the |
| 558 | rmr_call function, and illustrates how the transaction ID |
| 559 | must be set. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 560 | |
| 561 | |
| 562 | :: |
| 563 | |
| 564 | int retries_left = 5; // max retries on dev not available |
| 565 | int retry_delay = 50000; // retry delay (usec) |
| 566 | static rmr_mbuf_t* mbuf = NULL; // response msg |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 567 | msg_t* pm; // application struct for payload |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 568 | // get a send buffer and reference the payload |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 569 | mbuf = rmr_alloc_msg( mr, sizeof( pm->req ) ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 570 | pm = (msg_t*) mbuf->payload; |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 571 | // generate an xaction ID and fill in payload with data and msg type |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 572 | snprintf( mbuf->xaction, RMR_MAX_XID, "%s", gen_xaction() ); |
| 573 | snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" ); |
| 574 | mbuf->mtype = MT_REQ; |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 575 | msg = rmr_call( mr, msg ); |
| 576 | if( ! msg ) { // probably a timeout and no msg received |
| 577 | return NULL; // let errno trickle up |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 578 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 579 | if( mbuf->state != RMR_OK ) { |
| 580 | while( retries_left-- > 0 && // loop as long as eagain |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 581 | errno == EAGAIN && |
| 582 | (msg = rmr_call( mr, msg )) != NULL && |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 583 | mbuf->state != RMR_OK ) { |
| 584 | usleep( retry_delay ); |
| 585 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 586 | if( mbuf == NULL || mbuf->state != RMR_OK ) { |
| 587 | rmr_free_msg( mbuf ); // safe if nil |
| 588 | return NULL; |
| 589 | } |
| 590 | } |
| 591 | // do something with mbuf |
| 592 | |
| 593 | |
| 594 | |
| 595 | SEE ALSO |
| 596 | -------------------------------------------------------------------------------------------- |
| 597 | |
| 598 | rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3), |
| 599 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 600 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 601 | rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3), |
| 602 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3) |
| 603 | |
| 604 | |
| 605 | NAME |
| 606 | -------------------------------------------------------------------------------------------- |
| 607 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 608 | rmr_close |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 609 | |
| 610 | SYNOPSIS |
| 611 | -------------------------------------------------------------------------------------------- |
| 612 | |
| 613 | |
| 614 | :: |
| 615 | |
| 616 | #include <rmr/rmr.h> |
| 617 | void rmr_close( void* vctx ) |
| 618 | |
| 619 | |
| 620 | |
| 621 | DESCRIPTION |
| 622 | -------------------------------------------------------------------------------------------- |
| 623 | |
| 624 | The rmr_close function closes the listen socket effectively |
| 625 | cutting the application off. The route table listener is also |
| 626 | stopped. Calls to rmr_rcv_msg() will fail with unpredictable |
| 627 | error codes, and calls to rmr_send_msg(), rmr_call(), and |
| 628 | rmr_rts_msg() will have unknown results. |
| 629 | |
| 630 | |
| 631 | SEE ALSO |
| 632 | -------------------------------------------------------------------------------------------- |
| 633 | |
| 634 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 635 | rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3), |
| 636 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 637 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 638 | rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3), |
| 639 | rmr_wh_send_msg(3) |
| 640 | |
| 641 | |
| 642 | NAME |
| 643 | -------------------------------------------------------------------------------------------- |
| 644 | |
| 645 | rmr_free_msg |
| 646 | |
| 647 | SYNOPSIS |
| 648 | -------------------------------------------------------------------------------------------- |
| 649 | |
| 650 | |
| 651 | :: |
| 652 | |
| 653 | #include <rmr/rmr.h> |
| 654 | void rmr_free_msg( rmr_mbuf_t* mbuf ); |
| 655 | |
| 656 | |
| 657 | |
| 658 | DESCRIPTION |
| 659 | -------------------------------------------------------------------------------------------- |
| 660 | |
| 661 | The message buffer is returned to the pool, or the associated |
| 662 | memory is released depending on the needs of the underlying |
| 663 | messaging system. This allows the user application to release |
| 664 | a buffer that is not going to be used. It is safe to pass a |
| 665 | nil pointer to this function, and doing so does not result in |
| 666 | a change to the value of errrno. |
| 667 | |
| 668 | After calling, the user application should **not** use any of |
| 669 | the pointers (transaction ID, or payload) which were |
| 670 | available. |
| 671 | |
| 672 | SEE ALSO |
| 673 | -------------------------------------------------------------------------------------------- |
| 674 | |
| 675 | rmr_alloc_msg(3), rmr_call(3), rmr_init(3), |
| 676 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 677 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 678 | rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 679 | rmr_ring_free(3) |
| 680 | |
| 681 | |
| 682 | NAME |
| 683 | -------------------------------------------------------------------------------------------- |
| 684 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 685 | rmr_get_const |
| 686 | |
| 687 | SYNOPSIS |
| 688 | -------------------------------------------------------------------------------------------- |
| 689 | |
| 690 | |
| 691 | :: |
| 692 | |
| 693 | #include <rmr/rmr.h> |
| 694 | unsigned char* rmr_get_const(); |
| 695 | |
| 696 | |
| 697 | |
| 698 | DESCRIPTION |
| 699 | -------------------------------------------------------------------------------------------- |
| 700 | |
| 701 | The rmr_get_const function is a convenience function for |
| 702 | wrappers which do not have the ability to "compile in" RMR |
| 703 | constants. The function will build a nil terminated string |
| 704 | containing JSON which defines the RMR constants that C and Go |
| 705 | applications have at compile time via the rmr.h header file. |
| 706 | |
| 707 | All values are represented as strings and the JSON format is |
| 708 | illustrated in the following (partial) example: |
| 709 | |
| 710 | |
| 711 | :: |
| 712 | |
| 713 | { |
| 714 | "RMR_MAX_XID": "32", |
| 715 | "RMR_OK": "0", |
| 716 | "RMR_ERR_BADARG", "1", |
| 717 | "RMR_ERR_NOENDPT" "2" |
| 718 | } |
| 719 | |
| 720 | |
| 721 | |
| 722 | RETURN VALUE |
| 723 | -------------------------------------------------------------------------------------------- |
| 724 | |
| 725 | On success, a pointer to a string containing the JSON |
| 726 | defining constant and value pairs. On failure a nil pointer |
| 727 | is returned. |
| 728 | |
| 729 | SEE ALSO |
| 730 | -------------------------------------------------------------------------------------------- |
| 731 | |
| 732 | rmr(7) |
| 733 | |
| 734 | |
| 735 | NAME |
| 736 | -------------------------------------------------------------------------------------------- |
| 737 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 738 | rmr_get_meid |
| 739 | |
| 740 | SYNOPSIS |
| 741 | -------------------------------------------------------------------------------------------- |
| 742 | |
| 743 | |
| 744 | :: |
| 745 | |
| 746 | #include <rmr/rmr.h> |
| 747 | char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest ) |
| 748 | |
| 749 | |
| 750 | |
| 751 | DESCRIPTION |
| 752 | -------------------------------------------------------------------------------------------- |
| 753 | |
E. Scott Daniels | 190665f | 2019-12-09 09:05:22 -0500 | [diff] [blame] | 754 | The rmr_get_meid function will copy the managed entity ID |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 755 | (meid) field from the message into the *dest* buffer provided |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 756 | by the user. The buffer referenced by *dest* is assumed to be |
| 757 | at least RMR_MAX_MEID bytes in length. If *dest* is NULL, |
| 758 | then a buffer is allocated (the calling application is |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 759 | expected to free when the buffer is no longer needed). |
| 760 | |
| 761 | RETURN VALUE |
| 762 | -------------------------------------------------------------------------------------------- |
| 763 | |
| 764 | On success, a pointer to the extracted string is returned. If |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 765 | *dest* was supplied, then this is just a pointer to the |
| 766 | caller's buffer. If *dest* was NULL, this is a pointer to the |
| 767 | allocated buffer. If an error occurs, a nil pointer is |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 768 | returned and errno is set as described below. |
| 769 | |
| 770 | ERRORS |
| 771 | -------------------------------------------------------------------------------------------- |
| 772 | |
| 773 | If an error occurs, the value of the global variable errno |
| 774 | will be set to one of the following with the indicated |
| 775 | meaning. |
| 776 | |
| 777 | |
| 778 | |
| 779 | EINVAL |
| 780 | |
| 781 | The message, or an internal portion of the message, was |
| 782 | corrupted or the pointer was invalid. |
| 783 | |
| 784 | |
| 785 | ENOMEM |
| 786 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 787 | A nil pointer was passed for *dest,* however it was not |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 788 | possible to allocate a buffer using malloc(). |
| 789 | |
| 790 | |
| 791 | SEE ALSO |
| 792 | -------------------------------------------------------------------------------------------- |
| 793 | |
| 794 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3), |
| 795 | rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3), |
| 796 | rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3), |
| 797 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 798 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 799 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 800 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 801 | |
| 802 | |
| 803 | NAME |
| 804 | -------------------------------------------------------------------------------------------- |
| 805 | |
| 806 | rmr_get_rcvfd |
| 807 | |
| 808 | SYNOPSIS |
| 809 | -------------------------------------------------------------------------------------------- |
| 810 | |
| 811 | |
| 812 | :: |
| 813 | |
| 814 | #include <rmr/rmr.h> |
| 815 | void* rmr_get_rcvfd( void* ctx ) |
| 816 | |
| 817 | |
| 818 | |
| 819 | DESCRIPTION |
| 820 | -------------------------------------------------------------------------------------------- |
| 821 | |
| 822 | The rmr_get_rcvfd function returns a file descriptor which |
| 823 | may be given to epoll_wait() by an application that wishes to |
| 824 | use event poll in a single thread rather than block on the |
| 825 | arrival of a message via calls to rmr_rcv_msg(). When |
| 826 | epoll_wait() indicates that this file descriptor is ready, a |
| 827 | call to rmr_rcv_msg() will not block as at least one message |
| 828 | has been received. |
| 829 | |
| 830 | The context (ctx) pointer passed in is the pointer returned |
| 831 | by the call to rmr_init(). |
| 832 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 833 | RETURN VALUE |
| 834 | -------------------------------------------------------------------------------------------- |
| 835 | |
| 836 | The rmr_get_rcvfd function returns a file descriptor greater |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 837 | or equal to 0 on success and -1 on error. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 838 | |
| 839 | ERRORS |
| 840 | -------------------------------------------------------------------------------------------- |
| 841 | |
| 842 | The following error values are specifically set by this RMR |
| 843 | function. In some cases the error message of a system call is |
| 844 | propagated up, and thus this list might be incomplete. |
| 845 | |
| 846 | |
| 847 | EINVAL |
| 848 | |
| 849 | The use of this function is invalid in this environment. |
| 850 | |
| 851 | |
| 852 | EXAMPLE |
| 853 | -------------------------------------------------------------------------------------------- |
| 854 | |
| 855 | The following short code bit illustrates the use of this |
| 856 | function. Error checking has been omitted for clarity. |
| 857 | |
| 858 | |
| 859 | :: |
| 860 | |
| 861 | #include <stdio.h> |
| 862 | #include <stdlib.h> |
| 863 | #include <sys/epoll.h> |
| 864 | #include <rmr/rmr.h> |
| 865 | int main() { |
| 866 | int rcv_fd; // pollable fd |
| 867 | void* mrc; //msg router context |
| 868 | struct epoll_event events[10]; // support 10 events to poll |
| 869 | struct epoll_event epe; // event definition for event to listen to |
| 870 | int ep_fd = -1; |
| 871 | rmr_mbuf_t* msg = NULL; |
| 872 | int nready; |
| 873 | int i; |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 874 | int norm_msg_size = 1500; // 95% messages are less than this |
| 875 | mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 876 | rcv_fd = rmr_get_rcvfd( mrc ); |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 877 | ep_fd = epoll_create1( 0 ); // initialise epoll environment |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 878 | epe.events = EPOLLIN; |
| 879 | epe.data.fd = rcv_fd; |
| 880 | epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 881 | while( 1 ) { |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 882 | nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout) |
| 883 | for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready |
| 884 | if( events[i].data.fd == rcv_fd ) { // RMR has something |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 885 | msg = rmr_rcv_msg( mrc, msg ); |
| 886 | if( msg ) { |
| 887 | // do something with msg |
| 888 | } |
| 889 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 890 | // check for other ready fds.... |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | |
| 896 | |
| 897 | SEE ALSO |
| 898 | -------------------------------------------------------------------------------------------- |
| 899 | |
| 900 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 901 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 902 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 903 | rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 904 | rmr_ring_free(3) |
| 905 | |
| 906 | |
| 907 | NAME |
| 908 | -------------------------------------------------------------------------------------------- |
| 909 | |
| 910 | rmr_get_src |
| 911 | |
| 912 | SYNOPSIS |
| 913 | -------------------------------------------------------------------------------------------- |
| 914 | |
| 915 | |
| 916 | :: |
| 917 | |
| 918 | #include <rmr/rmr.h> |
| 919 | unsigned char* rmr_get_src( rmr_mbuf_t* mbuf, unsigned char* dest ) |
| 920 | |
| 921 | |
| 922 | |
| 923 | DESCRIPTION |
| 924 | -------------------------------------------------------------------------------------------- |
| 925 | |
| 926 | The rmr_get_src function will copy the *source* information |
| 927 | from the message to a buffer (dest) supplied by the user. In |
| 928 | an RMr message, the source is the sender's information that |
| 929 | is used for return to sender function calls, and is generally |
| 930 | the hostname and port in the form *name*. The source might be |
| 931 | an IP address port combination; the data is populated by the |
| 932 | sending process and the only requirement is that it be |
| 933 | capable of being used to start a TCP session with the sender. |
| 934 | |
| 935 | The maximum size allowed by RMr is 64 bytes (including the |
| 936 | nil string terminator), so the user must ensure that the |
| 937 | destination buffer given is at least 64 bytes. |
| 938 | |
| 939 | RETURN VALUE |
| 940 | -------------------------------------------------------------------------------------------- |
| 941 | |
| 942 | On success, a pointer to the destination buffer is given as a |
| 943 | convenience to the user programme. On failure, a nil pointer |
| 944 | is returned and the value of errno is set. |
| 945 | |
| 946 | ERRORS |
| 947 | -------------------------------------------------------------------------------------------- |
| 948 | |
| 949 | If an error occurs, the value of the global variable errno |
| 950 | will be set to one of the following with the indicated |
| 951 | meaning. |
| 952 | |
| 953 | |
| 954 | |
| 955 | EINVAL |
| 956 | |
| 957 | The message, or an internal portion of the message, was |
| 958 | corrupted or the pointer was invalid. |
| 959 | |
| 960 | |
| 961 | SEE ALSO |
| 962 | -------------------------------------------------------------------------------------------- |
| 963 | |
| 964 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3), |
| 965 | rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3), |
| 966 | rmr_get_srcip(3), rmr_payload_size(3), rmr_send_msg(3), |
| 967 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 968 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 969 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 970 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 971 | |
| 972 | |
| 973 | NAME |
| 974 | -------------------------------------------------------------------------------------------- |
| 975 | |
| 976 | rmr_get_srcip |
| 977 | |
| 978 | SYNOPSIS |
| 979 | -------------------------------------------------------------------------------------------- |
| 980 | |
| 981 | |
| 982 | :: |
| 983 | |
| 984 | #include <rmr/rmr.h> |
| 985 | unsigned char* rmr_get_srcip( rmr_mbuf_t* mbuf, unsigned char* dest ) |
| 986 | |
| 987 | |
| 988 | |
| 989 | DESCRIPTION |
| 990 | -------------------------------------------------------------------------------------------- |
| 991 | |
| 992 | The rmr_get_srcip function will copy the *source IP address* |
| 993 | from the message to a buffer (dest) supplied by the user. In |
| 994 | an RMr message, the source IP address is the sender's |
| 995 | information that is used for return to sender function calls; |
| 996 | this function makes it available to the user application. The |
| 997 | address is maintained as IP:port where *IP* could be either |
| 998 | an IPv6 or IPv4 address depending on what was provided by the |
| 999 | sending application. |
| 1000 | |
| 1001 | The maximum size allowed by RMr is 64 bytes (including the |
| 1002 | nil string terminator), so the user must ensure that the |
| 1003 | destination buffer given is at least 64 bytes. The user |
| 1004 | application should use the RMr constant RMR_MAX_SRC to ensure |
| 1005 | that the buffer supplied is large enough, and to protect |
| 1006 | against future RMr enhancements which might increase the |
| 1007 | address buffer size requirement. |
| 1008 | |
| 1009 | RETURN VALUE |
| 1010 | -------------------------------------------------------------------------------------------- |
| 1011 | |
| 1012 | On success, a pointer to the destination buffer is given as a |
| 1013 | convenience to the user programme. On failure, a nil pointer |
| 1014 | is returned and the value of errno is set. |
| 1015 | |
| 1016 | ERRORS |
| 1017 | -------------------------------------------------------------------------------------------- |
| 1018 | |
| 1019 | If an error occurs, the value of the global variable errno |
| 1020 | will be set to one of the following with the indicated |
| 1021 | meaning. |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | EINVAL |
| 1026 | |
| 1027 | The message, or an internal portion of the message, was |
| 1028 | corrupted or the pointer was invalid. |
| 1029 | |
| 1030 | |
| 1031 | SEE ALSO |
| 1032 | -------------------------------------------------------------------------------------------- |
| 1033 | |
| 1034 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3), |
| 1035 | rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3), |
| 1036 | rmr_get_src(3), rmr_payload_size(3), rmr_send_msg(3), |
| 1037 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 1038 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 1039 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 1040 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 1041 | |
| 1042 | |
| 1043 | NAME |
| 1044 | -------------------------------------------------------------------------------------------- |
| 1045 | |
| 1046 | rmr_get_trace |
| 1047 | |
| 1048 | SYNOPSIS |
| 1049 | -------------------------------------------------------------------------------------------- |
| 1050 | |
| 1051 | |
| 1052 | :: |
| 1053 | |
| 1054 | #include <rmr/rmr.h> |
| 1055 | int rmr_get_trace( rmr_mbuf_t* mbuf, unsigned char* dest, int size ) |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | DESCRIPTION |
| 1060 | -------------------------------------------------------------------------------------------- |
| 1061 | |
| 1062 | The rmr_get_trace function will copy the trace information |
| 1063 | from the message into the user's allocated memory referenced |
| 1064 | by dest. The size parameter is assumed to be the maximum |
| 1065 | number of bytes which can be copied (size of the destination |
| 1066 | buffer). |
| 1067 | |
| 1068 | RETURN VALUE |
| 1069 | -------------------------------------------------------------------------------------------- |
| 1070 | |
| 1071 | On success, the number of bytes actually copied is returned. |
| 1072 | If the return value is 0, no bytes copied, then the reason |
| 1073 | could be that the message pointer was nil, or the size |
| 1074 | parameter was <= 0. |
| 1075 | |
| 1076 | SEE ALSO |
| 1077 | -------------------------------------------------------------------------------------------- |
| 1078 | |
| 1079 | rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3), |
| 1080 | rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3), |
| 1081 | rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3), |
| 1082 | rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3), |
| 1083 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 1084 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 1085 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 1086 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3), |
| 1087 | rmr_set_trace(3), rmr_trace_ref(3) |
| 1088 | |
| 1089 | |
| 1090 | NAME |
| 1091 | -------------------------------------------------------------------------------------------- |
| 1092 | |
| 1093 | rmr_get_trlen |
| 1094 | |
| 1095 | SYNOPSIS |
| 1096 | -------------------------------------------------------------------------------------------- |
| 1097 | |
| 1098 | |
| 1099 | :: |
| 1100 | |
| 1101 | #include <rmr/rmr.h> |
| 1102 | int rmr_get_trlen( rmr_mbuf_t* msg ); |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | DESCRIPTION |
| 1107 | -------------------------------------------------------------------------------------------- |
| 1108 | |
| 1109 | Given a message buffer, this function returns the amount of |
| 1110 | space (bytes) that have been allocated for trace data. If no |
| 1111 | trace data has been allocated, then 0 is returned. |
| 1112 | |
| 1113 | RETURN VALUE |
| 1114 | -------------------------------------------------------------------------------------------- |
| 1115 | |
| 1116 | The number of bytes allocated for trace information in the |
| 1117 | given message. |
| 1118 | |
| 1119 | ERRORS |
| 1120 | -------------------------------------------------------------------------------------------- |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | INVAL |
| 1125 | |
| 1126 | Parameter(s) passed to the function were not valid. |
| 1127 | |
| 1128 | |
| 1129 | SEE ALSO |
| 1130 | -------------------------------------------------------------------------------------------- |
| 1131 | |
| 1132 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 1133 | rmr_get_trace(3), rmr_init(3), rmr_init_trace(3), |
| 1134 | rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 1135 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 1136 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3), |
| 1137 | rmr_set_trace(3), rmr_tralloc_msg(3) |
| 1138 | |
| 1139 | |
| 1140 | NAME |
| 1141 | -------------------------------------------------------------------------------------------- |
| 1142 | |
| 1143 | rmr_get_xact |
| 1144 | |
| 1145 | SYNOPSIS |
| 1146 | -------------------------------------------------------------------------------------------- |
| 1147 | |
| 1148 | |
| 1149 | :: |
| 1150 | |
| 1151 | #include <rmr/rmr.h> |
| 1152 | char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest ) |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | DESCRIPTION |
| 1157 | -------------------------------------------------------------------------------------------- |
| 1158 | |
| 1159 | The rmr_get_xact function will copy the transaction field |
| 1160 | from the message into the *dest* buffer provided by the user. |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1161 | The buffer referenced by *dest* is assumed to be at least |
| 1162 | RMR_MAX_XID bytes in length. If *dest* is NULL, then a buffer |
| 1163 | is allocated (the calling application is expected to free |
| 1164 | when the buffer is no longer needed). |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1165 | |
| 1166 | RETURN VALUE |
| 1167 | -------------------------------------------------------------------------------------------- |
| 1168 | |
| 1169 | On success, a pointer to the extracted string is returned. If |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1170 | *dest* was supplied, then this is just a pointer to the |
| 1171 | caller's buffer. If *dest* was NULL, this is a pointer to the |
| 1172 | allocated buffer. If an error occurs, a nil pointer is |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1173 | returned and errno is set as described below. |
| 1174 | |
| 1175 | ERRORS |
| 1176 | -------------------------------------------------------------------------------------------- |
| 1177 | |
| 1178 | If an error occurs, the value of the global variable errno |
| 1179 | will be set to one of the following with the indicated |
| 1180 | meaning. |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | EINVAL |
| 1185 | |
| 1186 | The message, or an internal portion of the message, was |
| 1187 | corrupted or the pointer was invalid. |
| 1188 | |
| 1189 | |
| 1190 | ENOMEM |
| 1191 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1192 | A nil pointer was passed for *dest,* however it was not |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1193 | possible to allocate a buffer using malloc(). |
| 1194 | |
| 1195 | |
| 1196 | SEE ALSO |
| 1197 | -------------------------------------------------------------------------------------------- |
| 1198 | |
| 1199 | rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3), |
| 1200 | rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3), |
| 1201 | rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3), |
| 1202 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 1203 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 1204 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 1205 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 1206 | |
| 1207 | |
| 1208 | NAME |
| 1209 | -------------------------------------------------------------------------------------------- |
| 1210 | |
| 1211 | rmr_init |
| 1212 | |
| 1213 | SYNOPSIS |
| 1214 | -------------------------------------------------------------------------------------------- |
| 1215 | |
| 1216 | |
| 1217 | :: |
| 1218 | |
| 1219 | #include <rmr/rmr.h> |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1220 | void* rmr_init( char* proto_port, int norm_msg_size, int flags ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1221 | |
| 1222 | |
| 1223 | |
| 1224 | DESCRIPTION |
| 1225 | -------------------------------------------------------------------------------------------- |
| 1226 | |
| 1227 | The rmr_init function prepares the environment for sending |
| 1228 | and receiving messages. It does so by establishing a worker |
| 1229 | thread (pthread) which subscribes to a route table generator |
| 1230 | which provides the necessary routing information for the RMR |
| 1231 | library to send messages. |
| 1232 | |
| 1233 | *Port* is used to listen for connection requests from other |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1234 | RMR based applications. The *norm_msg_size* parameter is used |
| 1235 | to allocate receive buffers and should be set to what the |
| 1236 | user application expects to be a size which will hold the |
| 1237 | vast majority of expected messages. When computing the size, |
| 1238 | the application should consider the usual payload size |
| 1239 | **and** the maximum trace data size that will be used. This |
| 1240 | value is also used as the default message size when |
| 1241 | allocating message buffers (when a zero size is given to |
| 1242 | rmr_alloc_msg(); see the rmr_alloc_msg() manual page). |
| 1243 | Messages arriving which are longer than the given normal size |
| 1244 | will cause RMR to allocate a new buffer which is large enough |
| 1245 | for the arriving message. |
| 1246 | |
| 1247 | Starting with version 3.8.0 RMR no longer places a maximum |
| 1248 | buffer size for received messages. The underlying system |
| 1249 | memory manager might impose such a limit and the attempt to |
| 1250 | allocate a buffer larger than that limit will likely result |
| 1251 | in an application abort. Other than the potential performance |
| 1252 | impact from extra memory allocation and release, there is no |
| 1253 | penality to the user programme for specifyning a normal |
| 1254 | buffer size which is usually smaller than received buffers. |
| 1255 | Similarly, the only penality to the application for over |
| 1256 | specifying the normal buffer size might be a larger memory |
| 1257 | footprint. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1258 | |
| 1259 | *Flags* allows for selection of some RMr options at the time |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1260 | of initialisation. These are set by ORing RMRFL constants |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1261 | from the RMr header file. Currently the following flags are |
| 1262 | supported: |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | RMRFL_NONE |
| 1267 | |
| 1268 | No flags are set. |
| 1269 | |
| 1270 | |
| 1271 | RMRFL_NOTHREAD |
| 1272 | |
| 1273 | The route table collector thread is not to be started. |
| 1274 | This should only be used by the route table generator |
| 1275 | application if it is based on RMr. |
| 1276 | |
| 1277 | |
| 1278 | RMRFL_MTCALL |
| 1279 | |
| 1280 | Enable multi-threaded call support. |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 1281 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1282 | |
| 1283 | RMRFL_NOLOCK |
| 1284 | |
| 1285 | Some underlying transport providers (e.g. SI95) enable |
| 1286 | locking to be turned off if the user application is single |
| 1287 | threaded, or otherwise can guarantee that RMR functions |
| 1288 | will not be invoked concurrently from different threads. |
| 1289 | Turning off locking can help make message receipt more |
| 1290 | efficient. If this flag is set when the underlying |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 1291 | transport does not support disabling locks, it will be |
| 1292 | ignored. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1293 | |
| 1294 | |
| 1295 | Multi-threaded Calling |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1296 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1297 | |
| 1298 | The support for an application to issue a *blocking call* by |
| 1299 | the rmr_call() function was limited such that only user |
| 1300 | applications which were operating in a single thread could |
| 1301 | safely use the function. Further, timeouts were message count |
| 1302 | based and not time unit based. Multi-threaded call support |
| 1303 | adds the ability for a user application with multiple threads |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 1304 | to invoke a blocking call function with the guarantee that |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1305 | the correct response message is delivered to the thread. The |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1306 | additional support is implemented with the *rmr_mt_call()* |
| 1307 | and *rmr_mt_rcv()* function calls. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1308 | |
| 1309 | Multi-threaded call support requires the user application to |
| 1310 | specifically enable it when RMr is initialised. This is |
| 1311 | necessary because a second, dedicated, receiver thread must |
| 1312 | be started, and requires all messages to be examined and |
| 1313 | queued by this thread. The additional overhead is minimal, |
| 1314 | queuing information is all in the RMr message header, but as |
| 1315 | an additional process is necessary the user application must |
| 1316 | "opt in" to this approach. |
| 1317 | |
| 1318 | |
| 1319 | ENVIRONMENT |
| 1320 | -------------------------------------------------------------------------------------------- |
| 1321 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1322 | As a part of the initialisation process rmr_init reads |
| 1323 | environment variables to configure itself. The following |
| 1324 | variables are used if found. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1325 | |
| 1326 | |
| 1327 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1328 | RMR_ASYNC_CONN |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1329 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1330 | Allows the async connection mode to be turned off (by |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1331 | setting the value to 0). When set to 1, or missing from |
| 1332 | the environment, RMR will invoke the connection interface |
| 1333 | in the transport mechanism using the non-blocking (async) |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1334 | mode. This will likely result in many "soft failures" |
| 1335 | (retry) until the connection is established, but allows |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1336 | the application to continue unimpeded should the |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1337 | connection be slow to set up. |
| 1338 | |
| 1339 | |
| 1340 | RMR_BIND_IF |
| 1341 | |
| 1342 | This provides the interface that RMR will bind listen |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1343 | ports to, allowing for a single interface to be used |
| 1344 | rather than listening across all interfaces. This should |
| 1345 | be the IP address assigned to the interface that RMR |
| 1346 | should listen on, and if not defined RMR will listen on |
| 1347 | all interfaces. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1348 | |
| 1349 | |
| 1350 | RMR_CTL_PORT |
| 1351 | |
| 1352 | This variable defines the port that RMR should open for |
| 1353 | communications with Route Manager, and other RMR control |
| 1354 | applications. If not defined, the port 4561 is assumed. |
| 1355 | |
| 1356 | Previously, the RMR_RTG_SVC (route table generator service |
| 1357 | port) was used to define this port. However, a future |
| 1358 | version of Route Manager will require RMR to connect and |
| 1359 | request tables, thus that variable is now used to supply |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1360 | the Route Manager's well-known address and port. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1361 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1362 | To maintain backwards compatibility with the older Route |
| 1363 | Manager versions, the presence of this variable in the |
| 1364 | environment will shift RMR's behaviour with respect to the |
| 1365 | default value used when RMR_RTG_SVC is **not** defined. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1366 | |
| 1367 | When RMR_CTL_PORT is **defined:** RMR assumes that Route |
| 1368 | Manager requires RMR to connect and request table updates |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1369 | is made, and the default well-known address for Route |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1370 | manager is used (routemgr:4561). |
| 1371 | |
| 1372 | When RMR_CTL_PORT is **undefined:** RMR assumes that Route |
| 1373 | Manager will connect and push table updates, thus the |
| 1374 | default listen port (4561) is used. |
| 1375 | |
| 1376 | To avoid any possible misinterpretation and/or incorrect |
| 1377 | assumptions on the part of RMR, it is recommended that |
| 1378 | both the RMR_CTL_PORT and RMR_RTG_SVC be defined. In the |
| 1379 | case where both variables are defined, RMR will behave |
| 1380 | exactly as is communicated with the variable's values. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1381 | |
| 1382 | |
| 1383 | RMR_RTG_SVC |
| 1384 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1385 | The value of this variable depends on the Route Manager in |
| 1386 | use. |
| 1387 | |
| 1388 | When the Route Manager is expecting to connect to an xAPP |
| 1389 | and push route tables, this variable must indicate the |
| 1390 | port which RMR should use to listen for these connections. |
| 1391 | |
| 1392 | When the Route Manager is expecting RMR to connect and |
| 1393 | request a table update during initialisation, the variable |
| 1394 | should be the host of the Route Manager process. |
| 1395 | |
| 1396 | The RMR_CTL_PORT variable (added with the support of |
| 1397 | sending table update requests to Route manager), controls |
| 1398 | the behaviour if this variable is not set. See the |
| 1399 | description of that variable for details. |
| 1400 | |
| 1401 | |
| 1402 | RMR_HR_LOG |
| 1403 | |
| 1404 | By default RMR writes messages to standard error |
| 1405 | (incorrectly referred to as log messages) in human |
| 1406 | readable format. If this environment variable is set to 0, |
| 1407 | the format of standard error messages might be written in |
| 1408 | some format not easily read by humans. If missing, a value |
| 1409 | of 1 is assumed. |
| 1410 | |
| 1411 | |
| 1412 | RMR_LOG_VLEVEL |
| 1413 | |
| 1414 | This is a numeric value which corresponds to the verbosity |
| 1415 | level used to limit messages written to standard error. |
| 1416 | The lower the number the less chatty RMR functions are |
| 1417 | during execution. The following is the current |
| 1418 | relationship between the value set on this variable and |
| 1419 | the messages written: |
| 1420 | |
| 1421 | |
| 1422 | 0 |
| 1423 | |
| 1424 | Off; no messages of any sort are written. |
| 1425 | |
| 1426 | |
| 1427 | 1 |
| 1428 | |
| 1429 | Only critical messages are written (default if this |
| 1430 | variable does not exist) |
| 1431 | |
| 1432 | |
| 1433 | 2 |
| 1434 | |
| 1435 | Errors and all messages written with a lower value. |
| 1436 | |
| 1437 | |
| 1438 | 3 |
| 1439 | |
| 1440 | Warnings and all messages written with a lower value. |
| 1441 | |
| 1442 | |
| 1443 | 4 |
| 1444 | |
| 1445 | Informational and all messages written with a lower |
| 1446 | value. |
| 1447 | |
| 1448 | |
| 1449 | 5 |
| 1450 | |
| 1451 | Debugging mode -- all messages written, however this |
| 1452 | requires RMR to have been compiled with debugging |
| 1453 | support enabled. |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | RMR_RTG_ISRAW |
| 1458 | |
| 1459 | **Deprecated.** Should be set to 1 if the route table |
| 1460 | generator is sending "plain" messages (not using RMR to |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1461 | send messages), 0 if the RTG is using RMR to send. The |
| 1462 | default is 1 as we don't expect the RTG to use RMR. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1463 | |
| 1464 | This variable is only recognised when using the NNG |
| 1465 | transport library as it is not possible to support NNG |
| 1466 | "raw" communications with other transport libraries. It is |
| 1467 | also necessary to match the value of this variable with |
| 1468 | the capabilities of the Route Manager; at some point in |
| 1469 | the future RMR will assume that all Route Manager messages |
| 1470 | will arrive via an RMR connection and will ignore this |
| 1471 | variable. |
| 1472 | |
| 1473 | RMR_SEED_RT |
| 1474 | |
| 1475 | This is used to supply a static route table which can be |
| 1476 | used for debugging, testing, or if no route table |
| 1477 | generator process is being used to supply the route table. |
| 1478 | If not defined, no static table is used and RMR will not |
| 1479 | report *ready* until a table is received. The static route |
| 1480 | table may contain both the route table (between newrt |
| 1481 | start and end records), and the MEID map (between meid_map |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1482 | start and end records). |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 1483 | |
| 1484 | RMR_SRC_ID |
| 1485 | |
| 1486 | This is either the name or IP address which is placed into |
| 1487 | outbound messages as the message source. This will used |
| 1488 | when an RMR based application uses the rmr_rts_msg() |
| 1489 | function to return a response to the sender. If not |
| 1490 | supplied RMR will use the hostname which in some container |
| 1491 | environments might not be routable. |
| 1492 | |
| 1493 | The value of this variable is also used for Route Manager |
| 1494 | messages which are sent via an RMR connection. |
| 1495 | |
| 1496 | RMR_VCTL_FILE |
| 1497 | |
| 1498 | This supplies the name of a verbosity control file. The |
| 1499 | core RMR functions do not produce messages unless there is |
| 1500 | a critical failure. However, the route table collection |
| 1501 | thread, not a part of the main message processing |
| 1502 | component, can write additional messages to standard |
| 1503 | error. If this variable is set, RMR will extract the |
| 1504 | verbosity level for these messages (0 is silent) from the |
| 1505 | first line of the file. Changes to the file are detected |
| 1506 | and thus the level can be changed dynamically, however RMR |
| 1507 | will only suss out this variable during initialisation, so |
| 1508 | it is impossible to enable verbosity after startup. |
| 1509 | |
| 1510 | RMR_WARNINGS |
| 1511 | |
| 1512 | If set to 1, RMR will write some warnings which are |
| 1513 | non-performance impacting. If the variable is not defined, |
| 1514 | or set to 0, RMR will not write these additional warnings. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1515 | |
| 1516 | |
| 1517 | RETURN VALUE |
| 1518 | -------------------------------------------------------------------------------------------- |
| 1519 | |
| 1520 | The rmr_init function returns a void pointer (a contex if you |
| 1521 | will) that is passed as the first parameter to nearly all |
| 1522 | other RMR functions. If rmr_init is unable to properly |
| 1523 | initialise the environment, NULL is returned and errno is set |
| 1524 | to an appropriate value. |
| 1525 | |
| 1526 | ERRORS |
| 1527 | -------------------------------------------------------------------------------------------- |
| 1528 | |
| 1529 | The following error values are specifically set by this RMR |
| 1530 | function. In some cases the error message of a system call is |
| 1531 | propagated up, and thus this list might be incomplete. |
| 1532 | |
| 1533 | |
| 1534 | ENOMEM |
| 1535 | |
| 1536 | Unable to allocate memory. |
| 1537 | |
| 1538 | |
| 1539 | EXAMPLE |
| 1540 | -------------------------------------------------------------------------------------------- |
| 1541 | |
| 1542 | |
| 1543 | :: |
| 1544 | |
| 1545 | void* uh; |
| 1546 | rmr_mbuf* buf = NULL; |
| 1547 | uh = rmr_init( "43086", 4096, 0 ); |
| 1548 | buf = rmr_rcv_msg( uh, buf ); |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | SEE ALSO |
| 1553 | -------------------------------------------------------------------------------------------- |
| 1554 | |
| 1555 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 1556 | rmr_get_rcvfd(3), rmr_mt_call(3), rmr_mt_rcv(3), |
| 1557 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 1558 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 1559 | rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 1560 | rmr_ring_free(3) |
| 1561 | |
| 1562 | |
| 1563 | NAME |
| 1564 | -------------------------------------------------------------------------------------------- |
| 1565 | |
| 1566 | rmr_init_trace |
| 1567 | |
| 1568 | SYNOPSIS |
| 1569 | -------------------------------------------------------------------------------------------- |
| 1570 | |
| 1571 | |
| 1572 | :: |
| 1573 | |
| 1574 | #include <rmr/rmr.h> |
| 1575 | void* rmr_init_trace( void* ctx ) |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | DESCRIPTION |
| 1580 | -------------------------------------------------------------------------------------------- |
| 1581 | |
| 1582 | The rmr_init_trace function establishes the default trace |
| 1583 | space placed in each message buffer allocated with |
| 1584 | rmr_alloc_msg(). If this function is never called, then no |
| 1585 | trace space is allocated by default into any message buffer. |
| 1586 | |
| 1587 | Trace space allows the user application to pass some trace |
| 1588 | token, or other data with the message, but outside of the |
| 1589 | payload. Trace data may be added to any message with |
| 1590 | rmr_set_trace(), and may be extracted from a message with |
| 1591 | rmr_get_trace(). The number of bytes that a message contains |
| 1592 | for/with trace data can be determined by invoking |
| 1593 | rmr_get_trlen(). |
| 1594 | |
| 1595 | This function may be safely called at any time during the |
| 1596 | life of the user programme to (re)set the default trace space |
| 1597 | reserved. If the user programme needs to allocate a message |
| 1598 | with trace space of a different size than is allocated by |
| 1599 | default, without fear of extra overhead of reallocating a |
| 1600 | message later, the rmr_tralloc_msg() function can be used. |
| 1601 | |
| 1602 | RETURN VALUE |
| 1603 | -------------------------------------------------------------------------------------------- |
| 1604 | |
| 1605 | A value of 1 is returned on success, and 0 on failure. A |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1606 | failure indicates that the RMr context (a void pointer passed |
| 1607 | to this function was not valid. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1608 | |
| 1609 | SEE ALSO |
| 1610 | -------------------------------------------------------------------------------------------- |
| 1611 | |
| 1612 | rmr_alloc_msg(3), rmr_tr_alloc_msg(3), rmr_call(3), |
| 1613 | rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_trace(3), |
| 1614 | rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3), |
| 1615 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 1616 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 1617 | rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3) |
| 1618 | |
| 1619 | |
| 1620 | NAME |
| 1621 | -------------------------------------------------------------------------------------------- |
| 1622 | |
| 1623 | rmr_mt_call |
| 1624 | |
| 1625 | SYNOPSIS |
| 1626 | -------------------------------------------------------------------------------------------- |
| 1627 | |
| 1628 | |
| 1629 | :: |
| 1630 | |
| 1631 | #include <rmr/rmr.h> |
| 1632 | extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* msg, int id, int timeout ); |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | DESCRIPTION |
| 1637 | -------------------------------------------------------------------------------------------- |
| 1638 | |
| 1639 | The rmr_mt_call function sends the user application message |
| 1640 | to a remote endpoint, and waits for a corresponding response |
| 1641 | message before returning control to the user application. The |
| 1642 | user application supplies a completed message buffer, as it |
| 1643 | would for a rmr_send_msg call, but unlike with a send, the |
| 1644 | buffer returned will have the response from the application |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1645 | that received the message. The thread invoking the |
| 1646 | *rmr_mt_call()* will block until a message arrives or until |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1647 | *timeout* milliseconds has passed; which ever comes first. |
| 1648 | Using a timeout value of zero (0) will cause the thread to |
| 1649 | block without a timeout. |
| 1650 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1651 | The *id* supplied as the third parameter is an integer in the |
| 1652 | range of 2 through 255 inclusive. This is a caller defined |
| 1653 | "thread number" and is used to match the response message |
| 1654 | with the correct user application thread. If the ID value is |
| 1655 | not in the proper range, the attempt to make the call will |
| 1656 | fail. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1657 | |
| 1658 | Messages which are received while waiting for the response |
| 1659 | are queued on a *normal* receive queue and will be delivered |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1660 | to the user application with the next invocation of |
| 1661 | *rmr_mt_rcv()* or *rmr_rvv_msg().* by RMR, and are returned |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1662 | to the user application when rmr_rcv_msg is invoked. These |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1663 | messages are returned in the order received, one per call to |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1664 | rmr_rcv_msg. |
| 1665 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1666 | The Transaction ID |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1667 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1668 | |
| 1669 | The user application is responsible for setting the value of |
| 1670 | the transaction ID field before invoking *rmr_mt_call.* The |
| 1671 | transaction ID is a RMR_MAX_XID byte field that is used to |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1672 | match the response message when it arrives. RMR will compare |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1673 | **all** of the bytes in the field, so the caller must ensure |
| 1674 | that they are set correctly to avoid missing the response |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1675 | message. The application which returns the response message |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1676 | is also expected to ensure that the return buffer has the |
| 1677 | matching transaction ID. This can be done transparently if |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1678 | the application uses the *rmr_rts_msg()* function and does |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1679 | not adjust the transaction ID. |
| 1680 | |
| 1681 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1682 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1683 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1684 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1685 | until one of three conditions occurs: |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | 1. |
| 1690 | |
| 1691 | The message is sent without error |
| 1692 | |
| 1693 | |
| 1694 | 2. |
| 1695 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1696 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1697 | |
| 1698 | |
| 1699 | 3. |
| 1700 | |
| 1701 | The maximum number of retry loops has been attempted |
| 1702 | |
| 1703 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1704 | A retry loop consists of approximately 1000 send attempts |
| 1705 | **without** any intervening calls to *sleep()* or *usleep().* |
| 1706 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1707 | 1000 send attempts is performed before returning to the user |
| 1708 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1709 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1710 | allowing the user application to completely disable retires |
| 1711 | (set to 0), or to increase the number of retry loops. |
| 1712 | |
| 1713 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1714 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1715 | |
| 1716 | The underlying transport mechanism used to send messages is |
| 1717 | configured in *non-blocking* mode. This means that if a |
| 1718 | message cannot be sent immediately the transport mechanism |
| 1719 | will **not** pause with the assumption that the inability to |
| 1720 | send will clear quickly (within a few milliseconds). This |
| 1721 | means that when the retry loop is completely disabled (set to |
| 1722 | 0), that the failure to accept a message for sending by the |
| 1723 | underlying mechanisms (software or hardware) will be reported |
| 1724 | immediately to the user application. |
| 1725 | |
| 1726 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1727 | mechanism being used, it is extremely likely that retry |
| 1728 | conditions will happen during normal operations. These are |
| 1729 | completely out of RMR's control, and there is nothing that |
| 1730 | RMR can do to avoid or mitigate these other than by allowing |
| 1731 | RMR to retry the send operation, and even then it is possible |
| 1732 | (e.g., during connection reattempts), that a single retry |
| 1733 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1734 | |
| 1735 | RETURN VALUE |
| 1736 | -------------------------------------------------------------------------------------------- |
| 1737 | |
| 1738 | The rmr_mt_call function returns a pointer to a message |
| 1739 | buffer with the state set to reflect the overall state of |
| 1740 | call processing. If the state is RMR_OK then the buffer |
| 1741 | contains the response message; otherwise the state indicates |
| 1742 | the error encountered while attempting to send the message. |
| 1743 | |
| 1744 | If no response message is received when the timeout period |
| 1745 | has expired, a nil pointer will be returned (NULL). |
| 1746 | |
| 1747 | ERRORS |
| 1748 | -------------------------------------------------------------------------------------------- |
| 1749 | |
| 1750 | These values are reflected in the state field of the returned |
| 1751 | message. |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | RMR_OK |
| 1756 | |
| 1757 | The call was successful and the message buffer references |
| 1758 | the response message. |
| 1759 | |
| 1760 | |
| 1761 | RMR_ERR_BADARG |
| 1762 | |
| 1763 | An argument passed to the function was invalid. |
| 1764 | |
| 1765 | |
| 1766 | RMR_ERR_CALLFAILED |
| 1767 | |
| 1768 | The call failed and the value of *errno,* as described |
| 1769 | below, should be checked for the specific reason. |
| 1770 | |
| 1771 | |
| 1772 | RMR_ERR_NOENDPT |
| 1773 | |
| 1774 | An endpoint associated with the message type could not be |
| 1775 | found in the route table. |
| 1776 | |
| 1777 | |
| 1778 | RMR_ERR_RETRY |
| 1779 | |
| 1780 | The underlying transport mechanism was unable to accept |
| 1781 | the message for sending. The user application can retry |
| 1782 | the call operation if appropriate to do so. |
| 1783 | |
| 1784 | |
| 1785 | The global "variable" *errno* will be set to one of the |
| 1786 | following values if the overall call processing was not |
| 1787 | successful. |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | ETIMEDOUT |
| 1792 | |
| 1793 | Too many messages were queued before receiving the |
| 1794 | expected response |
| 1795 | |
| 1796 | |
| 1797 | ENOBUFS |
| 1798 | |
| 1799 | The queued message ring is full, messages were dropped |
| 1800 | |
| 1801 | |
| 1802 | EINVAL |
| 1803 | |
| 1804 | A parameter was not valid |
| 1805 | |
| 1806 | |
| 1807 | EAGAIN |
| 1808 | |
| 1809 | The underlying message system wsa interrupted or the |
| 1810 | device was busy; the message was **not** sent, and user |
| 1811 | application should call this function with the message |
| 1812 | again. |
| 1813 | |
| 1814 | |
| 1815 | EXAMPLE |
| 1816 | -------------------------------------------------------------------------------------------- |
| 1817 | |
| 1818 | The following code bit shows one way of using the rmr_mt_call |
| 1819 | function, and illustrates how the transaction ID must be set. |
| 1820 | |
| 1821 | |
| 1822 | :: |
| 1823 | |
| 1824 | int retries_left = 5; // max retries on dev not available |
| 1825 | static rmr_mbuf_t* mbuf = NULL; // response msg |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1826 | msg_t* pm; // appl message struct (payload) |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1827 | // get a send buffer and reference the payload |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1828 | mbuf = rmr_alloc_msg( mr, sizeof( pm->req ) ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1829 | pm = (msg_t*) mbuf->payload; |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1830 | // generate an xaction ID and fill in payload with data and msg type |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1831 | rmr_bytes2xact( mbuf, xid, RMR_MAX_XID ); |
| 1832 | snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" ); |
| 1833 | mbuf->mtype = MT_USR_RESP; |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1834 | msg = rmr_mt_call( mr, msg, my_id, 100 ); // wait up to 100ms |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1835 | if( ! msg ) { // probably a timeout and no msg received |
| 1836 | return NULL; // let errno trickle up |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1837 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1838 | if( mbuf->state != RMR_OK ) { |
| 1839 | while( retries_left-- > 0 && // loop as long as eagain |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1840 | mbuf->state == RMR_ERR_RETRY && |
| 1841 | (msg = rmr_mt_call( mr, msg )) != NULL && |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1842 | mbuf->state != RMR_OK ) { |
| 1843 | usleep( retry_delay ); |
| 1844 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1845 | if( mbuf == NULL || mbuf->state != RMR_OK ) { |
| 1846 | rmr_free_msg( mbuf ); // safe if nil |
| 1847 | return NULL; |
| 1848 | } |
| 1849 | } |
| 1850 | // do something with mbuf |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | SEE ALSO |
| 1855 | -------------------------------------------------------------------------------------------- |
| 1856 | |
| 1857 | rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3), |
| 1858 | rmr_mt_rcv(3), rmr_payload_size(3), rmr_send_msg(3), |
| 1859 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 1860 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 1861 | rmr_set_stimeout(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 1862 | rmr_ring_free(3) |
| 1863 | |
| 1864 | |
| 1865 | NAME |
| 1866 | -------------------------------------------------------------------------------------------- |
| 1867 | |
| 1868 | rmr_mt_rcv |
| 1869 | |
| 1870 | SYNOPSIS |
| 1871 | -------------------------------------------------------------------------------------------- |
| 1872 | |
| 1873 | |
| 1874 | :: |
| 1875 | |
| 1876 | #include <rmr/rmr.h> |
| 1877 | rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout ); |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | DESCRIPTION |
| 1882 | -------------------------------------------------------------------------------------------- |
| 1883 | |
| 1884 | The rmr_mt_rcv function blocks until a message is received, |
| 1885 | or the timeout period (milliseconds) has passed. The result |
| 1886 | is an RMr message buffer which references a received message. |
| 1887 | In the case of a timeout the state will be reflected in an |
| 1888 | "empty buffer" (if old_msg was not nil, or simply with the |
| 1889 | return of a nil pointer. If a timeout value of zero (0) is |
| 1890 | given, then the function will block until the next message |
| 1891 | received. |
| 1892 | |
| 1893 | The *vctx* pointer is the pointer returned by the rmr_init |
| 1894 | function. *Old_msg* is a pointer to a previously used message |
| 1895 | buffer or NULL. The ability to reuse message buffers helps to |
| 1896 | avoid alloc/free cycles in the user application. When no |
| 1897 | buffer is available to supply, the receive function will |
| 1898 | allocate one. |
| 1899 | |
| 1900 | The *old_msg* parameter allows the user to pass a previously |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1901 | generated RMR message back to RMR for reuse. Optionally, the |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1902 | user application may pass a nil pointer if no reusable |
| 1903 | message is available. When a timeout occurs, and old_msg was |
| 1904 | not nil, the state will be returned by returning a pointer to |
| 1905 | the old message with the state set. |
| 1906 | |
| 1907 | It is possible to use the *rmr_rcv_msg()* function instead of |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1908 | this function. Doing so might be advantageous if the user |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1909 | programme does not always start the multi-threaded mode and |
| 1910 | the use of *rmr_rcv_msg()* would make the flow of the code |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 1911 | more simple. The advantages of using this function are the |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1912 | ability to set a timeout without using epoll, and a small |
| 1913 | performance gain (if multi-threaded mode is enabled, and the |
| 1914 | *rmr_rcv_msg()* function is used, it simply invokes this |
| 1915 | function without a timeout value, thus there is the small |
| 1916 | cost of a second call that results). Similarly, the |
| 1917 | *rmr_torcv_msg()* call can be used when in multi-threaded |
| 1918 | mode with the same "pass through" overhead to using this |
| 1919 | function directly. |
| 1920 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1921 | RETURN VALUE |
| 1922 | -------------------------------------------------------------------------------------------- |
| 1923 | |
| 1924 | When a message is received before the timeout period expires, |
| 1925 | a pointer to the RMr message buffer which describes the |
| 1926 | message is returned. This will, with a high probability, be a |
| 1927 | different message buffer than *old_msg;* the user application |
| 1928 | should not continue to use *old_msg* after it is passed to |
| 1929 | this function. |
| 1930 | |
| 1931 | In the event of a timeout the return value will be the old |
| 1932 | msg with the state set, or a nil pointer if no old message |
| 1933 | was provided. |
| 1934 | |
| 1935 | ERRORS |
| 1936 | -------------------------------------------------------------------------------------------- |
| 1937 | |
| 1938 | The *state* field in the message buffer will be set to one of |
| 1939 | the following values: |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | RMR_OK |
| 1944 | |
| 1945 | The message was received without error. |
| 1946 | |
| 1947 | |
| 1948 | RMR_ERR_BADARG |
| 1949 | |
| 1950 | A parameter passed to the function was not valid (e.g. a |
| 1951 | nil pointer). indicate either RMR_OK or RMR_ERR_EMPTY if |
| 1952 | an empty message was received. |
| 1953 | |
| 1954 | |
| 1955 | RMR_ERR_EMPTY |
| 1956 | |
| 1957 | The message received had no associated data. The length of |
| 1958 | the message will be 0. |
| 1959 | |
| 1960 | |
| 1961 | RMR_ERR_NOTSUPP |
| 1962 | |
| 1963 | The multi-threaded option was not enabled when RMr was |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 1964 | initialised. See the man page for *rmr_init()* for |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 1965 | details. |
| 1966 | |
| 1967 | |
| 1968 | RMR_ERR_RCVFAILED |
| 1969 | |
| 1970 | A hard error occurred preventing the receive from |
| 1971 | completing. |
| 1972 | |
| 1973 | When a nil pointer is returned, or any other state value was |
| 1974 | set in the message buffer, errno will be set to one of the |
| 1975 | following: |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | INVAL |
| 1980 | |
| 1981 | Parameter(s) passed to the function were not valid. |
| 1982 | |
| 1983 | |
| 1984 | EBADF |
| 1985 | |
| 1986 | The underlying message transport is unable to process the |
| 1987 | request. |
| 1988 | |
| 1989 | |
| 1990 | ENOTSUP |
| 1991 | |
| 1992 | The underlying message transport is unable to process the |
| 1993 | request. |
| 1994 | |
| 1995 | |
| 1996 | EFSM |
| 1997 | |
| 1998 | The underlying message transport is unable to process the |
| 1999 | request. |
| 2000 | |
| 2001 | |
| 2002 | EAGAIN |
| 2003 | |
| 2004 | The underlying message transport is unable to process the |
| 2005 | request. |
| 2006 | |
| 2007 | |
| 2008 | EINTR |
| 2009 | |
| 2010 | The underlying message transport is unable to process the |
| 2011 | request. |
| 2012 | |
| 2013 | |
| 2014 | ETIMEDOUT |
| 2015 | |
| 2016 | The underlying message transport is unable to process the |
| 2017 | request. |
| 2018 | |
| 2019 | |
| 2020 | ETERM |
| 2021 | |
| 2022 | The underlying message transport is unable to process the |
| 2023 | request. |
| 2024 | |
| 2025 | |
| 2026 | EXAMPLE |
| 2027 | -------------------------------------------------------------------------------------------- |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | :: |
| 2032 | |
| 2033 | rmr_mbuf_t* mbuf = NULL; // received msg |
| 2034 | msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms |
| 2035 | if( msg != NULL ) { |
| 2036 | switch( msg->state ) { |
| 2037 | case RMR_OK: |
| 2038 | printf( "got a good message\\n" ); |
| 2039 | break; |
| 2040 | case RMR_ERR_EMPTY: |
| 2041 | printf( "received timed out\\n" ); |
| 2042 | break; |
| 2043 | default: |
| 2044 | printf( "receive error: %d\\n", mbuf->state ); |
| 2045 | break; |
| 2046 | } |
| 2047 | } else { |
| 2048 | printf( "receive timeout (nil)\\n" ); |
| 2049 | } |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | SEE ALSO |
| 2054 | -------------------------------------------------------------------------------------------- |
| 2055 | |
| 2056 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 2057 | rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3), |
| 2058 | rmr_mt_call(3), rmr_payload_size(3), rmr_send_msg(3), |
| 2059 | rmr_torcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 2060 | rmr_ready(3), rmr_ring_free(3), rmr_torcv_msg(3) |
| 2061 | |
| 2062 | |
| 2063 | NAME |
| 2064 | -------------------------------------------------------------------------------------------- |
| 2065 | |
| 2066 | rmr_payload_size |
| 2067 | |
| 2068 | SYNOPSIS |
| 2069 | -------------------------------------------------------------------------------------------- |
| 2070 | |
| 2071 | |
| 2072 | :: |
| 2073 | |
| 2074 | #include <rmr/rmr.h> |
| 2075 | int rmr_payload_size( rmr_mbuf_t* msg ); |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | DESCRIPTION |
| 2080 | -------------------------------------------------------------------------------------------- |
| 2081 | |
| 2082 | Given a message buffer, this function returns the amount of |
| 2083 | space (bytes) available for the user application to consume |
| 2084 | in the message payload. This is different than the message |
| 2085 | length available as a field in the message buffer. |
| 2086 | |
| 2087 | RETURN VALUE |
| 2088 | -------------------------------------------------------------------------------------------- |
| 2089 | |
| 2090 | The number of bytes available in the payload. |
| 2091 | |
| 2092 | ERRORS |
| 2093 | -------------------------------------------------------------------------------------------- |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | INVAL |
| 2098 | |
| 2099 | Parameter(s) passed to the function were not valid. |
| 2100 | |
| 2101 | |
| 2102 | SEE ALSO |
| 2103 | -------------------------------------------------------------------------------------------- |
| 2104 | |
| 2105 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 2106 | rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 2107 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 2108 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3) |
| 2109 | |
| 2110 | |
| 2111 | NAME |
| 2112 | -------------------------------------------------------------------------------------------- |
| 2113 | |
| 2114 | rmr_rcv_msg |
| 2115 | |
| 2116 | SYNOPSIS |
| 2117 | -------------------------------------------------------------------------------------------- |
| 2118 | |
| 2119 | |
| 2120 | :: |
| 2121 | |
| 2122 | #include <rmr/rmr.h> |
| 2123 | rmr_mbuf_t* rmr_rcv_msg( void* vctx, rmr_mbuf_t* old_msg ); |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | DESCRIPTION |
| 2128 | -------------------------------------------------------------------------------------------- |
| 2129 | |
| 2130 | The rmr_rcv_msg function blocks until a message is received, |
| 2131 | returning the message to the caller via a pointer to a |
| 2132 | rmr_mbuf_t structure type. If messages were queued while |
| 2133 | waiting for the response to a previous invocation of |
| 2134 | rmr_call, the oldest message is removed from the queue and |
| 2135 | returned without delay. |
| 2136 | |
| 2137 | The *vctx* pointer is the pointer returned by the rmr_init |
| 2138 | function. *Old_msg* is a pointer to a previously used message |
| 2139 | buffer or NULL. The ability to reuse message buffers helps to |
| 2140 | avoid alloc/free cycles in the user application. When no |
| 2141 | buffer is available to supply, the receive function will |
| 2142 | allocate one. |
| 2143 | |
| 2144 | RETURN VALUE |
| 2145 | -------------------------------------------------------------------------------------------- |
| 2146 | |
| 2147 | The function returns a pointer to the rmr_mbuf_t structure |
| 2148 | which references the message information (state, length, |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2149 | payload), or a nil pointer in the case of an extreme error. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2150 | |
| 2151 | ERRORS |
| 2152 | -------------------------------------------------------------------------------------------- |
| 2153 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2154 | The *state* field in the message buffer will indicate RMR_OK |
| 2155 | when the message receive process was successful and the |
| 2156 | message can be used by the caller. Depending on the |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 2157 | underlying transport mechanism, one of the following RMR |
| 2158 | error stats may be returned: |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | RMR_ERR_EMPTY |
| 2163 | |
| 2164 | The message received had no payload, or was completely |
| 2165 | empty. |
| 2166 | |
| 2167 | |
| 2168 | RMR_ERR_TIMEOUT |
| 2169 | |
| 2170 | For some transport mechanisms, or if reading the receive |
| 2171 | queue from multiple threads, it is possible for one thread |
| 2172 | to find no data waiting when it queries the queue. When |
| 2173 | this state is reported, the message buffer does not |
| 2174 | contain message data and the user application should |
| 2175 | reinvoke the receive function. |
| 2176 | |
| 2177 | |
| 2178 | When an RMR error state is reported, the underlying errno |
| 2179 | value might provide more information. The following is a list |
| 2180 | of possible values that might accompany the states listed |
| 2181 | above: |
| 2182 | |
| 2183 | RMR_ERR_EMPTY if an empty message was received. If a nil |
| 2184 | pointer is returned, or any other state value was set in the |
| 2185 | message buffer, errno will be set to one of the following: |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2186 | |
| 2187 | |
| 2188 | |
| 2189 | INVAL |
| 2190 | |
| 2191 | Parameter(s) passed to the function were not valid. |
| 2192 | |
| 2193 | |
| 2194 | EBADF |
| 2195 | |
| 2196 | The underlying message transport is unable to process the |
| 2197 | request. |
| 2198 | |
| 2199 | |
| 2200 | ENOTSUP |
| 2201 | |
| 2202 | The underlying message transport is unable to process the |
| 2203 | request. |
| 2204 | |
| 2205 | |
| 2206 | EFSM |
| 2207 | |
| 2208 | The underlying message transport is unable to process the |
| 2209 | request. |
| 2210 | |
| 2211 | |
| 2212 | EAGAIN |
| 2213 | |
| 2214 | The underlying message transport is unable to process the |
| 2215 | request. |
| 2216 | |
| 2217 | |
| 2218 | EINTR |
| 2219 | |
| 2220 | The underlying message transport is unable to process the |
| 2221 | request. |
| 2222 | |
| 2223 | |
| 2224 | ETIMEDOUT |
| 2225 | |
| 2226 | The underlying message transport is unable to process the |
| 2227 | request. |
| 2228 | |
| 2229 | |
| 2230 | ETERM |
| 2231 | |
| 2232 | The underlying message transport is unable to process the |
| 2233 | request. |
| 2234 | |
| 2235 | |
| 2236 | EXAMPLE |
| 2237 | -------------------------------------------------------------------------------------------- |
| 2238 | |
| 2239 | |
| 2240 | SEE ALSO |
| 2241 | -------------------------------------------------------------------------------------------- |
| 2242 | |
| 2243 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 2244 | rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3), |
| 2245 | rmr_payload_size(3), rmr_send_msg(3), rmr_torcv_msg(3), |
| 2246 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 2247 | rmr_ring_free(3), rmr_torcv_msg(3) |
| 2248 | |
| 2249 | |
| 2250 | NAME |
| 2251 | -------------------------------------------------------------------------------------------- |
| 2252 | |
| 2253 | rmr_ready |
| 2254 | |
| 2255 | SYNOPSIS |
| 2256 | -------------------------------------------------------------------------------------------- |
| 2257 | |
| 2258 | |
| 2259 | :: |
| 2260 | |
| 2261 | #include <rmr/rmr.h> |
| 2262 | int rmr_ready( void* vctx ); |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | DESCRIPTION |
| 2267 | -------------------------------------------------------------------------------------------- |
| 2268 | |
| 2269 | The rmr_ready function checks to see if a routing table has |
| 2270 | been successfully received and installed. The return value |
| 2271 | indicates the state of readiness. |
| 2272 | |
| 2273 | RETURN VALUE |
| 2274 | -------------------------------------------------------------------------------------------- |
| 2275 | |
| 2276 | A return value of 1 (true) indicates that the routing table |
| 2277 | is in place and attempts to send messages can be made. When 0 |
| 2278 | is returned (false) the routing table has not been received |
| 2279 | and thus attempts to send messages will fail with *no |
| 2280 | endpoint* errors. |
| 2281 | |
| 2282 | SEE ALSO |
| 2283 | -------------------------------------------------------------------------------------------- |
| 2284 | |
| 2285 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 2286 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 2287 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_fib(3), |
| 2288 | rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 2289 | rmr_ring_free(3) |
| 2290 | |
| 2291 | |
| 2292 | NAME |
| 2293 | -------------------------------------------------------------------------------------------- |
| 2294 | |
| 2295 | rmr_realloc_payload |
| 2296 | |
| 2297 | SYNOPSIS |
| 2298 | -------------------------------------------------------------------------------------------- |
| 2299 | |
| 2300 | |
| 2301 | :: |
| 2302 | |
| 2303 | #include <rmr/rmr.h> |
| 2304 | extern rmr_mbuf_t* rmr_realloc_payload( rmr_mbuf_t* msg, int new_len, int copy, int clone ); |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | DESCRIPTION |
| 2309 | -------------------------------------------------------------------------------------------- |
| 2310 | |
| 2311 | The rmr_realloc_payload function will return a pointer to an |
| 2312 | RMR message buffer struct (rmr_mbuf_t) which has a payload |
| 2313 | large enough to accomodate *new_len* bytes. If necessary, the |
| 2314 | underlying payload is reallocated, and the bytes from the |
| 2315 | original payload are copied if the *copy* parameter is true |
| 2316 | (1). If the message passed in has a payload large enough, |
| 2317 | there is no additional memory allocation and copying. |
| 2318 | |
| 2319 | Cloning The Message Buffer |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2320 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2321 | |
| 2322 | This function can also be used to generate a separate copy of |
| 2323 | the original message, with the desired payload size, without |
| 2324 | destroying the original message buffer or the original |
| 2325 | payload. A standalone copy is made only when the *clone* |
| 2326 | parameter is true (1). When cloning, the payload is copied to |
| 2327 | the cloned message **only** if the *copy* parameter is true. |
| 2328 | |
| 2329 | Message Buffer Metadata |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2330 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2331 | |
| 2332 | The metadata in the original message buffer (message type, |
| 2333 | subscription ID, and payload length) will be preserved if the |
| 2334 | *copy* parameter is true. When this parameter is not true |
| 2335 | (0), then these values are set to the uninitialised value |
| 2336 | (-1) for type and ID, and the length is set to 0. |
| 2337 | |
| 2338 | RETURN VALUE |
| 2339 | -------------------------------------------------------------------------------------------- |
| 2340 | |
| 2341 | The rmr_realloc_payload function returns a pointer to the |
| 2342 | message buffer with the payload which is large enough to hold |
| 2343 | *new_len* bytes. If the *clone* option is true, this will be |
| 2344 | a pointer to the newly cloned message buffer; the original |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2345 | message buffer pointer may still be used to reference that |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2346 | message. It is the calling application's responsibility to |
| 2347 | free the memory associateed with both messages using the |
| 2348 | rmr_free_msg() function. |
| 2349 | |
| 2350 | When the *clone* option is not used, it is still good |
| 2351 | practice by the calling application to capture and use this |
| 2352 | reference as it is possible that the message buffer, and not |
| 2353 | just the payload buffer, was reallocated. In the event of an |
| 2354 | error, a nil pointer will be returned and the value of |
| 2355 | *errno* will be set to reflect the problem. |
| 2356 | |
| 2357 | ERRORS |
| 2358 | -------------------------------------------------------------------------------------------- |
| 2359 | |
| 2360 | These value of *errno* will reflect the error condition if a |
| 2361 | nil pointer is returned: |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | ENOMEM |
| 2366 | |
| 2367 | Memory allocation of the new payload failed. |
| 2368 | |
| 2369 | |
| 2370 | EINVAL |
| 2371 | |
| 2372 | The pointer passed in was nil, or refrenced an invalid |
| 2373 | message, or the required length was not valid. |
| 2374 | |
| 2375 | |
| 2376 | EXAMPLE |
| 2377 | -------------------------------------------------------------------------------------------- |
| 2378 | |
| 2379 | The following code bit illustrates how this function can be |
| 2380 | used to reallocate a buffer for a return to sender |
| 2381 | acknowledgement message which is larger than the message |
| 2382 | received. |
| 2383 | |
| 2384 | |
| 2385 | :: |
| 2386 | |
| 2387 | if( rmr_payload_size( msg ) < ack_sz ) { // received message too small for ack |
| 2388 | msg = rmr_realloc_payload( msg, ack_sz, 0, 0 ); // reallocate the message with a payload big enough |
| 2389 | if( msg == NULL ) { |
| 2390 | fprintf( stderr, "[ERR] realloc returned a nil pointer: %s\\n", strerror( errno ) ); |
| 2391 | } else { |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2392 | // populate and send ack message |
| 2393 | } |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | SEE ALSO |
| 2399 | -------------------------------------------------------------------------------------------- |
| 2400 | |
| 2401 | rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3), |
| 2402 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 2403 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 2404 | rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3), |
| 2405 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3) |
| 2406 | |
| 2407 | |
| 2408 | NAME |
| 2409 | -------------------------------------------------------------------------------------------- |
| 2410 | |
| 2411 | rmr_rts_msg |
| 2412 | |
| 2413 | SYNOPSIS |
| 2414 | -------------------------------------------------------------------------------------------- |
| 2415 | |
| 2416 | |
| 2417 | :: |
| 2418 | |
| 2419 | #include <rmr/rmr.h> |
| 2420 | rmr_mbuf_t* rmr_rts_msg( void* vctx, rmr_mbuf_t* msg ); |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | DESCRIPTION |
| 2425 | -------------------------------------------------------------------------------------------- |
| 2426 | |
| 2427 | The rmr_rts_msg function sends a message returning it to the |
| 2428 | endpoint which sent the message rather than selecting an |
| 2429 | endpoint based on the message type and routing table. Other |
| 2430 | than this small difference, the behaviour is exactly the same |
| 2431 | as rmr_send_msg. |
| 2432 | |
| 2433 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2434 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2435 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2436 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2437 | until one of three conditions occurs: |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | 1. |
| 2442 | |
| 2443 | The message is sent without error |
| 2444 | |
| 2445 | |
| 2446 | 2. |
| 2447 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2448 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2449 | |
| 2450 | |
| 2451 | 3. |
| 2452 | |
| 2453 | The maximum number of retry loops has been attempted |
| 2454 | |
| 2455 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2456 | A retry loop consists of approximately 1000 send attempts |
| 2457 | **without** any intervening calls to *sleep()* or *usleep().* |
| 2458 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2459 | 1000 send attempts is performed before returning to the user |
| 2460 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2461 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2462 | allowing the user application to completely disable retires |
| 2463 | (set to 0), or to increase the number of retry loops. |
| 2464 | |
| 2465 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2466 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2467 | |
| 2468 | The underlying transport mechanism used to send messages is |
| 2469 | configured in *non-blocking* mode. This means that if a |
| 2470 | message cannot be sent immediately the transport mechanism |
| 2471 | will **not** pause with the assumption that the inability to |
| 2472 | send will clear quickly (within a few milliseconds). This |
| 2473 | means that when the retry loop is completely disabled (set to |
| 2474 | 0), that the failure to accept a message for sending by the |
| 2475 | underlying mechanisms (software or hardware) will be reported |
| 2476 | immediately to the user application. |
| 2477 | |
| 2478 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2479 | mechanism being used, it is extremely likely that retry |
| 2480 | conditions will happen during normal operations. These are |
| 2481 | completely out of RMR's control, and there is nothing that |
| 2482 | RMR can do to avoid or mitigate these other than by allowing |
| 2483 | RMR to retry the send operation, and even then it is possible |
| 2484 | (e.g., during connection reattempts), that a single retry |
| 2485 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2486 | |
| 2487 | PAYLOAD SIZE |
| 2488 | -------------------------------------------------------------------------------------------- |
| 2489 | |
| 2490 | When crafting a response based on a received message, the |
| 2491 | user application must take care not to write more bytes to |
| 2492 | the message payload than the allocated message has. In the |
| 2493 | case of a received message, it is possible that the response |
| 2494 | needs to be larger than the payload associated with the |
| 2495 | inbound message. In order to use the return to sender |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2496 | function, the source information in the original message must |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2497 | be present in the response; information which cannot be added |
| 2498 | to a message buffer allocated through the standard RMR |
| 2499 | allocation function. To allocate a buffer with a larger |
| 2500 | payload, and which retains the necessary sender data needed |
| 2501 | by this function, the *rmr_realloc_payload()* function must |
| 2502 | be used to extend the payload to a size suitable for the |
| 2503 | response. |
| 2504 | |
| 2505 | RETURN VALUE |
| 2506 | -------------------------------------------------------------------------------------------- |
| 2507 | |
| 2508 | On success, a new message buffer, with an empty payload, is |
| 2509 | returned for the application to use for the next send. The |
| 2510 | state in this buffer will reflect the overall send operation |
| 2511 | state and should be RMR_OK. |
| 2512 | |
| 2513 | If the state in the returned buffer is anything other than |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2514 | RMR_OK, the user application may need to attempt a |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2515 | retransmission of the message, or take other action depending |
| 2516 | on the setting of errno as described below. |
| 2517 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2518 | In the event of extreme failure, a nil pointer is returned. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2519 | In this case the value of errno might be of some use, for |
| 2520 | documentation, but there will be little that the user |
| 2521 | application can do other than to move on. |
| 2522 | |
| 2523 | ERRORS |
| 2524 | -------------------------------------------------------------------------------------------- |
| 2525 | |
| 2526 | The following values may be passed back in the *state* field |
| 2527 | of the returned message buffer. |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | RMR_ERR_BADARG |
| 2532 | |
| 2533 | The message buffer pointer did not refer to a valid |
| 2534 | message. |
| 2535 | |
| 2536 | RMR_ERR_NOHDR |
| 2537 | |
| 2538 | The header in the message buffer was not valid or |
| 2539 | corrupted. |
| 2540 | |
| 2541 | RMR_ERR_NOENDPT |
| 2542 | |
| 2543 | The message type in the message buffer did not map to a |
| 2544 | known endpoint. |
| 2545 | |
| 2546 | RMR_ERR_SENDFAILED |
| 2547 | |
| 2548 | The send failed; errno has the possible reason. |
| 2549 | |
| 2550 | |
| 2551 | The following values may be assigned to errno on failure. |
| 2552 | |
| 2553 | |
| 2554 | INVAL |
| 2555 | |
| 2556 | Parameter(s) passed to the function were not valid, or the |
| 2557 | underlying message processing environment was unable to |
| 2558 | interpret the message. |
| 2559 | |
| 2560 | |
| 2561 | ENOKEY |
| 2562 | |
| 2563 | The header information in the message buffer was invalid. |
| 2564 | |
| 2565 | |
| 2566 | ENXIO |
| 2567 | |
| 2568 | No known endpoint for the message could be found. |
| 2569 | |
| 2570 | |
| 2571 | EMSGSIZE |
| 2572 | |
| 2573 | The underlying transport refused to accept the message |
| 2574 | because of a size value issue (message was not attempted |
| 2575 | to be sent). |
| 2576 | |
| 2577 | |
| 2578 | EFAULT |
| 2579 | |
| 2580 | The message referenced by the message buffer is corrupt |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2581 | (nil pointer or bad internal length). |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2582 | |
| 2583 | |
| 2584 | EBADF |
| 2585 | |
| 2586 | Internal RMR error; information provided to the message |
| 2587 | transport environment was not valid. |
| 2588 | |
| 2589 | |
| 2590 | ENOTSUP |
| 2591 | |
| 2592 | Sending was not supported by the underlying message |
| 2593 | transport. |
| 2594 | |
| 2595 | |
| 2596 | EFSM |
| 2597 | |
| 2598 | The device is not in a state that can accept the message. |
| 2599 | |
| 2600 | |
| 2601 | EAGAIN |
| 2602 | |
| 2603 | The device is not able to accept a message for sending. |
| 2604 | The user application should attempt to resend. |
| 2605 | |
| 2606 | |
| 2607 | EINTR |
| 2608 | |
| 2609 | The operation was interrupted by delivery of a signal |
| 2610 | before the message was sent. |
| 2611 | |
| 2612 | |
| 2613 | ETIMEDOUT |
| 2614 | |
| 2615 | The underlying message environment timed out during the |
| 2616 | send process. |
| 2617 | |
| 2618 | |
| 2619 | ETERM |
| 2620 | |
| 2621 | The underlying message environment is in a shutdown state. |
| 2622 | |
| 2623 | |
| 2624 | EXAMPLE |
| 2625 | -------------------------------------------------------------------------------------------- |
| 2626 | |
| 2627 | |
| 2628 | SEE ALSO |
| 2629 | -------------------------------------------------------------------------------------------- |
| 2630 | |
| 2631 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 2632 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 2633 | rmr_rcv_specific(3), rmr_ready(3), rmr_fib(3), |
| 2634 | rmr_has_str(3), rmr_set_stimeout(3), rmr_tokenise(3), |
| 2635 | rmr_mk_ring(3), rmr_ring_free(3) |
| 2636 | |
| 2637 | |
| 2638 | NAME |
| 2639 | -------------------------------------------------------------------------------------------- |
| 2640 | |
| 2641 | rmr_send_msg |
| 2642 | |
| 2643 | SYNOPSIS |
| 2644 | -------------------------------------------------------------------------------------------- |
| 2645 | |
| 2646 | |
| 2647 | :: |
| 2648 | |
| 2649 | #include <rmr/rmr.h> |
| 2650 | rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg ); |
| 2651 | |
| 2652 | |
| 2653 | |
| 2654 | DESCRIPTION |
| 2655 | -------------------------------------------------------------------------------------------- |
| 2656 | |
| 2657 | The rmr_send_msg function accepts a message buffer from the |
| 2658 | user application and attempts to send it. The destination of |
| 2659 | the message is selected based on the message type specified |
| 2660 | in the message buffer, and the matching information in the |
| 2661 | routing tables which are currently in use by the RMR library. |
| 2662 | This may actually result in the sending of the message to |
| 2663 | multiple destinations which could degrade expected overall |
| 2664 | performance of the user application. (Limiting excessive |
| 2665 | sending of messages is the responsibility of the |
| 2666 | application(s) responsible for building the routing table |
| 2667 | used by the RMR library, and not the responsibility of the |
| 2668 | library.) |
| 2669 | |
| 2670 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2671 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2672 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2673 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2674 | until one of three conditions occurs: |
| 2675 | |
| 2676 | |
| 2677 | |
| 2678 | 1. |
| 2679 | |
| 2680 | The message is sent without error |
| 2681 | |
| 2682 | |
| 2683 | 2. |
| 2684 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2685 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2686 | |
| 2687 | |
| 2688 | 3. |
| 2689 | |
| 2690 | The maximum number of retry loops has been attempted |
| 2691 | |
| 2692 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2693 | A retry loop consists of approximately 1000 send attempts |
| 2694 | **without** any intervening calls to *sleep()* or *usleep().* |
| 2695 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2696 | 1000 send attempts is performed before returning to the user |
| 2697 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2698 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2699 | allowing the user application to completely disable retires |
| 2700 | (set to 0), or to increase the number of retry loops. |
| 2701 | |
| 2702 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2703 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2704 | |
| 2705 | The underlying transport mechanism used to send messages is |
| 2706 | configured in *non-blocking* mode. This means that if a |
| 2707 | message cannot be sent immediately the transport mechanism |
| 2708 | will **not** pause with the assumption that the inability to |
| 2709 | send will clear quickly (within a few milliseconds). This |
| 2710 | means that when the retry loop is completely disabled (set to |
| 2711 | 0), that the failure to accept a message for sending by the |
| 2712 | underlying mechanisms (software or hardware) will be reported |
| 2713 | immediately to the user application. |
| 2714 | |
| 2715 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2716 | mechanism being used, it is extremely likely that retry |
| 2717 | conditions will happen during normal operations. These are |
| 2718 | completely out of RMR's control, and there is nothing that |
| 2719 | RMR can do to avoid or mitigate these other than by allowing |
| 2720 | RMR to retry the send operation, and even then it is possible |
| 2721 | (e.g., during connection reattempts), that a single retry |
| 2722 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2723 | |
| 2724 | RETURN VALUE |
| 2725 | -------------------------------------------------------------------------------------------- |
| 2726 | |
| 2727 | On success, a new message buffer, with an empty payload, is |
| 2728 | returned for the application to use for the next send. The |
| 2729 | state in this buffer will reflect the overall send operation |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 2730 | state and will be RMR_OK when the send was successful. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2731 | |
| 2732 | When the message cannot be successfully sent this function |
| 2733 | will return the unsent (original) message buffer with the |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2734 | state set to indicate the reason for failure. The value of |
| 2735 | *errno* may also be set to reflect a more detailed failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2736 | reason if it is known. |
| 2737 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2738 | In the event of extreme failure, a nil pointer is returned. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2739 | In this case the value of errno might be of some use, for |
| 2740 | documentation, but there will be little that the user |
| 2741 | application can do other than to move on. |
| 2742 | |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 2743 | **CAUTION:** In some cases it is extremely likely that the |
| 2744 | message returned by the send function does **not** reference |
| 2745 | the same memory structure. Thus is important for the user |
| 2746 | programme to capture the new pointer for future use or to be |
| 2747 | passed to rmr_free(). If you are experiencing either double |
| 2748 | free errors or segment faults in either rmr_free() or |
| 2749 | rmr_send_msg(), ensure that the return value from this |
| 2750 | function is being captured and used. |
| 2751 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2752 | ERRORS |
| 2753 | -------------------------------------------------------------------------------------------- |
| 2754 | |
| 2755 | The following values may be passed back in the *state* field |
| 2756 | of the returned message buffer. |
| 2757 | |
| 2758 | |
| 2759 | |
| 2760 | RMR_RETRY |
| 2761 | |
| 2762 | The message could not be sent, but the underlying |
| 2763 | transport mechanism indicates that the failure is |
| 2764 | temporary. If the send operation is tried again it might |
| 2765 | be successful. |
| 2766 | |
| 2767 | RMR_SEND_FAILED |
| 2768 | |
| 2769 | The send operation was not successful and the underlying |
| 2770 | transport mechanism indicates a permanent (hard) failure; |
| 2771 | retrying the send is not possible. |
| 2772 | |
| 2773 | RMR_ERR_BADARG |
| 2774 | |
| 2775 | The message buffer pointer did not refer to a valid |
| 2776 | message. |
| 2777 | |
| 2778 | RMR_ERR_NOHDR |
| 2779 | |
| 2780 | The header in the message buffer was not valid or |
| 2781 | corrupted. |
| 2782 | |
| 2783 | RMR_ERR_NOENDPT |
| 2784 | |
| 2785 | The message type in the message buffer did not map to a |
| 2786 | known endpoint. |
| 2787 | |
| 2788 | |
| 2789 | The following values may be assigned to errno on failure. |
| 2790 | |
| 2791 | |
| 2792 | INVAL |
| 2793 | |
| 2794 | Parameter(s) passed to the function were not valid, or the |
| 2795 | underlying message processing environment was unable to |
| 2796 | interpret the message. |
| 2797 | |
| 2798 | |
| 2799 | ENOKEY |
| 2800 | |
| 2801 | The header information in the message buffer was invalid. |
| 2802 | |
| 2803 | |
| 2804 | ENXIO |
| 2805 | |
| 2806 | No known endpoint for the message could be found. |
| 2807 | |
| 2808 | |
| 2809 | EMSGSIZE |
| 2810 | |
| 2811 | The underlying transport refused to accept the message |
| 2812 | because of a size value issue (message was not attempted |
| 2813 | to be sent). |
| 2814 | |
| 2815 | |
| 2816 | EFAULT |
| 2817 | |
| 2818 | The message referenced by the message buffer is corrupt |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2819 | (nil pointer or bad internal length). |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2820 | |
| 2821 | |
| 2822 | EBADF |
| 2823 | |
| 2824 | Internal RMR error; information provided to the message |
| 2825 | transport environment was not valid. |
| 2826 | |
| 2827 | |
| 2828 | ENOTSUP |
| 2829 | |
| 2830 | Sending was not supported by the underlying message |
| 2831 | transport. |
| 2832 | |
| 2833 | |
| 2834 | EFSM |
| 2835 | |
| 2836 | The device is not in a state that can accept the message. |
| 2837 | |
| 2838 | |
| 2839 | EAGAIN |
| 2840 | |
| 2841 | The device is not able to accept a message for sending. |
| 2842 | The user application should attempt to resend. |
| 2843 | |
| 2844 | |
| 2845 | EINTR |
| 2846 | |
| 2847 | The operation was interrupted by delivery of a signal |
| 2848 | before the message was sent. |
| 2849 | |
| 2850 | |
| 2851 | ETIMEDOUT |
| 2852 | |
| 2853 | The underlying message environment timed out during the |
| 2854 | send process. |
| 2855 | |
| 2856 | |
| 2857 | ETERM |
| 2858 | |
| 2859 | The underlying message environment is in a shutdown state. |
| 2860 | |
| 2861 | |
| 2862 | EXAMPLE |
| 2863 | -------------------------------------------------------------------------------------------- |
| 2864 | |
| 2865 | The following is a simple example of how the rmr_send_msg |
| 2866 | function is called. In this example, the send message buffer |
| 2867 | is saved between calls and reused eliminating alloc/free |
| 2868 | cycles. |
| 2869 | |
| 2870 | |
| 2871 | :: |
| 2872 | |
| 2873 | static rmr_mbuf_t* send_msg = NULL; // message to send; reused on each call |
| 2874 | msg_t* send_pm; // payload for send |
| 2875 | msg_t* pm; // our message format in the received payload |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2876 | if( send_msg == NULL ) { |
| 2877 | send_msg = rmr_alloc_msg( mr, MAX_SIZE ); // new buffer to send |
| 2878 | } |
| 2879 | // reference payload and fill in message type |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2880 | pm = (msg_t*) send_msg->payload; |
E. Scott Daniels | a1575da | 2020-01-24 16:00:11 -0500 | [diff] [blame] | 2881 | send_msg->mtype = MT_ANSWER; |
| 2882 | msg->len = generate_data( pm ); // something that fills the payload in |
| 2883 | msg = rmr_send_msg( mr, send_msg ); // ensure new pointer used after send |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2884 | if( ! msg ) { |
| 2885 | return ERROR; |
| 2886 | } else { |
| 2887 | if( msg->state != RMR_OK ) { |
| 2888 | // check for RMR_ERR_RETRY, and resend if needed |
| 2889 | // else return error |
| 2890 | } |
| 2891 | } |
| 2892 | return OK; |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2893 | |
| 2894 | |
| 2895 | |
| 2896 | SEE ALSO |
| 2897 | -------------------------------------------------------------------------------------------- |
| 2898 | |
| 2899 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 2900 | rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 2901 | rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3), |
| 2902 | rmr_ring_free(3), rmr_torcv_rcv(3), rmr_wh_send_msg(3) |
| 2903 | |
| 2904 | |
| 2905 | NAME |
| 2906 | -------------------------------------------------------------------------------------------- |
| 2907 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 2908 | rmr_set_fack |
| 2909 | |
| 2910 | SYNOPSIS |
| 2911 | -------------------------------------------------------------------------------------------- |
| 2912 | |
| 2913 | |
| 2914 | :: |
| 2915 | |
| 2916 | #include <rmr/rmr.h> |
| 2917 | void rmr_set_fack( void* vctx ); |
| 2918 | |
| 2919 | |
| 2920 | |
| 2921 | DESCRIPTION |
| 2922 | -------------------------------------------------------------------------------------------- |
| 2923 | |
| 2924 | The rmr_set_fack function enables *fast TCP acknowledgements* |
| 2925 | if the underlying transport library supports it. This might |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 2926 | be useful for applications which must send messages at a |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 2927 | maximum rate. |
| 2928 | |
| 2929 | RETURN VALUE |
| 2930 | -------------------------------------------------------------------------------------------- |
| 2931 | |
| 2932 | There is no return value. |
| 2933 | |
| 2934 | ERRORS |
| 2935 | -------------------------------------------------------------------------------------------- |
| 2936 | |
| 2937 | This function does not generate any errors. |
| 2938 | |
| 2939 | SEE ALSO |
| 2940 | -------------------------------------------------------------------------------------------- |
| 2941 | |
| 2942 | rmr_init(3), |
| 2943 | |
| 2944 | |
| 2945 | NAME |
| 2946 | -------------------------------------------------------------------------------------------- |
| 2947 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2948 | rmr_set_stimeout |
| 2949 | |
| 2950 | SYNOPSIS |
| 2951 | -------------------------------------------------------------------------------------------- |
| 2952 | |
| 2953 | |
| 2954 | :: |
| 2955 | |
| 2956 | #include <rmr/rmr.h> |
| 2957 | rmr_mbuf_t* rmr_set_stimeout( void* vctx, int rloops ); |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | DESCRIPTION |
| 2962 | -------------------------------------------------------------------------------------------- |
| 2963 | |
| 2964 | The rmr_set_stimeout function sets the configuration for how |
| 2965 | RMr will retry message send operations which complete with |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2966 | either a *timeout* or *again* completion value. (Send |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2967 | operations include all of the possible message send |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2968 | functions: *rmr_send_msg(), rmr_call(), rmr_rts_msg()* and |
| 2969 | *rmr_wh_send_msg().* The *rloops* parameter sets the maximum |
| 2970 | number of retry loops that will be attempted before giving up |
| 2971 | and returning the unsuccessful state to the user application. |
| 2972 | Each retry loop is approximately 1000 attempts, and RMr does |
| 2973 | **not** invoke any sleep function between retries in the |
| 2974 | loop; a small, 1 mu-sec, sleep is executed between loop sets |
| 2975 | if the *rloops* value is greater than 1. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2976 | |
| 2977 | |
| 2978 | Disabling Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 2979 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2980 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2981 | By default, the send operations will execute with an *rloop* |
| 2982 | setting of 1; each send operation will attempt to resend the |
| 2983 | message approximately 1000 times before giving up. If the |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2984 | user application does not want to have send operations retry |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2985 | when the underlying transport mechanism indicates *timeout* |
| 2986 | or *again,* the application should invoke this function and |
| 2987 | pass a value of 0 (zero) for *rloops.* With this setting, all |
| 2988 | RMr send operations will attempt a send operation only |
| 2989 | **once,** returning immediately to the caller with the state |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2990 | of that single attempt. |
| 2991 | |
| 2992 | RETURN VALUE |
| 2993 | -------------------------------------------------------------------------------------------- |
| 2994 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 2995 | This function returns a -1 to indicate that the *rloops* |
| 2996 | value could not be set, and the value *RMR_OK* to indicate |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 2997 | success. |
| 2998 | |
| 2999 | ERRORS |
| 3000 | -------------------------------------------------------------------------------------------- |
| 3001 | |
E. Scott Daniels | b7a4b52 | 2019-11-07 15:35:17 -0500 | [diff] [blame] | 3002 | Currently errno is **not** set by this function; the only |
| 3003 | cause of a failure is an invalid context (*vctx*) pointer. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3004 | |
| 3005 | EXAMPLE |
| 3006 | -------------------------------------------------------------------------------------------- |
| 3007 | |
| 3008 | The following is a simple example of how the rmr_set_stimeout |
| 3009 | function is called. |
| 3010 | |
| 3011 | |
| 3012 | :: |
| 3013 | |
| 3014 | #define NO_FLAGS 0 |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3015 | char* port = "43086"; // port for message router listen |
| 3016 | int max_size = 4096; // max message size for default allocations |
| 3017 | void* mr_context; // message router context |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3018 | mr_context = rmr_init( port, max_size, NO_FLAGS ); |
| 3019 | if( mr_context != NULL ) { |
| 3020 | rmr_set_stimeout( mr_context, 0 ); // turn off retries |
| 3021 | } |
| 3022 | |
| 3023 | |
| 3024 | |
| 3025 | SEE ALSO |
| 3026 | -------------------------------------------------------------------------------------------- |
| 3027 | |
| 3028 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 3029 | rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 3030 | rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3), |
| 3031 | rmr_ring_free(3), rmr_send_msg(3), rmr_torcv_rcv(3), |
| 3032 | rmr_wh_send_msg(3) |
| 3033 | |
| 3034 | |
| 3035 | NAME |
| 3036 | -------------------------------------------------------------------------------------------- |
| 3037 | |
| 3038 | rmr_set_trace |
| 3039 | |
| 3040 | SYNOPSIS |
| 3041 | -------------------------------------------------------------------------------------------- |
| 3042 | |
| 3043 | |
| 3044 | :: |
| 3045 | |
| 3046 | #include <rmr/rmr.h> |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 3047 | int rmr_set_trace( rmr_mbuf_t* mbuf, unsigned char* data, int len ) |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3048 | |
| 3049 | |
| 3050 | |
| 3051 | DESCRIPTION |
| 3052 | -------------------------------------------------------------------------------------------- |
| 3053 | |
| 3054 | The rmr_set_trace function will copy len bytes from data into |
| 3055 | the trace portion of mbuf. If the trace area of mbuf is not |
| 3056 | the correct size, the message buffer will be reallocated to |
| 3057 | ensure that enough space is available for the trace data. |
| 3058 | |
| 3059 | RETURN VALUE |
| 3060 | -------------------------------------------------------------------------------------------- |
| 3061 | |
| 3062 | The rmr_set_trace function returns the number of bytes |
| 3063 | successfully copied to the message. If 0 is returned either |
| 3064 | the message pointer was nil, or the size in the parameters |
| 3065 | was <= 0. |
| 3066 | |
| 3067 | SEE ALSO |
| 3068 | -------------------------------------------------------------------------------------------- |
| 3069 | |
| 3070 | rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3), |
| 3071 | rmr_bytes2payload(3), rmr_call(3), rmr_free_msg(3), |
| 3072 | rmr_get_rcvfd(3), rmr_get_meid(3), rmr_get_trace(3), |
| 3073 | rmr_get_trlen(3), rmr_init(3), rmr_init_trace(3), |
| 3074 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 3075 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 3076 | rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3), |
| 3077 | rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3), |
| 3078 | rmr_wh_open(3), rmr_wh_send_msg(3) |
| 3079 | |
| 3080 | |
| 3081 | NAME |
| 3082 | -------------------------------------------------------------------------------------------- |
| 3083 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3084 | rmr_set_vlevel |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 3085 | |
| 3086 | SYNOPSIS |
| 3087 | -------------------------------------------------------------------------------------------- |
| 3088 | |
| 3089 | |
| 3090 | :: |
| 3091 | |
| 3092 | #include <rmr/rmr.h> |
| 3093 | #include <rmr/rmr_logging.h> |
| 3094 | void rmr_set_vlevel( int new_level ) |
| 3095 | |
| 3096 | |
| 3097 | |
| 3098 | DESCRIPTION |
| 3099 | -------------------------------------------------------------------------------------------- |
| 3100 | |
| 3101 | The rmr_set_vlevel allows the user programme to set the |
| 3102 | verbosity level which is used to determine the messages RMR |
| 3103 | writes to standard error. The new_vlevel value must be one of |
| 3104 | the following constants which have the indicated meanings: |
| 3105 | |
| 3106 | |
| 3107 | RMR_VL_OFF |
| 3108 | |
| 3109 | Turns off all message writing. This includes the stats and |
| 3110 | debugging messages generated by the route collector thread |
| 3111 | which are normally affected only by the externally managed |
| 3112 | verbose level file (and related environment variable). |
| 3113 | |
| 3114 | |
| 3115 | RMR_VL_CRIT |
| 3116 | |
| 3117 | Write only messages of critical importance. From the point |
| 3118 | of view of RMR, when a critical proper behaviour of the |
| 3119 | library cannot be expected or guaranteed. |
| 3120 | |
| 3121 | RMR_VL_ERR |
| 3122 | |
| 3123 | Include error messages in the output. An error is an event |
| 3124 | from which RMR has no means to recover. Continued proper |
| 3125 | execution is likely except where the affected connection |
| 3126 | and/or component mentioned in the error is concerned. |
| 3127 | |
| 3128 | RMR_VL_WARN |
| 3129 | |
| 3130 | Include warning messages in the output. A warning |
| 3131 | indicates an event which is not considered to be normal, |
| 3132 | but is expected and continued acceptable behaviour of the |
| 3133 | system is assured. |
| 3134 | |
| 3135 | RMR_VL_INFO |
| 3136 | |
| 3137 | Include informational messagees in the output. |
| 3138 | Informational messages include some diagnostic information |
| 3139 | which explain the activities of RMR. |
| 3140 | |
| 3141 | RMR_VL_DEBUG |
| 3142 | |
| 3143 | Include all debugging messages in the output. Debugging |
| 3144 | must have also been enabled during the build as a |
| 3145 | precaution to accidentally enabling this level of output |
| 3146 | as it can grossly affect performance. |
| 3147 | |
| 3148 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3149 | Generally RMR does not write messages to the standard error |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 3150 | device from *critical path* functions, therefore it is |
| 3151 | usually not harmful to enable a verbosity level of either |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3152 | RMR_VL_CRIT or RMR_VL_ERR. |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 3153 | |
| 3154 | Messages written from the route table collection thread are |
| 3155 | still governed by the value placed into the verbose level |
| 3156 | control file (see the man page for rmr_init()); those |
| 3157 | messages are affected only when logging is completely |
| 3158 | disabled by passing RMR_VL_OFF to this function. |
| 3159 | |
| 3160 | The verbosity level can also be set via an environment |
| 3161 | variable prior to the start of the RMR based application. The |
| 3162 | environment variable is read only during initialisation; if |
| 3163 | the programme must change the value during execution, this |
| 3164 | function must be used. The default value, if this function is |
| 3165 | never called, and the environment variable is not present, is |
| 3166 | RMR_VL_ERR. |
| 3167 | |
| 3168 | SEE ALSO |
| 3169 | -------------------------------------------------------------------------------------------- |
| 3170 | |
| 3171 | rmr_init(3) |
| 3172 | |
| 3173 | |
| 3174 | NAME |
| 3175 | -------------------------------------------------------------------------------------------- |
| 3176 | |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3177 | rmr_str2meid |
| 3178 | |
| 3179 | SYNOPSIS |
| 3180 | -------------------------------------------------------------------------------------------- |
| 3181 | |
| 3182 | |
| 3183 | :: |
| 3184 | |
| 3185 | #include <rmr/rmr.h> |
| 3186 | int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len ) |
| 3187 | |
| 3188 | |
| 3189 | |
| 3190 | DESCRIPTION |
| 3191 | -------------------------------------------------------------------------------------------- |
| 3192 | |
| 3193 | The rmr_str2meid function will copy the string pointed to by |
E. Scott Daniels | 190665f | 2019-12-09 09:05:22 -0500 | [diff] [blame] | 3194 | src to the managed entity ID (meid) field in the given |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3195 | message. The field is a fixed length, gated by the constant |
| 3196 | RMR_MAX_MEID and if string length is larger than this value, |
| 3197 | then **nothing** will be copied. (Note, this differs slightly |
| 3198 | from the behaviour of the lrmr_bytes2meid() function.) |
| 3199 | |
| 3200 | RETURN VALUE |
| 3201 | -------------------------------------------------------------------------------------------- |
| 3202 | |
| 3203 | On success, the value RMR_OK is returned. If the string |
| 3204 | cannot be copied to the message, the return value will be one |
| 3205 | of the errors listed below. |
| 3206 | |
| 3207 | ERRORS |
| 3208 | -------------------------------------------------------------------------------------------- |
| 3209 | |
| 3210 | If the return value is not RMR_OK, then it will be set to one |
| 3211 | of the values below. |
| 3212 | |
| 3213 | |
| 3214 | |
| 3215 | RMR_ERR_BADARG |
| 3216 | |
| 3217 | The message, or an internal portion of the message, was |
| 3218 | corrupted or the pointer was invalid. |
| 3219 | |
| 3220 | |
| 3221 | RMR_ERR_OVERFLOW |
| 3222 | |
| 3223 | The length passed in was larger than the maximum length of |
| 3224 | the field; only a portion of the source bytes were copied. |
| 3225 | |
| 3226 | |
| 3227 | EXAMPLE |
| 3228 | -------------------------------------------------------------------------------------------- |
| 3229 | |
| 3230 | |
| 3231 | SEE ALSO |
| 3232 | -------------------------------------------------------------------------------------------- |
| 3233 | |
| 3234 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 3235 | rmr_get_meid(3), rmr_get_rcvfd(3), rmr_payload_size(3), |
| 3236 | rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 3237 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 3238 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3), |
| 3239 | rmr_bytes2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 3240 | |
| 3241 | |
| 3242 | NAME |
| 3243 | -------------------------------------------------------------------------------------------- |
| 3244 | |
| 3245 | rmr_str2xact |
| 3246 | |
| 3247 | SYNOPSIS |
| 3248 | -------------------------------------------------------------------------------------------- |
| 3249 | |
| 3250 | |
| 3251 | :: |
| 3252 | |
| 3253 | #include <rmr/rmr.h> |
| 3254 | int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len ) |
| 3255 | |
| 3256 | |
| 3257 | |
| 3258 | DESCRIPTION |
| 3259 | -------------------------------------------------------------------------------------------- |
| 3260 | |
| 3261 | The rmr_str2xact function will copy the string pointed to by |
| 3262 | src to the transaction ID (xaction) field in the given |
| 3263 | message. The field is a fixed length, gated by the constant |
| 3264 | RMR_MAX_XID and if string length is larger than this value, |
| 3265 | then **nothing** will be copied. (Note, this differs slightly |
| 3266 | from the behaviour of the lrmr_bytes2xact() function.) |
| 3267 | |
| 3268 | |
| 3269 | RETURN VALUE |
| 3270 | -------------------------------------------------------------------------------------------- |
| 3271 | |
| 3272 | On success, the value RMR_OK is returned. If the string |
| 3273 | cannot be copied to the message, the return value will be |
| 3274 | one of the errors listed below. |
| 3275 | |
| 3276 | ERRORS |
| 3277 | -------------------------------------------------------------------------------------------- |
| 3278 | |
| 3279 | If the return value is not RMR_OK, then it will be set to |
| 3280 | one of the values below. |
| 3281 | |
| 3282 | |
| 3283 | RMR_ERR_BADARG |
| 3284 | |
| 3285 | The message, or an internal portion of the message, was |
| 3286 | corrupted or the pointer was invalid. |
| 3287 | |
| 3288 | |
| 3289 | RMR_ERR_OVERFLOW |
| 3290 | |
| 3291 | The length passed in was larger than the maximum length of |
| 3292 | the field; only a portion of the source bytes were copied. |
| 3293 | |
| 3294 | |
| 3295 | EXAMPLE |
| 3296 | -------------------------------------------------------------------------------------------- |
| 3297 | |
| 3298 | |
| 3299 | SEE ALSO |
| 3300 | -------------------------------------------------------------------------------------------- |
| 3301 | |
| 3302 | rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_bytes2xact(3), |
| 3303 | rmr_call(3), rmr_free_msg(3), rmr_get_meid(3), |
| 3304 | rmr_get_rcvfd(3), rmr_get_xact(3), rmr_payload_size(3), |
| 3305 | rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 3306 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 3307 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3), |
| 3308 | rmr_str2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3) |
| 3309 | |
| 3310 | |
| 3311 | NAME |
| 3312 | -------------------------------------------------------------------------------------------- |
| 3313 | |
| 3314 | RMR support functions |
| 3315 | |
| 3316 | SYNOPSIS |
| 3317 | -------------------------------------------------------------------------------------------- |
| 3318 | |
| 3319 | |
| 3320 | :: |
| 3321 | |
| 3322 | #include <rmr/rmr.h> |
| 3323 | #include <rmr/ring_inline.h> |
| 3324 | char* rmr_fib( char* fname ); |
| 3325 | int rmr_has_str( char const* buf, char const* str, char sep, int max ); |
| 3326 | int rmr_tokenise( char* buf, char** tokens, int max, char sep ); |
| 3327 | void* rmr_mk_ring( int size ); |
| 3328 | void rmr_ring_free( void* vr ); |
| 3329 | static inline void* rmr_ring_extract( void* vr ) |
| 3330 | static inline int rmr_ring_insert( void* vr, void* new_data ) |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | DESCRIPTION |
| 3335 | -------------------------------------------------------------------------------------------- |
| 3336 | |
| 3337 | These functions support the RMR library, and are made |
| 3338 | available to user applications as some (e.g. route table |
| 3339 | generators) might need and/or want to make use of them. The |
| 3340 | rmr_fib function accepts a file name and reads the entire |
| 3341 | file into a single buffer. The intent is to provide an easy |
| 3342 | way to load a static route table without a lot of buffered |
| 3343 | I/O hoops. |
| 3344 | |
| 3345 | The rmr_has_str function accepts a *buffer* containing a set |
| 3346 | of delimited tokens (e.g. foo,bar,goo) and returns true if |
| 3347 | the target string, *str,* matches one of the tokens. The |
| 3348 | *sep* parameter provides the separation character in the |
| 3349 | buffer (e.g a comma) and *max* indicates the maximum number |
| 3350 | of tokens to split the buffer into before checking. |
| 3351 | |
| 3352 | The rmr_tokenise function is a simple tokeniser which splits |
| 3353 | *buf* into tokens at each occurrence of *sep*. Multiple |
| 3354 | occurrences of the separator character (e.g. a,,b) result in |
| 3355 | a nil token. Pointers to the tokens are placed into the |
| 3356 | *tokens* array provided by the caller which is assumed to |
| 3357 | have at least enough space for *max* entries. |
| 3358 | |
| 3359 | The rmr_mk_ring function creates a buffer ring with *size* |
| 3360 | entries. |
| 3361 | |
| 3362 | The rmr_ring_free function accepts a pointer to a ring |
| 3363 | context and frees the associated memory. |
| 3364 | |
| 3365 | The rmr_ring_insert and rmr_ring_extract functions are |
| 3366 | provided as static inline functions via the |
| 3367 | *rmr/ring_inline.h* header file. These functions both accept |
| 3368 | the ring *context* returned by mk_ring, and either insert a |
| 3369 | pointer at the next available slot (tail) or extract the data |
| 3370 | at the head. |
| 3371 | |
| 3372 | RETURN VALUES |
| 3373 | -------------------------------------------------------------------------------------------- |
| 3374 | |
| 3375 | The following are the return values for each of these |
| 3376 | functions. |
| 3377 | |
| 3378 | The rmr_fib function returns a pointer to the buffer |
| 3379 | containing the contents of the file. The buffer is terminated |
| 3380 | with a single nil character (0) making it a legitimate C |
| 3381 | string. If the file was empty or nonexistent, a buffer with |
| 3382 | an immediate nil character. If it is important to the calling |
| 3383 | programme to know if the file was empty or did not exist, the |
| 3384 | caller should use the system stat function call to make that |
| 3385 | determination. |
| 3386 | |
| 3387 | The rmr_has_str function returns 1 if *buf* contains the |
| 3388 | token referenced by &ita and false (0) if it does not. On |
| 3389 | error, a -1 value is returned and errno is set accordingly. |
| 3390 | |
| 3391 | The rmr_tokenise function returns the actual number of token |
| 3392 | pointers placed into *tokens* |
| 3393 | |
| 3394 | The rmr_mk_ring function returns a void pointer which is the |
| 3395 | *context* for the ring. |
| 3396 | |
| 3397 | The rmr_ring_insert function returns 1 if the data was |
| 3398 | successfully inserted into the ring, and 0 if the ring is |
| 3399 | full and the pointer could not be deposited. |
| 3400 | |
| 3401 | The rmr_ring_extract will return the data which is at the |
| 3402 | head of the ring, or NULL if the ring is empty. |
| 3403 | |
| 3404 | ERRORS |
| 3405 | -------------------------------------------------------------------------------------------- |
| 3406 | |
| 3407 | Not many of these functions set the value in errno, however |
| 3408 | the value may be one of the following: |
| 3409 | |
| 3410 | |
| 3411 | INVAL |
| 3412 | |
| 3413 | Parameter(s) passed to the function were not valid. |
| 3414 | |
| 3415 | |
| 3416 | EXAMPLE |
| 3417 | -------------------------------------------------------------------------------------------- |
| 3418 | |
| 3419 | |
| 3420 | SEE ALSO |
| 3421 | -------------------------------------------------------------------------------------------- |
| 3422 | |
| 3423 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 3424 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 3425 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |
| 3426 | |
| 3427 | |
| 3428 | NAME |
| 3429 | -------------------------------------------------------------------------------------------- |
| 3430 | |
| 3431 | rmr_torcv_msg |
| 3432 | |
| 3433 | SYNOPSIS |
| 3434 | -------------------------------------------------------------------------------------------- |
| 3435 | |
| 3436 | |
| 3437 | :: |
| 3438 | |
| 3439 | #include <rmr/rmr.h> |
| 3440 | rmr_mbuf_t* rmr_torcv_msg( void* vctx, rmr_mbuf_t* old_msg, int ms_to ); |
| 3441 | |
| 3442 | |
| 3443 | |
| 3444 | DESCRIPTION |
| 3445 | -------------------------------------------------------------------------------------------- |
| 3446 | |
| 3447 | The rmr_torcv_msg function will pause for *ms_to* |
| 3448 | milliseconds waiting for a message to arrive. If a message |
| 3449 | arrives before the timeout expires the message buffer |
| 3450 | returned will have a status of RMR_OK and the payload will |
| 3451 | contain the data received. If the timeout expires before the |
| 3452 | message is received, the status will have the value |
| 3453 | RMR_ERR_TIMEOUT. When a received message is returned the |
| 3454 | message buffer will also contain the message type and length |
| 3455 | set by the sender. If messages were queued while waiting for |
| 3456 | the response to a previous invocation of rmr_call, the oldest |
| 3457 | message is removed from the queue and returned without delay. |
| 3458 | |
| 3459 | The *vctx* pointer is the pointer returned by the rmr_init |
| 3460 | function. *Old_msg* is a pointer to a previously used message |
| 3461 | buffer or NULL. The ability to reuse message buffers helps to |
| 3462 | avoid alloc/free cycles in the user application. When no |
| 3463 | buffer is available to supply, the receive function will |
| 3464 | allocate one. |
| 3465 | |
| 3466 | RETURN VALUE |
| 3467 | -------------------------------------------------------------------------------------------- |
| 3468 | |
| 3469 | The function returns a pointer to the rmr_mbuf_t structure |
| 3470 | which references the message information (state, length, |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 3471 | payload), or a nil pointer in the case of an extreme error. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3472 | |
| 3473 | ERRORS |
| 3474 | -------------------------------------------------------------------------------------------- |
| 3475 | |
| 3476 | The *state* field in the message buffer will be one of the |
| 3477 | following: |
| 3478 | |
| 3479 | |
| 3480 | |
| 3481 | RMR_OK |
| 3482 | |
| 3483 | The message buffer (payload) references the received data. |
| 3484 | |
| 3485 | |
| 3486 | RMR_ERR_INITFAILED |
| 3487 | |
| 3488 | The first call to this function must initialise an |
| 3489 | underlying system notification mechanism. On failure, this |
| 3490 | error is returned and errno will have the system error |
| 3491 | status set. If this function fails to intialise, the poll |
| 3492 | mechansim, it is likely that message receives will never |
| 3493 | be successful. |
| 3494 | |
| 3495 | |
| 3496 | RMR_ERR_TIMEOUT |
| 3497 | |
| 3498 | The timeout expired before a complete message was |
| 3499 | received. All other fields in the message buffer are not |
| 3500 | valid. |
| 3501 | |
| 3502 | |
| 3503 | RMR_ERR_EMPTY |
| 3504 | |
| 3505 | A message was received, but it had no payload. All other |
| 3506 | fields in the message buffer are not valid. |
| 3507 | |
| 3508 | |
| 3509 | |
| 3510 | |
| 3511 | INVAL |
| 3512 | |
| 3513 | Parameter(s) passed to the function were not valid. |
| 3514 | |
| 3515 | |
| 3516 | EBADF |
| 3517 | |
| 3518 | The underlying message transport is unable to process the |
| 3519 | request. |
| 3520 | |
| 3521 | |
| 3522 | ENOTSUP |
| 3523 | |
| 3524 | The underlying message transport is unable to process the |
| 3525 | request. |
| 3526 | |
| 3527 | |
| 3528 | EFSM |
| 3529 | |
| 3530 | The underlying message transport is unable to process the |
| 3531 | request. |
| 3532 | |
| 3533 | |
| 3534 | EAGAIN |
| 3535 | |
| 3536 | The underlying message transport is unable to process the |
| 3537 | request. |
| 3538 | |
| 3539 | |
| 3540 | EINTR |
| 3541 | |
| 3542 | The underlying message transport is unable to process the |
| 3543 | request. |
| 3544 | |
| 3545 | |
| 3546 | ETIMEDOUT |
| 3547 | |
| 3548 | The underlying message transport is unable to process the |
| 3549 | request. |
| 3550 | |
| 3551 | |
| 3552 | ETERM |
| 3553 | |
| 3554 | The underlying message transport is unable to process the |
| 3555 | request. |
| 3556 | |
| 3557 | |
| 3558 | EXAMPLE |
| 3559 | -------------------------------------------------------------------------------------------- |
| 3560 | |
| 3561 | |
| 3562 | SEE ALSO |
| 3563 | -------------------------------------------------------------------------------------------- |
| 3564 | |
| 3565 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 3566 | rmr_get_rcvfd(3), rmr_init(3), rmr_payload_size(3), |
| 3567 | rmr_rcv_msg(3), rmr_send_msg(3), rmr_rcv_specific(3), |
| 3568 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 3569 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3) |
| 3570 | |
| 3571 | |
| 3572 | NAME |
| 3573 | -------------------------------------------------------------------------------------------- |
| 3574 | |
| 3575 | rmr_trace_ref |
| 3576 | |
| 3577 | SYNOPSIS |
| 3578 | -------------------------------------------------------------------------------------------- |
| 3579 | |
| 3580 | |
| 3581 | :: |
| 3582 | |
| 3583 | #include <rmr/rmr.h> |
| 3584 | int rmr_trace_ref( rmr_mbuf_t* mbuf, int* sizeptr ) |
| 3585 | |
| 3586 | |
| 3587 | |
| 3588 | DESCRIPTION |
| 3589 | -------------------------------------------------------------------------------------------- |
| 3590 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3591 | The rmr_trace_ref function returns a pointer to the trace |
| 3592 | area in the message, and optionally populates the user |
| 3593 | programme supplied size integer with the trace area size, if |
| 3594 | *sizeptr* is not nil. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3595 | |
| 3596 | RETURN VALUE |
| 3597 | -------------------------------------------------------------------------------------------- |
| 3598 | |
| 3599 | On success, a void pointer to the trace area of the message |
| 3600 | is returned. A nil pointer is returned if the message has no |
| 3601 | trace data area allocated, or if the message itself is |
| 3602 | invalid. |
| 3603 | |
| 3604 | SEE ALSO |
| 3605 | -------------------------------------------------------------------------------------------- |
| 3606 | |
| 3607 | rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3), |
| 3608 | rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3), |
| 3609 | rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3), |
| 3610 | rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3), |
| 3611 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 3612 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 3613 | rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3), |
| 3614 | rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3), |
| 3615 | rmr_set_trace(3) |
| 3616 | |
| 3617 | |
| 3618 | NAME |
| 3619 | -------------------------------------------------------------------------------------------- |
| 3620 | |
| 3621 | rmr_tralloc_msg |
| 3622 | |
| 3623 | SYNOPSIS |
| 3624 | -------------------------------------------------------------------------------------------- |
| 3625 | |
| 3626 | |
| 3627 | :: |
| 3628 | |
| 3629 | #include <rmr/rmr.h> |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3630 | rmr_mbuf_t* rmr_tralloc_msg( void* vctx, int size, |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3631 | int trace_size, unsigned const char *tr_data ); |
| 3632 | |
| 3633 | |
| 3634 | |
| 3635 | DESCRIPTION |
| 3636 | -------------------------------------------------------------------------------------------- |
| 3637 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3638 | The rmr_tralloc_msg function is used to allocate a buffer |
| 3639 | which the user programme can write into and then send through |
| 3640 | the library. The buffer is allocated such that sending it |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3641 | requires no additional copying from the buffer as it passes |
| 3642 | through the underlying transport mechanism. |
| 3643 | |
| 3644 | The *size* parameter is used to set the payload length in the |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3645 | message. If it is 0, then the default size supplied on the |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3646 | *rmr_init* call will be used. In addition to allocating the |
| 3647 | payload, a space in the buffer is reserved for *trace* data |
| 3648 | (tr_size bytes), and the bytes pointed to by *tr_data* are |
| 3649 | copied into that portion of the message. The *vctx* parameter |
| 3650 | is the void context pointer that was returned by the |
| 3651 | *rmr_init* function. |
| 3652 | |
| 3653 | The pointer to the message buffer returned is a structure |
| 3654 | which has some user application visible fields; the structure |
| 3655 | is described in rmr.h, and is illustrated below. |
| 3656 | |
| 3657 | |
| 3658 | :: |
| 3659 | |
| 3660 | typedef struct { |
| 3661 | int state; |
| 3662 | int mtype; |
| 3663 | int len; |
| 3664 | unsigned char* payload; |
| 3665 | unsigned char* xaction; |
| 3666 | } rmr_mbuf_t; |
| 3667 | |
| 3668 | |
| 3669 | |
| 3670 | |
| 3671 | |
| 3672 | state |
| 3673 | |
| 3674 | Is the current buffer state. Following a call to |
| 3675 | rmr_send_msg the state indicates whether the buffer was |
| 3676 | successfully sent which determines exactly what the |
| 3677 | payload points to. If the send failed, the payload |
| 3678 | referenced by the buffer is the message that failed to |
| 3679 | send (allowing the application to attempt a |
| 3680 | retransmission). When the state is a_OK the buffer |
| 3681 | represents an empty buffer that the application may fill |
| 3682 | in in preparation to send. |
| 3683 | |
| 3684 | |
| 3685 | mtype |
| 3686 | |
| 3687 | When sending a message, the application is expected to set |
| 3688 | this field to the appropriate message type value (as |
| 3689 | determined by the user programme). Upon send this value |
| 3690 | determines how the a library will route the message. For a |
| 3691 | buffer which has been received, this field will contain |
| 3692 | the message type that was set by the sending application. |
| 3693 | |
| 3694 | |
| 3695 | len |
| 3696 | |
| 3697 | The application using a buffer to send a message is |
| 3698 | expected to set the length value to the actual number of |
| 3699 | bytes that it placed into the message. This is likely less |
| 3700 | than the total number of bytes that the message can carry. |
| 3701 | For a message buffer that is passed to the application as |
| 3702 | the result of a receive call, this will be the value that |
| 3703 | the sending application supplied and should indicate the |
| 3704 | number of bytes in the payload which are valid. |
| 3705 | |
| 3706 | |
| 3707 | payload |
| 3708 | |
| 3709 | The payload is a pointer to the actual received data. The |
| 3710 | user programme may read and write from/to the memory |
| 3711 | referenced by the payload up until the point in time that |
| 3712 | the buffer is used on a rmr_send, rmr_call or rmr_reply |
| 3713 | function call. Once the buffer has been passed back to a a |
| 3714 | library function the user programme should **NOT** make |
| 3715 | use of the payload pointer. |
| 3716 | |
| 3717 | |
| 3718 | xaction |
| 3719 | |
| 3720 | The *xaction* field is a pointer to a fixed sized area in |
| 3721 | the message into which the user may write a transaction |
| 3722 | ID. The ID is optional with the exception of when the user |
| 3723 | application uses the rmr_call function to send a message |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3724 | and wait for the reply; the underlying processing expects |
| 3725 | that the matching reply message will also contain the same |
| 3726 | data in the *xaction* field. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3727 | |
| 3728 | |
| 3729 | RETURN VALUE |
| 3730 | -------------------------------------------------------------------------------------------- |
| 3731 | |
| 3732 | The function returns a pointer to a rmr_mbuf structure, or |
| 3733 | NULL on error. |
| 3734 | |
| 3735 | ERRORS |
| 3736 | -------------------------------------------------------------------------------------------- |
| 3737 | |
| 3738 | |
| 3739 | |
| 3740 | ENOMEM |
| 3741 | |
| 3742 | Unable to allocate memory. |
| 3743 | |
| 3744 | |
| 3745 | SEE ALSO |
| 3746 | -------------------------------------------------------------------------------------------- |
| 3747 | |
| 3748 | rmr_alloc_msg(3), rmr_mbuf(3) rmr_call(3), rmr_free_msg(3), |
| 3749 | rmr_init(3), rmr_init_trace(3), rmr_get_trace(3), |
| 3750 | rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3), |
| 3751 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 3752 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 3753 | rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3) |
| 3754 | |
| 3755 | |
| 3756 | NAME |
| 3757 | -------------------------------------------------------------------------------------------- |
| 3758 | |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3759 | rmr_wh_call |
| 3760 | |
| 3761 | SYNOPSIS |
| 3762 | -------------------------------------------------------------------------------------------- |
| 3763 | |
| 3764 | |
| 3765 | :: |
| 3766 | |
| 3767 | #include <rmr/rmr.h> |
| 3768 | rmr_mbuf_t* rmr_wh_call( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg, int call_id, int max_wait ) |
| 3769 | |
| 3770 | |
| 3771 | |
| 3772 | DESCRIPTION |
| 3773 | -------------------------------------------------------------------------------------------- |
| 3774 | |
| 3775 | The rmr_wh_call function accepts a message buffer (msg) from |
| 3776 | the user application and attempts to send it using the |
| 3777 | wormhole ID provided (whid). If the send is successful, the |
| 3778 | call will block until either a response message is received, |
| 3779 | or the max_wait number of milliseconds has passed. In order |
| 3780 | for the response to be recognised as a response, the remote |
| 3781 | process **must** use rmr_rts_msg() to send their response. |
| 3782 | |
| 3783 | Like *rmr_wh_send_msg,* this function attempts to send the |
| 3784 | message directly to a process at the other end of a wormhole |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3785 | which was created with *rmr_wh_open().* When sending message |
| 3786 | via wormholes, the normal RMR routing based on message type |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3787 | is ignored, and the caller may leave the message type |
| 3788 | unspecified in the message buffer (unless it is needed by the |
| 3789 | receiving process). The call_id parameter is a number in the |
| 3790 | range of 2 through 255 and is used to identify the calling |
| 3791 | thread in order to properly match a response message when it |
| 3792 | arrives. Providing this value, and ensuring the proper |
| 3793 | uniqueness, is the responsibility of the user application and |
| 3794 | as such the ability to use the rmr_wh_call() function from |
| 3795 | potentially non-threaded concurrent applications (such as |
| 3796 | Go's goroutines) is possible. |
| 3797 | |
| 3798 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 3799 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3800 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3801 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3802 | until one of three conditions occurs: |
| 3803 | |
| 3804 | |
| 3805 | |
| 3806 | 1. |
| 3807 | |
| 3808 | The message is sent without error |
| 3809 | |
| 3810 | |
| 3811 | 2. |
| 3812 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3813 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3814 | |
| 3815 | |
| 3816 | 3. |
| 3817 | |
| 3818 | The maximum number of retry loops has been attempted |
| 3819 | |
| 3820 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3821 | A retry loop consists of approximately 1000 send attempts |
| 3822 | **without** any intervening calls to *sleep()* or *usleep().* |
| 3823 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3824 | 1000 send attempts is performed before returning to the user |
| 3825 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3826 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3827 | allowing the user application to completely disable retires |
| 3828 | (set to 0), or to increase the number of retry loops. |
| 3829 | |
| 3830 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 3831 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3832 | |
| 3833 | The underlying transport mechanism used to send messages is |
| 3834 | configured in *non-blocking* mode. This means that if a |
| 3835 | message cannot be sent immediately the transport mechanism |
| 3836 | will **not** pause with the assumption that the inability to |
| 3837 | send will clear quickly (within a few milliseconds). This |
| 3838 | means that when the retry loop is completely disabled (set to |
| 3839 | 0), that the failure to accept a message for sending by the |
| 3840 | underlying mechanisms (software or hardware) will be reported |
| 3841 | immediately to the user application. |
| 3842 | |
| 3843 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3844 | mechanism being used, it is extremely likely that retry |
| 3845 | conditions will happen during normal operations. These are |
| 3846 | completely out of RMR's control, and there is nothing that |
| 3847 | RMR can do to avoid or mitigate these other than by allowing |
| 3848 | RMR to retry the send operation, and even then it is possible |
| 3849 | (e.g., during connection reattempts), that a single retry |
| 3850 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3851 | |
| 3852 | RETURN VALUE |
| 3853 | -------------------------------------------------------------------------------------------- |
| 3854 | |
| 3855 | On success, new message buffer, with the payload containing |
| 3856 | the response from the remote endpoint is returned. The state |
| 3857 | in this buffer will reflect the overall send operation state |
| 3858 | and should be RMR_OK. |
| 3859 | |
| 3860 | If a message is returned with a state which is anything other |
| 3861 | than RMR_OK, the indication is that the send was not |
| 3862 | successful. The user application must check the state and |
| 3863 | determine the course of action. If the return value is NULL, |
| 3864 | no message, the indication is that there was no response |
| 3865 | received within the timeout (max_wait) period of time. |
| 3866 | |
| 3867 | ERRORS |
| 3868 | -------------------------------------------------------------------------------------------- |
| 3869 | |
| 3870 | The following values may be passed back in the *state* field |
| 3871 | of the returned message buffer. |
| 3872 | |
| 3873 | |
| 3874 | |
| 3875 | RMR_ERR_WHID |
| 3876 | |
| 3877 | The wormhole ID passed in was not associated with an open |
| 3878 | wormhole, or was out of range for a valid ID. |
| 3879 | |
| 3880 | RMR_ERR_NOWHOPEN |
| 3881 | |
| 3882 | No wormholes exist, further attempt to validate the ID are |
| 3883 | skipped. |
| 3884 | |
| 3885 | RMR_ERR_BADARG |
| 3886 | |
| 3887 | The message buffer pointer did not refer to a valid |
| 3888 | message. |
| 3889 | |
| 3890 | RMR_ERR_NOHDR |
| 3891 | |
| 3892 | The header in the message buffer was not valid or |
| 3893 | corrupted. |
| 3894 | |
| 3895 | |
| 3896 | EXAMPLE |
| 3897 | -------------------------------------------------------------------------------------------- |
| 3898 | |
| 3899 | The following is a simple example of how the a wormhole is |
| 3900 | created (rmr_wh_open) and then how rmr_wh_send_msg function |
| 3901 | is used to send messages. Some error checking is omitted for |
| 3902 | clarity. |
| 3903 | |
| 3904 | |
| 3905 | :: |
| 3906 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3907 | #include <rmr/rmr.h> // system headers omitted for clarity |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3908 | int main() { |
| 3909 | rmr_whid_t whid = -1; // wormhole id for sending |
| 3910 | void* mrc; //msg router context |
| 3911 | int i; |
| 3912 | rmr_mbuf_t* sbuf; // send buffer |
| 3913 | int count = 0; |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 3914 | int norm_msg_size = 1500; // most messages fit in this size |
| 3915 | mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE ); |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3916 | if( mrc == NULL ) { |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3917 | fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" ); |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3918 | exit( 1 ); |
| 3919 | } |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3920 | while( ! rmr_ready( mrc ) ) { // wait for routing table info |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3921 | sleep( 1 ); |
| 3922 | } |
| 3923 | sbuf = rmr_alloc_msg( mrc, 2048 ); |
| 3924 | while( 1 ) { |
| 3925 | if( whid < 0 ) { |
| 3926 | whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3927 | if( RMR_WH_CONNECTED( wh ) ) { |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3928 | snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ ); |
| 3929 | sbuf->len = strlen( sbuf->payload ); |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3930 | sbuf = rmr_wh_call( mrc, whid, sbuf, 1000 ); // expect a response in 1s or less |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3931 | if( sbuf != NULL && sbuf->state = RMR_OK ) { |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3932 | sprintf( stderr, "response: %s\\n", sbuf->payload ); // assume they sent a string |
E. Scott Daniels | 8633a0b | 2020-03-09 13:57:39 -0400 | [diff] [blame] | 3933 | } else { |
| 3934 | sprintf( stderr, "response not received, or send error\\n" ); |
| 3935 | } |
| 3936 | } |
| 3937 | } |
| 3938 | sleep( 5 ); |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | |
| 3943 | |
| 3944 | SEE ALSO |
| 3945 | -------------------------------------------------------------------------------------------- |
| 3946 | |
| 3947 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 3948 | rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 3949 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 3950 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3), |
| 3951 | rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3), |
| 3952 | rmr_wh_state(3) |
| 3953 | |
| 3954 | |
| 3955 | NAME |
| 3956 | -------------------------------------------------------------------------------------------- |
| 3957 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3958 | rmr_wh_close |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3959 | |
| 3960 | SYNOPSIS |
| 3961 | -------------------------------------------------------------------------------------------- |
| 3962 | |
| 3963 | |
| 3964 | :: |
| 3965 | |
| 3966 | #include <rmr/rmr.h> |
| 3967 | void rmr_close( void* vctx, rmr_whid_t whid ) |
| 3968 | |
| 3969 | |
| 3970 | |
| 3971 | DESCRIPTION |
| 3972 | -------------------------------------------------------------------------------------------- |
| 3973 | |
| 3974 | The rmr_wh_close function closes the wormhole associated with |
| 3975 | the wormhole id passed in. Future calls to rmr_wh_send_msg |
| 3976 | with this ID will fail. |
| 3977 | |
| 3978 | The underlying TCP connection to the remote endpoint is |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 3979 | **not** closed as this session may be required for regularly |
| 3980 | routed messages (messages routed based on message type). |
| 3981 | There is no way to force a TCP session to be closed at this |
| 3982 | point in time. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 3983 | |
| 3984 | SEE ALSO |
| 3985 | -------------------------------------------------------------------------------------------- |
| 3986 | |
| 3987 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 3988 | rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3), |
| 3989 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 3990 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
| 3991 | rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3), |
| 3992 | rmr_wh_send_msg(3) |
| 3993 | |
| 3994 | |
| 3995 | NAME |
| 3996 | -------------------------------------------------------------------------------------------- |
| 3997 | |
| 3998 | rmr_wh_open |
| 3999 | |
| 4000 | SYNOPSIS |
| 4001 | -------------------------------------------------------------------------------------------- |
| 4002 | |
| 4003 | |
| 4004 | :: |
| 4005 | |
| 4006 | #include <rmr/rmr.h> |
| 4007 | void* rmr_wh_open( void* vctx, char* target ) |
| 4008 | |
| 4009 | |
| 4010 | |
| 4011 | DESCRIPTION |
| 4012 | -------------------------------------------------------------------------------------------- |
| 4013 | |
| 4014 | The rmr_wh_open function creates a direct link for sending, a |
| 4015 | wormhole, to another RMr based process. Sending messages |
| 4016 | through a wormhole requires that the connection be |
| 4017 | established overtly by the user application (via this |
| 4018 | function), and that the ID returned by rmr_wh_open be passed |
| 4019 | to the rmr_wh_send_msg function. |
| 4020 | |
| 4021 | *Target* is the *name* or *IP-address* combination of the |
| 4022 | processess that the wormhole should be connected to. *Vctx* |
| 4023 | is the RMr void context pointer that was returned by the |
| 4024 | rmr_init function. |
| 4025 | |
| 4026 | When invoked, this function immediatly attempts to connect to |
| 4027 | the target process. If the connection cannot be established, |
| 4028 | an error is returned to the caller, and no direct messages |
| 4029 | can be sent to the target. Once a wormhole is connected, the |
| 4030 | underlying transport mechanism (e.g. NNG) will provide |
| 4031 | reconnects should the connection be lost, however the |
| 4032 | handling of messages sent when a connection is broken is |
| 4033 | undetermined as each underlying transport mechanism may |
| 4034 | handle buffering and retries differently. |
| 4035 | |
| 4036 | RETURN VALUE |
| 4037 | -------------------------------------------------------------------------------------------- |
| 4038 | |
| 4039 | The rmr_wh_open function returns a type rmr_whid_t which must |
| 4040 | be passed to the rmr_wh_send_msg function when sending a |
| 4041 | message. The id may also be tested to determine success or |
| 4042 | failure of the connection by using the RMR_WH_CONNECTED macro |
| 4043 | and passing the ID as the parameter; a result of 1 indicates |
| 4044 | that the connection was esablished and that the ID is valid. |
| 4045 | |
| 4046 | ERRORS |
| 4047 | -------------------------------------------------------------------------------------------- |
| 4048 | |
| 4049 | The following error values are specifically set by this RMR |
| 4050 | function. In some cases the error message of a system call is |
| 4051 | propagated up, and thus this list might be incomplete. |
| 4052 | |
| 4053 | |
| 4054 | EINVAL |
| 4055 | |
| 4056 | A parameter passed was not valid. |
| 4057 | |
| 4058 | EACCESS |
| 4059 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4060 | The user application does not have the ability to |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4061 | establish a wormhole to the indicated target (or maybe any |
| 4062 | target). |
| 4063 | |
| 4064 | ECONNREFUSED |
| 4065 | |
| 4066 | The connection was refused. |
| 4067 | |
| 4068 | |
| 4069 | EXAMPLE |
| 4070 | -------------------------------------------------------------------------------------------- |
| 4071 | |
| 4072 | |
| 4073 | :: |
| 4074 | |
| 4075 | void* rmc; |
| 4076 | rmr_whid_t wh; |
| 4077 | rmc = rmr_init( "43086", 4096, 0 ); // init context |
| 4078 | wh = rmr_wh_open( rmc, "localhost:6123" ); |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4079 | if( !RMR_WH_CONNECTED( wh ) ) { |
| 4080 | fprintf( stderr, "unable to connect wormhole: %s\\n", |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4081 | strerror( errno ) ); |
| 4082 | } |
| 4083 | |
| 4084 | |
| 4085 | |
| 4086 | SEE ALSO |
| 4087 | -------------------------------------------------------------------------------------------- |
| 4088 | |
| 4089 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), |
| 4090 | rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3), |
| 4091 | rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3), |
| 4092 | rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 4093 | rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_close(3), |
| 4094 | rmr_wh_send_msg(3), rmr_wh_state(3) |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4095 | |
| 4096 | |
| 4097 | NAME |
| 4098 | -------------------------------------------------------------------------------------------- |
| 4099 | |
| 4100 | rmr_wh_send_msg |
| 4101 | |
| 4102 | SYNOPSIS |
| 4103 | -------------------------------------------------------------------------------------------- |
| 4104 | |
| 4105 | |
| 4106 | :: |
| 4107 | |
| 4108 | #include <rmr/rmr.h> |
| 4109 | rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t id, rmr_mbuf_t* msg ); |
| 4110 | |
| 4111 | |
| 4112 | |
| 4113 | DESCRIPTION |
| 4114 | -------------------------------------------------------------------------------------------- |
| 4115 | |
| 4116 | The rmr_wh_send_msg function accepts a message buffer from |
| 4117 | the user application and attempts to send it using the |
| 4118 | wormhole ID provided (id). Unlike *rmr_send_msg,* this |
| 4119 | function attempts to send the message directly to a process |
| 4120 | at the other end of a wormhole which was created with |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4121 | *rmr_wh_open().* When sending message via wormholes, the |
| 4122 | normal RMR routing based on message type is ignored, and the |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4123 | caller may leave the message type unspecified in the message |
| 4124 | buffer (unless it is needed by the receiving process). |
| 4125 | |
| 4126 | The message buffer (msg) used to send is the same format as |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4127 | used for regular RMR send and reply to sender operations, |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4128 | thus any buffer allocated by these means, or calls to |
| 4129 | *rmr_rcv_msg()* can be passed to this function. |
| 4130 | |
| 4131 | Retries |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 4132 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4133 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4134 | The send operations in RMR will retry *soft* send failures |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4135 | until one of three conditions occurs: |
| 4136 | |
| 4137 | |
| 4138 | |
| 4139 | 1. |
| 4140 | |
| 4141 | The message is sent without error |
| 4142 | |
| 4143 | |
| 4144 | 2. |
| 4145 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4146 | The underlying transport reports a *hard* failure |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4147 | |
| 4148 | |
| 4149 | 3. |
| 4150 | |
| 4151 | The maximum number of retry loops has been attempted |
| 4152 | |
| 4153 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4154 | A retry loop consists of approximately 1000 send attempts |
| 4155 | **without** any intervening calls to *sleep()* or *usleep().* |
| 4156 | The number of retry loops defaults to 1, thus a maximum of |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4157 | 1000 send attempts is performed before returning to the user |
| 4158 | application. This value can be set at any point after RMr |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4159 | initialisation using the *rmr_set_stimeout()* function |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4160 | allowing the user application to completely disable retires |
| 4161 | (set to 0), or to increase the number of retry loops. |
| 4162 | |
| 4163 | Transport Level Blocking |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 4164 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4165 | |
| 4166 | The underlying transport mechanism used to send messages is |
| 4167 | configured in *non-blocking* mode. This means that if a |
| 4168 | message cannot be sent immediately the transport mechanism |
| 4169 | will **not** pause with the assumption that the inability to |
| 4170 | send will clear quickly (within a few milliseconds). This |
| 4171 | means that when the retry loop is completely disabled (set to |
| 4172 | 0), that the failure to accept a message for sending by the |
| 4173 | underlying mechanisms (software or hardware) will be reported |
| 4174 | immediately to the user application. |
| 4175 | |
| 4176 | It should be noted that depending on the underlying transport |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4177 | mechanism being used, it is extremely likely that retry |
| 4178 | conditions will happen during normal operations. These are |
| 4179 | completely out of RMR's control, and there is nothing that |
| 4180 | RMR can do to avoid or mitigate these other than by allowing |
| 4181 | RMR to retry the send operation, and even then it is possible |
| 4182 | (e.g., during connection reattempts), that a single retry |
| 4183 | loop is not enough to guarantee a successful send. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4184 | |
| 4185 | RETURN VALUE |
| 4186 | -------------------------------------------------------------------------------------------- |
| 4187 | |
| 4188 | On success, a new message buffer, with an empty payload, is |
| 4189 | returned for the application to use for the next send. The |
| 4190 | state in this buffer will reflect the overall send operation |
| 4191 | state and should be RMR_OK. |
| 4192 | |
| 4193 | If the state in the returned buffer is anything other than |
| 4194 | RMR_OK, the user application may need to attempt a |
| 4195 | retransmission of the message, or take other action depending |
| 4196 | on the setting of errno as described below. |
| 4197 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 4198 | In the event of extreme failure, a nil pointer is returned. |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4199 | In this case the value of errno might be of some use, for |
| 4200 | documentation, but there will be little that the user |
| 4201 | application can do other than to move on. |
| 4202 | |
| 4203 | ERRORS |
| 4204 | -------------------------------------------------------------------------------------------- |
| 4205 | |
| 4206 | The following values may be passed back in the *state* field |
| 4207 | of the returned message buffer. |
| 4208 | |
| 4209 | |
| 4210 | |
| 4211 | RMR_ERR_WHID |
| 4212 | |
| 4213 | The wormhole ID passed in was not associated with an open |
| 4214 | wormhole, or was out of range for a valid ID. |
| 4215 | |
| 4216 | RMR_ERR_NOWHOPEN |
| 4217 | |
| 4218 | No wormholes exist, further attempt to validate the ID are |
| 4219 | skipped. |
| 4220 | |
| 4221 | RMR_ERR_BADARG |
| 4222 | |
| 4223 | The message buffer pointer did not refer to a valid |
| 4224 | message. |
| 4225 | |
| 4226 | RMR_ERR_NOHDR |
| 4227 | |
| 4228 | The header in the message buffer was not valid or |
| 4229 | corrupted. |
| 4230 | |
| 4231 | |
| 4232 | The following values may be assigned to errno on failure. |
| 4233 | |
| 4234 | |
| 4235 | INVAL |
| 4236 | |
| 4237 | Parameter(s) passed to the function were not valid, or the |
| 4238 | underlying message processing environment was unable to |
| 4239 | interpret the message. |
| 4240 | |
| 4241 | |
| 4242 | ENOKEY |
| 4243 | |
| 4244 | The header information in the message buffer was invalid. |
| 4245 | |
| 4246 | |
| 4247 | ENXIO |
| 4248 | |
| 4249 | No known endpoint for the message could be found. |
| 4250 | |
| 4251 | |
| 4252 | EMSGSIZE |
| 4253 | |
| 4254 | The underlying transport refused to accept the message |
| 4255 | because of a size value issue (message was not attempted |
| 4256 | to be sent). |
| 4257 | |
| 4258 | |
| 4259 | EFAULT |
| 4260 | |
| 4261 | The message referenced by the message buffer is corrupt |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 4262 | (nil pointer or bad internal length). |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4263 | |
| 4264 | |
| 4265 | EBADF |
| 4266 | |
| 4267 | Internal RMR error; information provided to the message |
| 4268 | transport environment was not valid. |
| 4269 | |
| 4270 | |
| 4271 | ENOTSUP |
| 4272 | |
| 4273 | Sending was not supported by the underlying message |
| 4274 | transport. |
| 4275 | |
| 4276 | |
| 4277 | EFSM |
| 4278 | |
| 4279 | The device is not in a state that can accept the message. |
| 4280 | |
| 4281 | |
| 4282 | EAGAIN |
| 4283 | |
| 4284 | The device is not able to accept a message for sending. |
| 4285 | The user application should attempt to resend. |
| 4286 | |
| 4287 | |
| 4288 | EINTR |
| 4289 | |
| 4290 | The operation was interrupted by delivery of a signal |
| 4291 | before the message was sent. |
| 4292 | |
| 4293 | |
| 4294 | ETIMEDOUT |
| 4295 | |
| 4296 | The underlying message environment timed out during the |
| 4297 | send process. |
| 4298 | |
| 4299 | |
| 4300 | ETERM |
| 4301 | |
| 4302 | The underlying message environment is in a shutdown state. |
| 4303 | |
| 4304 | |
| 4305 | EXAMPLE |
| 4306 | -------------------------------------------------------------------------------------------- |
| 4307 | |
| 4308 | The following is a simple example of how the a wormhole is |
| 4309 | created (rmr_wh_open) and then how rmr_wh_send_msg function |
| 4310 | is used to send messages. Some error checking is omitted for |
| 4311 | clarity. |
| 4312 | |
| 4313 | |
| 4314 | :: |
| 4315 | |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4316 | #include <rmr/rmr.h> // system headers omitted for clarity |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4317 | int main() { |
| 4318 | rmr_whid_t whid = -1; // wormhole id for sending |
| 4319 | void* mrc; //msg router context |
| 4320 | int i; |
| 4321 | rmr_mbuf_t* sbuf; // send buffer |
| 4322 | int count = 0; |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 4323 | int norm_msg_size = 1500; // most msg fit in this size |
| 4324 | mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4325 | if( mrc == NULL ) { |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4326 | fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4327 | exit( 1 ); |
| 4328 | } |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4329 | while( ! rmr_ready( mrc ) ) { // wait for routing table info |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4330 | sleep( 1 ); |
| 4331 | } |
| 4332 | sbuf = rmr_alloc_msg( mrc, 2048 ); |
| 4333 | while( 1 ) { |
| 4334 | if( whid < 0 ) { |
| 4335 | whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4336 | if( RMR_WH_CONNECTED( wh ) ) { |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4337 | snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ ); |
| 4338 | sbuf->len = strlen( sbuf->payload ); |
| 4339 | sbuf = rmr_wh_send_msg( mrc, whid, sbuf ); |
Lott, Christopher (cl778h) | 5157a97 | 2020-04-06 20:31:32 -0400 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | sleep( 5 ); |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | |
| 4347 | |
| 4348 | SEE ALSO |
| 4349 | -------------------------------------------------------------------------------------------- |
| 4350 | |
| 4351 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 4352 | rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3), |
| 4353 | rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3), |
| 4354 | rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3), |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 4355 | rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3), |
| 4356 | rmr_wh_state(3) |
E. Scott Daniels | 392168d | 2019-11-06 15:12:38 -0500 | [diff] [blame] | 4357 | |
E. Scott Daniels | 4d1f9bf | 2020-03-06 12:29:28 -0500 | [diff] [blame] | 4358 | |
| 4359 | NAME |
| 4360 | -------------------------------------------------------------------------------------------- |
| 4361 | |
| 4362 | rmr_wh_state |
| 4363 | |
| 4364 | SYNOPSIS |
| 4365 | -------------------------------------------------------------------------------------------- |
| 4366 | |
| 4367 | |
| 4368 | :: |
| 4369 | |
| 4370 | #include <rmr/rmr.h> |
| 4371 | int rmr_wh_state( void* vctx, rmr_whid_t whid ) |
| 4372 | |
| 4373 | |
| 4374 | |
| 4375 | DESCRIPTION |
| 4376 | -------------------------------------------------------------------------------------------- |
| 4377 | |
| 4378 | The rmr_wh_state function will return the current state of |
| 4379 | the connection associated with the given wormhole (whid). The |
| 4380 | return value indicates whether the connection is open |
| 4381 | (RMR_OK), or closed (any other return value). |
| 4382 | |
| 4383 | When using some transport mechanisms (e.g. NNG), it may not |
| 4384 | be possible for RMR to know the actual state and the |
| 4385 | connection may always be reported as "open." |
| 4386 | |
| 4387 | RETURN |
| 4388 | -------------------------------------------------------------------------------------------- |
| 4389 | |
| 4390 | The following values are potential return values. |
| 4391 | |
| 4392 | |
| 4393 | |
| 4394 | RMR_OK |
| 4395 | |
| 4396 | The wormhole ID is valid and the connection is "open." |
| 4397 | |
| 4398 | |
| 4399 | RMR_ERR_WHID |
| 4400 | |
| 4401 | THe wormhole ID passed into the function was not valid. |
| 4402 | |
| 4403 | |
| 4404 | RMR_ERR_NOENDPT |
| 4405 | |
| 4406 | The wormhole is not open (not connected). |
| 4407 | |
| 4408 | |
| 4409 | RMR_ERR_BADARG |
| 4410 | |
| 4411 | The context passed to the function was nil or invalid. |
| 4412 | |
| 4413 | |
| 4414 | RMR_ERR_NOWHOPEN |
| 4415 | |
| 4416 | Wormholes have not been initialised (no wormhole open call |
| 4417 | has been made). |
| 4418 | |
| 4419 | |
| 4420 | |
| 4421 | SEE ALSO |
| 4422 | -------------------------------------------------------------------------------------------- |
| 4423 | |
| 4424 | rmr_wh_open(3), rmr_wh_send_msg(3), rmr_wh_close(3) |