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 advantagous 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 advantags 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 NOTE: Currently the multi-threaded functions are supported only when the NNG
82 transport mechanism is being used. It will not be possible to link a programme
83 using the nanomsg version of the library when references to this function are
87 When a message is received before the timeout period expires, a pointer to the
88 RMr message buffer which describes the message is returned.
89 This will, with a high probability, be a different message buffer than &ital(old_msg;)
90 the user application should not continue to use &ital(old_msg) after it is passed
94 In the event of a timeout the return value will be the old msg with the state set,
95 or a nil pointer if no old message was provided.
98 The &ital(state) field in the message buffer will be set to one of the following
102 &beg_dlist(.75i : ^&bold_font )
103 &di(RMR_OK) The message was received without error.
106 &di(RMR_ERR_BADARG) A parameter passed to the function was not valid (e.g. a nil pointer).
108 indicate either &cw(RMR_OK) or
109 &cw(RMR_ERR_EMPTY) if an empty message was received.
112 &di(RMR_ERR_EMPTY) The message received had no associated data. The length of the
116 &di(RMR_ERR_NOTSUPP) The multi-threaded option was not enabled when RMr was
117 initialised. See the man page for &ital(rmr_init() ) for details.
120 &di(RMR_ERR_RCVFAILED) A hard error occurred preventing the receive from completing.
124 When a nil pointer is returned, or any other state value was set in the message
125 buffer, &cw(errno) will be set to one of the following:
128 &beg_dlist(.75i : ^&bold_font )
129 &di(INVAL) Parameter(s) passed to the function were not valid.
132 &di(EBADF) The underlying message transport is unable to process the request.
135 &di(ENOTSUP) The underlying message transport is unable to process the request.
138 &di(EFSM) The underlying message transport is unable to process the request.
141 &di(EAGAIN) The underlying message transport is unable to process the request.
144 &di(EINTR) The underlying message transport is unable to process the request.
147 &di(ETIMEDOUT) The underlying message transport is unable to process the request.
150 &di(ETERM) The underlying message transport is unable to process the request.
156 rmr_mbuf_t* mbuf = NULL; // received msg
158 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
160 switch( msg->state ) {
162 printf( "got a good message\n" );
166 printf( "received timed out\n" );
170 printf( "receive error: %d\n", mbuf->state );
174 printf( "receive timeout (nil)\n" );