Fix failure when in static only route table mode
[ric-plt/lib/rmr.git] / doc / src / man / rmr_get_rcvfd.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
20 .if false
21     Mnemonic    rmr_get_rcvfd.3.xfm
22     Abstract    The manual page for the rmr_get_rcvfd function.
23     Author      E. Scott Daniels
24     Date        11 February 2019
25 .fi
26
27 .gv e LIB lib
28 .im &{lib}/man/setup.im
29
30 &line_len(6i)
31
32 &h1(RMR Library Functions)
33 &h2(NAME)
34     rmr_get_rcvfd
35
36 &h2(SYNOPSIS)
37 &indent
38 &ex_start
39 #include <rmr/rmr.h>
40
41 void* rmr_get_rcvfd( void* ctx )
42 &ex_end
43
44 &uindent
45
46 &h2(DESCRIPTION)
47 The &cw(rmr_get_rcvfd) function returns a file descriptor which may be given to epoll_wait()
48 by an application that wishes to use event poll in a single thread rather than block
49 on the arrival of a message via calls to rmr_rcv_msg().
50 When epoll_wait() indicates that this file descriptor is ready, a call to rmr_rcv_msg()
51 will not block as at least one message has been received.
52
53 &space
54 The context (ctx) pointer passed in is the pointer returned by the call to rmr_init().
55
56 &h2(RETURN VALUE)
57 The &cw(rmr_get_rcvfd) function returns a file descriptor greater or equal to 0 on success
58 and -1 on error.
59
60 &h2(ERRORS)
61 The following error values are specifically set by this RMR function. In some cases the
62 error message of a system call is propagated up, and thus this list might be incomplete.
63
64 &beg_dlist(.75i : ^&bold_font )
65 &di(EINVAL) The use of this function is invalid in this environment.
66 &end_dlist
67
68 &h2(EXAMPLE)
69 The following short code bit illustrates the use of this function. Error checking has
70 been omitted for clarity.
71 &space
72
73 &ex_start
74 #include <stdio.h>
75 #include <stdlib.h>
76 #include <sys/epoll.h>
77 #include <rmr/rmr.h>
78
79 int main() {
80     int rcv_fd;     // pollable fd
81     void* mrc;      //msg router context
82     struct epoll_event events[10];          // support 10 events to poll
83     struct epoll_event epe;                 // event definition for event to listen to
84     int     ep_fd = -1;
85     rmr_mbuf_t* msg = NULL;
86     int nready;
87     int i;
88     int norm_msg_size = 1500;               // 95% messages are less than this
89
90     mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
91     rcv_fd = rmr_get_rcvfd( mrc );
92
93     ep_fd = epoll_create1( 0 );             // initialise epoll environment
94     epe.events = EPOLLIN;
95     epe.data.fd = rcv_fd;
96     epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe );    // add our info to the mix
97
98     while( 1 ) {
99         nready = epoll_wait( ep_fd, events, 10, -1 );   // -1 == block forever (no timeout)
100         for( i = 0; i < nready && i < 10; i++ ) {       // loop through to find what is ready
101             if( events[i].data.fd == rcv_fd ) {         // RMR has something
102                 msg = rmr_rcv_msg( mrc, msg );
103                 if( msg ) {
104                     // do something with msg
105                 }
106             }
107
108             // check for other ready fds....
109         }
110     }
111 }
112 &ex_end
113
114 &h2(SEE ALSO )
115 .ju off
116 rmr_alloc_msg(3),
117 rmr_call(3),
118 rmr_free_msg(3),
119 rmr_payload_size(3),
120 rmr_send_msg(3),
121 rmr_rcv_msg(3),
122 rmr_rcv_specific(3),
123 rmr_rts_msg(3),
124 rmr_ready(3),
125 rmr_fib(3),
126 rmr_has_str(3),
127 rmr_tokenise(3),
128 rmr_mk_ring(3),
129 rmr_ring_free(3)
130 .ju on
131