7f2af20ee5a501f58c217f66c01b26847977852a
[ric-plt/lib/rmr.git] / doc / src / man / rmr_mt_rcv.3.xfm
1 .if false
2 ==================================================================================
3    Copyright (c) 2019 Nokia
4    Copyright (c) 2018-2019 AT&T Intellectual Property.
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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 ==================================================================================
18 .fi
19 .if false
20     Mnemonic    rmr_mt_rcv_man.xfm
21     Abstract    The manual page for the rmr_mt_rcv function.
22     Author      E. Scott Daniels
23     Date        24 May 2019
24 .fi
25
26 .gv e LIB lib
27 .im &{lib}/man/setup.im
28
29 &line_len(6i)
30
31 &h1(RMR Library Functions)
32 &h2(NAME)
33     rmr_mt_rcv
34
35 &h2(SYNOPSIS )
36 &indent
37 &ex_start
38 #include <rmr/rmr.h>
39
40 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
41 &ex_end
42 &uindent
43
44 &h2(DESCRIPTION)
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.
52
53 &space
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
57 user application.
58 When no buffer is available to supply, the receive function will allocate one.
59
60 &space
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
64 is available.
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.
67
68 &space
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
72 the code more simple.
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.
79
80 &h2(RETURN VALUE)
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
85 to this function.
86
87 &space
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.
90
91 &h2(ERRORS)
92 The &ital(state) field in the message buffer will be set to one of the following
93 values:
94 &space
95
96 &beg_dlist(.75i : ^&bold_font )
97 &di(RMR_OK) The message was received without error.
98
99 &half_space
100 &di(RMR_ERR_BADARG) A parameter passed to the function was not valid (e.g. a nil pointer).
101
102 indicate either &cw(RMR_OK) or
103 &cw(RMR_ERR_EMPTY) if an empty message was received.
104
105 &half_space
106 &di(RMR_ERR_EMPTY) The message received had no associated data. The length of the
107     message will be 0.
108
109 &half_space
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.
112
113 &half_space
114 &di(RMR_ERR_RCVFAILED) A hard error occurred preventing the receive from completing.
115 &end_dlist
116
117
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:
120 &space
121
122 &beg_dlist(.75i : ^&bold_font )
123 &di(INVAL) Parameter(s) passed to the function were not valid.
124
125 &half_space
126 &di(EBADF) The underlying message transport is unable to process the request.
127
128 &half_space
129 &di(ENOTSUP) The underlying message transport is unable to process the request.
130
131 &half_space
132 &di(EFSM) The underlying message transport is unable to process the request.
133
134 &half_space
135 &di(EAGAIN) The underlying message transport is unable to process the request.
136
137 &half_space
138 &di(EINTR) The underlying message transport is unable to process the request.
139
140 &half_space
141 &di(ETIMEDOUT) The underlying message transport is unable to process the request.
142
143 &half_space
144 &di(ETERM) The underlying message transport is unable to process the request.
145 &end_dlist
146
147 &h2(EXAMPLE)
148 &space
149 &ex_start
150     rmr_mbuf_t*  mbuf = NULL;   // received msg
151
152     msg = rmr_mt_recv( mr, mbuf, 100 );     // wait up to 100ms
153     if( msg != NULL ) {
154         switch( msg->state ) {
155             case RMR_OK:
156                 printf( "got a good message\n" );
157                 break;
158
159             case RMR_ERR_EMPTY:
160                 printf( "received timed out\n" );
161                 break;
162
163             default:
164                 printf( "receive error: %d\n", mbuf->state );
165                 break;
166         }
167     } else {
168         printf( "receive timeout (nil)\n" );
169     }
170 &ex_end
171
172 &h2(SEE ALSO )
173 .ju off
174 rmr_alloc_msg(3),
175 rmr_call(3),
176 rmr_free_msg(3),
177 rmr_get_rcvfd(3),
178 rmr_init(3),
179 rmr_mk_ring(3),
180 rmr_mt_call(3),
181 rmr_payload_size(3),
182 rmr_send_msg(3),
183 rmr_torcv_msg(3),
184 rmr_rcv_specific(3),
185 rmr_rts_msg(3),
186 rmr_ready(3),
187 rmr_ring_free(3),
188 rmr_torcv_msg(3)
189 .ju on
190