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
26 .** if formatting with tfm, the roff.im will cause roff output to be generated
27 .** if formatting with pfm, then pretty postscript will be generated
30 .im &{lib}/generic_ps.im
32 .gv e OUTPUT_RST use_rst
42 &h1(RMR Library Functions)
51 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
56 The &cw(rmr_mt_rcv) function blocks until a message is received, or the timeout
57 period (milliseconds) has passed.
58 The result is an RMr message buffer which references a received message.
59 In the case of a timeout the state will be reflected in an "empty buffer" (if old_msg
60 was not nil, or simply with the return of a nil pointer.
61 If a timeout value of zero (0) is given, then the function will block until
62 the next message received.
65 The &ital(vctx) pointer is the pointer returned by the &cw(rmr_init) function.
66 &ital(Old_msg) is a pointer to a previously used message buffer or NULL.
67 The ability to reuse message buffers helps to avoid alloc/free cycles in the
69 When no buffer is available to supply, the receive function will allocate one.
72 The &ital(old_msg) parameter allows the user to pass a previously generated RMr
73 message back to RMr for reuse.
74 Optionally, the user application may pass a nil pointer if no reusable message
76 When a timeout occurs, and old_msg was not nil, the state will be returned
77 by returning a pointer to the old message with the state set.
80 It is possible to use the &ital(rmr_rcv_msg()) function instead of this function.
81 Doing so might be advantagous if the user programme does not always start the
82 multi-threaded mode and the use of &ital(rmr_rcv_msg()) would make the flow of
84 The advantags of using this function are the ability to set a timeout without
85 using epoll, and a small performance gain (if multi-threaded mode is enabled, and the
86 &ital(rmr_rcv_msg()) function is used, it simply invokes this function without
87 a timeout value, thus there is the small cost of a second call that results).
88 Similarly, the &ital(rmr_torcv_msg()) call can be used when in multi-threaded
89 mode with the same "pass through" overhead to using this function directly.
92 NOTE: Currently the multi-threaded functions are supported only when the NNG
93 transport mechanism is being used. It will not be possible to link a programme
94 using the nanomsg version of the library when references to this function are
98 When a message is received before the timeout period expires, a pointer to the
99 RMr message buffer which describes the message is returned.
100 This will, with a high probability, be a different message buffer than &ital(old_msg;)
101 the user application should not continue to use &ital(old_msg) after it is passed
105 In the event of a timeout the return value will be the old msg with the state set,
106 or a nil pointer if no old message was provided.
109 The &ital(state) field in the message buffer will be set to one of the following
113 &beg_dlist(.75i : ^&bold_font )
114 &di(RMR_OK) The message was received without error.
117 &di(RMR_ERR_BADARG) A parameter passed to the function was not valid (e.g. a nil pointer).
119 indicate either &cw(RMR_OK) or
120 &cw(RMR_ERR_EMPTY) if an empty message was received.
123 &di(RMR_ERR_EMPTY) The message received had no associated data. The length of the
127 &di(RMR_ERR_NOTSUPP) The multi-threaded option was not enabled when RMr was
128 initialised. See the man page for &ital(rmr_init() ) for details.
131 &di(RMR_ERR_RCVFAILED) A hard error occurred preventing the receive from completing.
135 When a nil pointer is returned, or any other state value was set in the message
136 buffer, &cw(errno) will be set to one of the following:
139 &beg_dlist(.75i : ^&bold_font )
140 &di(INVAL) Parameter(s) passed to the function were not valid.
143 &di(EBADF) The underlying message transport is unable to process the request.
146 &di(ENOTSUP) The underlying message transport is unable to process the request.
149 &di(EFSM) The underlying message transport is unable to process the request.
152 &di(EAGAIN) The underlying message transport is unable to process the request.
155 &di(EINTR) The underlying message transport is unable to process the request.
158 &di(ETIMEDOUT) The underlying message transport is unable to process the request.
161 &di(ETERM) The underlying message transport is unable to process the request.
167 rmr_mbuf_t* mbuf = NULL; // received msg
169 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
171 switch( msg->state ) {
173 printf( "got a good message\n" );
177 printf( "received timed out\n" );
181 printf( "receive error: %d\n", mbuf->state );
185 printf( "receive timeout (nil)\n" );