2 ==================================================================================
3 Copyright (c) 2019 Nokia
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
20 Mnemonic rmr_mt_rcv_man.xfm
21 Abstract The manual page for the rmr_mt_rcv function.
22 Author E. Scott Daniels
27 .im &{lib}/man/setup.im
31 &h1(RMR Library Functions)
40 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
45 The &cw(rmr_mt_rcv) function blocks until a message is received, or the timeout
46 period (milliseconds) has passed.
47 The result is an RMr message buffer which references a received message.
48 In the case of a timeout the state will be reflected in an "empty buffer" (if old_msg
49 was not nil, or simply with the return of a nil pointer.
50 If a timeout value of zero (0) is given, then the function will block until
51 the next message received.
54 The &ital(vctx) pointer is the pointer returned by the &cw(rmr_init) function.
55 &ital(Old_msg) is a pointer to a previously used message buffer or NULL.
56 The ability to reuse message buffers helps to avoid alloc/free cycles in the
58 When no buffer is available to supply, the receive function will allocate one.
61 The &ital(old_msg) parameter allows the user to pass a previously generated RMR
62 message back to RMR for reuse.
63 Optionally, the user application may pass a nil pointer if no reusable message
65 When a timeout occurs, and old_msg was not nil, the state will be returned
66 by returning a pointer to the old message with the state set.
69 It is possible to use the &ital(rmr_rcv_msg()) function instead of this function.
70 Doing so might be advantageous if the user programme does not always start the
71 multi-threaded mode and the use of &ital(rmr_rcv_msg()) would make the flow of
73 The advantages of using this function are the ability to set a timeout without
74 using epoll, and a small performance gain (if multi-threaded mode is enabled, and the
75 &ital(rmr_rcv_msg()) function is used, it simply invokes this function without
76 a timeout value, thus there is the small cost of a second call that results).
77 Similarly, the &ital(rmr_torcv_msg()) call can be used when in multi-threaded
78 mode with the same "pass through" overhead to using this function directly.
81 When a message is received before the timeout period expires, a pointer to the
82 RMr message buffer which describes the message is returned.
83 This will, with a high probability, be a different message buffer than &ital(old_msg;)
84 the user application should not continue to use &ital(old_msg) after it is passed
88 In the event of a timeout the return value will be the old msg with the state set,
89 or a nil pointer if no old message was provided.
92 The &ital(state) field in the message buffer will be set to one of the following
96 &beg_dlist(.75i : ^&bold_font )
97 &di(RMR_OK) The message was received without error.
100 &di(RMR_ERR_BADARG) A parameter passed to the function was not valid (e.g. a nil pointer).
102 indicate either &cw(RMR_OK) or
103 &cw(RMR_ERR_EMPTY) if an empty message was received.
106 &di(RMR_ERR_EMPTY) The message received had no associated data. The length of the
110 &di(RMR_ERR_NOTSUPP) The multi-threaded option was not enabled when RMr was
111 initialised. See the man page for &ital(rmr_init()) for details.
114 &di(RMR_ERR_RCVFAILED) A hard error occurred preventing the receive from completing.
118 When a nil pointer is returned, or any other state value was set in the message
119 buffer, &cw(errno) will be set to one of the following:
122 &beg_dlist(.75i : ^&bold_font )
123 &di(INVAL) Parameter(s) passed to the function were not valid.
126 &di(EBADF) The underlying message transport is unable to process the request.
129 &di(ENOTSUP) The underlying message transport is unable to process the request.
132 &di(EFSM) The underlying message transport is unable to process the request.
135 &di(EAGAIN) The underlying message transport is unable to process the request.
138 &di(EINTR) The underlying message transport is unable to process the request.
141 &di(ETIMEDOUT) The underlying message transport is unable to process the request.
144 &di(ETERM) The underlying message transport is unable to process the request.
150 rmr_mbuf_t* mbuf = NULL; // received msg
152 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
154 switch( msg->state ) {
156 printf( "got a good message\n" );
160 printf( "received timed out\n" );
164 printf( "receive error: %d\n", mbuf->state );
168 printf( "receive timeout (nil)\n" );